Class: Hover::Encoder::JSONStream

Inherits:
Object
  • Object
show all
Defined in:
lib/hover/encoder/json_stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJSONStream

Returns a new instance of JSONStream.



6
7
# File 'lib/hover/encoder/json_stream.rb', line 6

def initialize
end

Instance Attribute Details

#fileObject

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

#closeObject



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