Class: AWSData::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/aws-data/base.rb

Direct Known Subclasses

Dynamic, Metadata

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/aws-data/base.rb', line 18

def initialize
  # Setup the finders, or throw an exception if their IP isn't routable
  unless self.class._base_path
    raise "Can't instanciate without a base_path"
  end

  methods = parse_endpoint_data(transport.get(self.class._base_path))

  methods.each do |m|
    method_name = m.name.gsub(/-/, "_").to_sym
    if m.finder
      eigenclass.send(:define_method, method_name) do
        Finder.new("#{self.class._base_path}/#{m.name}/")
      end
    else
      eigenclass.send(:define_method, method_name) do
        transport.get("#{self.class._base_path}/#{m.name}")
      end
    end
  end
end

Class Method Details

._base_pathObject



13
14
15
# File 'lib/aws-data/base.rb', line 13

def _base_path
  @base_path
end

.base_path(path) ⇒ Object



9
10
11
# File 'lib/aws-data/base.rb', line 9

def base_path(path)
  @base_path = path
end

Instance Method Details

#eigenclassObject



57
58
59
60
61
# File 'lib/aws-data/base.rb', line 57

def eigenclass
  class << self
    self
  end
end

#parse_endpoint_data(data) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/aws-data/base.rb', line 44

def parse_endpoint_data(data)
  ret = []
  data.split("\n").each do |el|
    if el.end_with? "/"
      el.gsub!(/\/$/, "")
      ret << Record.new(el, true)
    else
      ret << Record.new(el, false)
    end
  end
  return ret
end

#transportObject



40
41
42
# File 'lib/aws-data/base.rb', line 40

def transport
  @transport ||= Transport.new
end