Class: Higo::Transport::File

Inherits:
Object
  • Object
show all
Defined in:
lib/higo/transport/file.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil) ⇒ File

Returns a new instance of File.



8
9
10
11
12
# File 'lib/higo/transport/file.rb', line 8

def initialize(path: nil)
  @path      = find_file(path)
  @_raw_file = {}
  @responses = {}
end

Instance Attribute Details

#_raw_fileObject

Returns the value of attribute _raw_file.



6
7
8
# File 'lib/higo/transport/file.rb', line 6

def _raw_file
  @_raw_file
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/higo/transport/file.rb', line 5

def path
  @path
end

#responsesObject

Returns the value of attribute responses.



6
7
8
# File 'lib/higo/transport/file.rb', line 6

def responses
  @responses
end

Class Method Details

.transport(path) ⇒ Object



14
15
16
17
18
# File 'lib/higo/transport/file.rb', line 14

def self.transport(path)
  file  = new(path)
  file._raw_file = file.call
  file
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
# File 'lib/higo/transport/file.rb', line 20

def call
  Fiber.new do
    ::File.open(path, 'r') do |f|
      f.readlines.map
    end
  end
end

#finishObject



28
29
30
31
32
33
# File 'lib/higo/transport/file.rb', line 28

def finish
  _raw_file.resume.map do |val|
    responses.merge!(Hash[*process_value(val)])
  end
  responses
end