Class: Butterfly::YamlFile

Inherits:
AdaptorBase show all
Defined in:
lib/butterfly/adaptors/yaml_file_adaptor.rb

Instance Method Summary collapse

Methods inherited from AdaptorBase

#delete, #handle_call, #post, #put

Constructor Details

#initialize(o = {}) ⇒ YamlFile

Returns a new instance of YamlFile.



6
7
8
9
# File 'lib/butterfly/adaptors/yaml_file_adaptor.rb', line 6

def initialize(o={})
  @time_til_stale = o[:time_til_stale] || Default.time_til_stale
  @file = o[:file] + ".yml"
end

Instance Method Details

#get(req, resp) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/butterfly/adaptors/yaml_file_adaptor.rb', line 10

def get(req, resp)
  if data.has_key?(req.params[0])
    body = "", current_data = data        
    req.params.each do |param|
      current_data = current_data[param]
    end
    current_data
  else
    resp.fail!
    "Not found"
  end
end