Class: EY::Model::ApiStruct

Inherits:
Struct
  • Object
show all
Defined in:
lib/engineyard/model/api_struct.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/engineyard/model/api_struct.rb', line 5

def self.new(*args, &block)
  super(*args) do |*block_args|
    block.call(*block_args) if block

    def self.from_array(array, common_values = {})
      array.map do |values|
        from_hash(values.merge(common_values))
      end if array
    end

    def self.from_hash(hash)
      return nil unless hash
      # in ruby 1.8, #members is an array of strings
      # in ruby 1.9, #members is an array of symbols
      members = new.members.map {|m| m.to_sym}
      values = members.map{|a| hash.has_key?(a) ? hash[a] : hash[a.to_s] }
      new(*values)
    end

  end
end

Instance Method Details

#api_get(uri, options = {}) ⇒ Object



27
28
29
# File 'lib/engineyard/model/api_struct.rb', line 27

def api_get(uri, options = {})
  api.request(uri, options.merge(:method => :get))
end