Class: AstroPay::Model
- Inherits:
-
Object
- Object
- AstroPay::Model
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- lib/astro_pay/model.rb
Instance Attribute Summary collapse
-
#error ⇒ Object
Returns the value of attribute error.
-
#message ⇒ Object
Returns the value of attribute message.
Instance Method Summary collapse
-
#attributes ⇒ Hash
Gets the instance attributes.
-
#attributes=(attributes = {}) ⇒ Object
Sets a given hash values as attribute values for the class.
-
#initialize(attributes = {}) ⇒ AstroPay::Model
constructor
Creates a new instance of [AstroPay::Model].
Constructor Details
#initialize(attributes = {}) ⇒ AstroPay::Model
Creates a new instance of [AstroPay::Model].
13 14 15 |
# File 'lib/astro_pay/model.rb', line 13 def initialize(attributes = {}) self.attributes = attributes end |
Instance Attribute Details
#error ⇒ Object
Returns the value of attribute error.
3 4 5 |
# File 'lib/astro_pay/model.rb', line 3 def error @error end |
#message ⇒ Object
Returns the value of attribute message.
3 4 5 |
# File 'lib/astro_pay/model.rb', line 3 def @message end |
Instance Method Details
#attributes ⇒ Hash
Gets the instance attributes.
37 38 39 |
# File 'lib/astro_pay/model.rb', line 37 def attributes Hash[instance_variables.map { |name| [name, instance_variable_get(name)] }] end |
#attributes=(attributes = {}) ⇒ Object
Note:
If raised, [NoMethodError] will be caught and a message will be printed to the standard output.
Sets a given hash values as attribute values for the class. It will try to match the keys of the hash to existent attributes that have accessors.
23 24 25 26 27 28 29 30 31 |
# File 'lib/astro_pay/model.rb', line 23 def attributes=(attributes = {}) attributes.each do |name, value| begin send("#{name.to_s.underscore}=", value) rescue NoMethodError => e puts "Unable to assign #{name.to_s.underscore} with value #{value}. No such method." end end end |