class EY::CloudClient::ApiStruct
Public Class Methods
from_array(api, array, common_values = {})
click to toggle source
# File lib/engineyard-cloud-client/models/api_struct.rb, line 9 def self.from_array(api, array, common_values = {}) if array array.map do |values| from_hash(api, values.merge(common_values)) end end end
from_hash(api, attrs_or_struct)
click to toggle source
# File lib/engineyard-cloud-client/models/api_struct.rb, line 17 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
new(*args, &block)
click to toggle source
Calls superclass method
# 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
new(api, attrs)
click to toggle source
# File lib/engineyard-cloud-client/models/api_struct.rb, line 34 def initialize(api, attrs) self.api = api self.attributes = attrs end
Public Instance Methods
<=>(other)
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/engineyard-cloud-client/models/api_struct.rb, line 59 def sort_attributes members.map { |m| sort_string(m.to_s) } end
Protected Instance Methods
sort_string(str)
click to toggle source
Return ~, which comes late in lexical order, to avoid comparison to nil
# File lib/engineyard-cloud-client/models/api_struct.rb, line 66 def sort_string(str) str || "~" end