Class: EvalIn::Result
- Inherits:
-
Object
- Object
- EvalIn::Result
- Defined in:
- lib/eval_in/result.rb
Overview
The data structure containing the final result its attributes default to null-objects for their given type
Class Attribute Summary collapse
-
.attribute_names ⇒ Object
readonly
Returns the value of attribute attribute_names.
Instance Method Summary collapse
-
#as_json ⇒ Object
Returns representation of the result built out of JSON primitives (hash, string, int) This is useful for composing JSON structures and only rendering the JSON string at the end.
-
#initialize(attributes = {}) ⇒ Result
constructor
A new instance of Result.
- #to_json ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Result
Returns a new instance of Result.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/eval_in/result.rb', line 13 def initialize(attributes={}) attributes = attributes.dup self.exitstatus = attributes.delete(:exitstatus) || -1 self.language = attributes.delete(:language) || "" self.language_friendly = attributes.delete(:language_friendly) || "" self.code = attributes.delete(:code) || "" self.output = attributes.delete(:output) || "" self.status = attributes.delete(:status) || "" self.url = attributes.delete(:url) || "" stderr = attributes.delete(:stderr) || $stderr stderr.puts "Unexpected attributes! #{attributes.keys.inspect}" if attributes.any? end |
Class Attribute Details
.attribute_names ⇒ Object (readonly)
Returns the value of attribute attribute_names.
10 11 12 |
# File 'lib/eval_in/result.rb', line 10 def attribute_names @attribute_names end |
Instance Method Details
#as_json ⇒ Object
Returns representation of the result built out of JSON primitives (hash, string, int) This is useful for composing JSON structures and only rendering the JSON string at the end
28 29 30 31 32 |
# File 'lib/eval_in/result.rb', line 28 def as_json self.class.attribute_names.each_with_object Hash.new do |name, attributes| attributes[name.to_s] = public_send name end end |
#to_json ⇒ Object
34 35 36 |
# File 'lib/eval_in/result.rb', line 34 def to_json JSON.dump(as_json) end |