Class: EY::CloudClient::ApiStruct
- Inherits:
-
Struct
- Object
- Struct
- EY::CloudClient::ApiStruct
- Defined in:
- lib/engineyard-cloud-client/models/api_struct.rb
Class Method Summary collapse
Instance Method Summary collapse
- #attributes=(attrs) ⇒ Object
-
#initialize(api, attrs) ⇒ ApiStruct
constructor
A new instance of ApiStruct.
Constructor Details
#initialize(api, attrs) ⇒ ApiStruct
Returns a new instance of ApiStruct.
34 35 36 37 |
# File 'lib/engineyard-cloud-client/models/api_struct.rb', line 34 def initialize(api, attrs) self.api = api self.attributes = attrs end |
Class Method Details
.new(*args, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/engineyard-cloud-client/models/api_struct.rb', line 4 def self.new(*args, &block) args = [:api] | args super(*args) do |*block_args| block.call(*block_args) if block def self.from_array(api, array, common_values = {}) if array array.map do |values| from_hash(api, values.merge(common_values)) end end end def self.from_hash(api, attrs_or_struct) return nil unless attrs_or_struct if attrs_or_struct.respond_to?(:attributes=) # already a model obj = attrs_or_struct elsif obj = api.registry.find(self, attrs_or_struct['id']) obj.attributes = attrs_or_struct else obj = new(api, attrs_or_struct) api.registry.set(self, obj) end obj end end end |
Instance Method Details
#attributes=(attrs) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/engineyard-cloud-client/models/api_struct.rb', line 39 def attributes=(attrs) attrs.each do |key, val| setter = :"#{key}=" if respond_to?(setter) send(setter, val) end end end |