Class: Hover::Encoder::JSONStream
- Inherits:
-
Object
- Object
- Hover::Encoder::JSONStream
- Defined in:
- lib/hover/encoder/json_stream.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
Instance Method Summary collapse
- #append(attributes, klass) ⇒ Object
- #append_each(attributes_sets, klass) ⇒ Object
- #append_records(scope) ⇒ Object
- #close ⇒ Object
-
#initialize ⇒ JSONStream
constructor
A new instance of JSONStream.
- #open(path) ⇒ Object
Constructor Details
#initialize ⇒ JSONStream
Returns a new instance of JSONStream.
6 7 |
# File 'lib/hover/encoder/json_stream.rb', line 6 def initialize end |
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/hover/encoder/json_stream.rb', line 4 def file @file end |
Instance Method Details
#append(attributes, klass) ⇒ Object
18 19 20 |
# File 'lib/hover/encoder/json_stream.rb', line 18 def append(attributes, klass) self.file.puts(JSON.dump(attributes.merge('class' => klass.name))) end |
#append_each(attributes_sets, klass) ⇒ Object
22 23 24 25 26 |
# File 'lib/hover/encoder/json_stream.rb', line 22 def append_each(attributes_sets, klass) attributes_sets.each do |attributes| append(attributes, klass) end end |
#append_records(scope) ⇒ Object
28 29 30 31 32 |
# File 'lib/hover/encoder/json_stream.rb', line 28 def append_records(scope) scope.find_each do |record| append(record.attributes.as_json, record.class) end end |
#close ⇒ Object
13 14 15 16 |
# File 'lib/hover/encoder/json_stream.rb', line 13 def close self.file.close self.file = nil end |
#open(path) ⇒ Object
9 10 11 |
# File 'lib/hover/encoder/json_stream.rb', line 9 def open(path) self.file = File.open(path, 'w') end |