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
- #<=>(other) ⇒ Object
- #attributes=(attrs) ⇒ Object
-
#initialize(api, attrs) ⇒ ApiStruct
constructor
A new instance of ApiStruct.
- #inspect ⇒ Object
- #sort_attributes ⇒ Object
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.id, obj) end obj end end end |
Instance Method Details
#<=>(other) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/engineyard-cloud-client/models/api_struct.rb', line 52 def <=>(other) unless other.is_a?(self.class) raise ArgumentError, "comparison of #{self.class.name} with #{other.class.name} failed" end sort_attributes <=> other.sort_attributes end |
#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 |
#inspect ⇒ Object
48 49 50 |
# File 'lib/engineyard-cloud-client/models/api_struct.rb', line 48 def inspect %|#<#{self.class.name} #{(members - [:api]).map { |x| "#{x}=#{send(x).inspect}" }.join(" ")}>| end |
#sort_attributes ⇒ Object
59 60 61 |
# File 'lib/engineyard-cloud-client/models/api_struct.rb', line 59 def sort_attributes members.map { |m| sort_string(m.to_s) } end |