Class: IronBank::Resource
- Inherits:
-
Object
- Object
- IronBank::Resource
- Extended by:
- Associations::ClassMethods, Metadata, Queryable
- Includes:
- Associations
- Defined in:
- lib/iron_bank/resource.rb
Overview
An Iron Bank RESTful resource.
Direct Known Subclasses
IronBank::Resources::Account, IronBank::Resources::Amendment, IronBank::Resources::CommunicationProfile, IronBank::Resources::Contact, IronBank::Resources::Export, IronBank::Resources::Import, IronBank::Resources::Invoice, IronBank::Resources::InvoiceAdjustment, IronBank::Resources::InvoiceItem, IronBank::Resources::InvoicePayment, IronBank::Resources::Payment, IronBank::Resources::PaymentMethod, IronBank::Resources::Product, IronBank::Resources::ProductRatePlan, IronBank::Resources::ProductRatePlanCharge, IronBank::Resources::ProductRatePlanChargeTier, IronBank::Resources::RatePlan, IronBank::Resources::RatePlanCharge, IronBank::Resources::RatePlanChargeTier, IronBank::Resources::Subscription, IronBank::Resources::TaxationItem, IronBank::Resources::Usage
Instance Attribute Summary collapse
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
Class Method Summary collapse
Instance Method Summary collapse
-
#==(other) ⇒ Object
Two resources are equals if their remote (from Zuora) data are similar.
-
#id ⇒ Object
Every Zuora object has an ID, so we can safely declare it for each resource.
-
#initialize(remote = {}) ⇒ Resource
constructor
A new instance of Resource.
- #inspect ⇒ Object
- #reload ⇒ Object
- #remove_instance_vars ⇒ Object
Methods included from Associations::ClassMethods
Methods included from Metadata
excluded_fields, fields, query_custom_fields, query_fields, reset, schema, single_resource_query_fields, with_schema
Methods included from Queryable
all, find, find_each, first, where
Methods included from Associations
Constructor Details
#initialize(remote = {}) ⇒ Resource
Returns a new instance of Resource.
27 28 29 |
# File 'lib/iron_bank/resource.rb', line 27 def initialize(remote = {}) @remote = remote end |
Instance Attribute Details
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
25 26 27 |
# File 'lib/iron_bank/resource.rb', line 25 def remote @remote end |
Class Method Details
.object_name ⇒ Object
12 13 14 |
# File 'lib/iron_bank/resource.rb', line 12 def self.object_name name.split("::").last end |
Instance Method Details
#==(other) ⇒ Object
Two resources are equals if their remote (from Zuora) data are similar
48 49 50 |
# File 'lib/iron_bank/resource.rb', line 48 def ==(other) other.is_a?(IronBank::Resource) ? remote == other.remote : false end |
#id ⇒ Object
Every Zuora object has an ID, so we can safely declare it for each resource
33 34 35 |
# File 'lib/iron_bank/resource.rb', line 33 def id remote[:id] end |
#inspect ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/iron_bank/resource.rb', line 37 def inspect # NOTE: In Ruby, the IDs of objects start from the second bit on the right # but in "value space" (used by the original `inspect` implementation) # they start from the third bit on the right. Hence the bitsfhit operation # here. # https://stackoverflow.com/questions/2818602/in-ruby-why-does-inspect-print-out-some-kind-of-object-id-which-is-different ruby_id = "#{self.class.name}:0x#{(object_id << 1).to_s(16)} id=\"#{id}\"" respond_to?(:name) ? "#<#{ruby_id} name=\"#{name}\">" : "#<#{ruby_id}>" end |
#reload ⇒ Object
52 53 54 55 56 |
# File 'lib/iron_bank/resource.rb', line 52 def reload remove_instance_vars @remote = self.class.find(id).remote self end |
#remove_instance_vars ⇒ Object
58 59 60 61 62 63 |
# File 'lib/iron_bank/resource.rb', line 58 def remove_instance_vars # Substract predefined variables from the instance variables (instance_variables - [:@remote]).each do |var| remove_instance_variable(:"#{var}") end end |