Class: AstroPay::Model

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion, ActiveModel::Validations
Defined in:
lib/astro_pay/model.rb

Direct Known Subclasses

Card, Direct

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ AstroPay::Model

Creates a new instance of [AstroPay::Model].

Parameters:

  • attributes (Hash) (defaults to: {})

    with the following fields: :error, :message.



13
14
15
# File 'lib/astro_pay/model.rb', line 13

def initialize(attributes = {})
  self.attributes = attributes
end

Instance Attribute Details

#errorObject

Returns the value of attribute error.



3
4
5
# File 'lib/astro_pay/model.rb', line 3

def error
  @error
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/astro_pay/model.rb', line 3

def message
  @message
end

Instance Method Details

#attributesHash

Gets the instance attributes.

Returns:

  • (Hash)

    with the attribute name as key, and the attribute value as value.



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.

Parameters:

  • attributes (Hash) (defaults to: {})


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