-
Notifications
You must be signed in to change notification settings - Fork 8
panda, tiger, eagle #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
noahpatterson
wants to merge
3
commits into
RubyoffRails:master
Choose a base branch
from
noahpatterson:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,16 +8,18 @@ | |
| Rabl.register! | ||
|
|
||
| class LogRequest | ||
| attr_reader :text, :time, :created_at | ||
| def initialize(time, text) | ||
| attr_reader :text, :time, :created_at, :execution_time, :user_code | ||
| def initialize(user_code, time, execution_time, text) | ||
| @text = text | ||
| @time = time | ||
| @created_at = Time.now | ||
| @execution_time = Time.now | ||
| @user_code = user_code | ||
| end | ||
|
|
||
| @@log = [] | ||
| def self.log_request(time, text) | ||
| @@log << LogRequest.new(time, text) | ||
| def self.log_request(user_code, time, execution_time, text) | ||
| @@log << LogRequest.new(user_code, time, execution_time, text) | ||
| end | ||
|
|
||
| def self.log | ||
|
|
@@ -27,12 +29,42 @@ def self.log | |
| def self.clear_log! | ||
| @@log = [] | ||
| end | ||
| end | ||
|
|
||
| class User | ||
| @@unique_codes = [] | ||
|
|
||
| attr_reader :code | ||
| def initialize | ||
| @code = create_unique_code | ||
| @@unique_codes << @code | ||
| end | ||
|
|
||
| def create_unique_code | ||
| @@unique_codes.length + 1 | ||
| end | ||
| end | ||
|
|
||
| LogRequest.log_request Time.now, "Just do it alreay" | ||
| # LogRequest.log_request Time.now, 2.hours.from_now, "Just do it alreay" | ||
|
|
||
| get '/' do | ||
| @logs = LogRequest.log | ||
| if params['user_code'] | ||
| @logs = LogRequest.log.select { |log| | ||
| log if log.user_code == params['user_code'].to_i } | ||
| else | ||
| @logs = LogRequest.log | ||
| end | ||
| render :rabl, :logs, :format => "json" | ||
| end | ||
|
|
||
| post '/' do | ||
| if params.empty? or params['post'].nil? or params['post']['user_code'].nil? | ||
| status 401 | ||
| erb :'401' | ||
| else | ||
| request = JSON.parse(params['post']) | ||
| LogRequest.log_request request['user_code'], request['time'], request['execution_time'], request['text'] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably got a little old writing it out. Did you know you could do: LogRequest.log_request request.values_at(*%w(user_code time execution_time text))If that interests you, check out: |
||
| @logs = LogRequest.log | ||
| render :rabl, :logs, :format => "json" | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| collection @logs | ||
|
|
||
| attributes :time, :text | ||
| attributes :user_code, :time, :text, :execution_time |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This syntax is close, but not really there. a
selectblock doesn't return the thing inside the block as a map does. Instead, it only keeps the things in the collection if select is true.example: http://rubyfiddle.com/riddles/e0745