Class: Paysafe::Result
- Inherits:
-
Object
- Object
- Paysafe::Result
- Defined in:
- lib/paysafe/result.rb
Direct Known Subclasses
Address, Authorization, BirthDate, Card, CardExpiry, Customer, GatewayResponse, Payment, PaymentHandle, PaymentMethod, PaymentMethods, PaymentProcessor, Profile, SingleUseCustomerToken, SingleUseToken, StandaloneCredit, Verification
Instance Attribute Summary collapse
- #attributes ⇒ Hash readonly
Class Method Summary collapse
-
.attributes(*attrs) ⇒ Object
Define methods that retrieve the value from attributes.
-
.define_attribute_method(key1, klass = nil) ⇒ Object
Dynamically define a method for an attribute.
-
.define_predicate_method(key1, key2 = key1) ⇒ Object
Dynamically define a predicate method for an attribute.
-
.object_attribute(klass, key1) ⇒ Object
Define object methods from attributes.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Paysafe::Result
constructor
Initializes a new object.
Constructor Details
#initialize(attributes = {}) ⇒ Paysafe::Result
Initializes a new object
52 53 54 |
# File 'lib/paysafe/result.rb', line 52 def initialize(attributes={}) @attributes = attributes || {} end |
Instance Attribute Details
#attributes ⇒ Hash (readonly)
57 58 59 |
# File 'lib/paysafe/result.rb', line 57 def attributes @attributes end |
Class Method Details
.attributes(*attrs) ⇒ Object
Define methods that retrieve the value from attributes
8 9 10 11 12 13 |
# File 'lib/paysafe/result.rb', line 8 def attributes(*attrs) attrs.each do |attr| define_attribute_method(attr) define_predicate_method(attr) end end |
.define_attribute_method(key1, klass = nil) ⇒ Object
Dynamically define a method for an attribute
28 29 30 31 32 33 34 35 |
# File 'lib/paysafe/result.rb', line 28 def define_attribute_method(key1, klass = nil) define_method(key1) do if instance_variable_defined?("@#{key1}") return instance_variable_get("@#{key1}") end instance_variable_set("@#{key1}", get_value_by(key1, klass)) end end |
.define_predicate_method(key1, key2 = key1) ⇒ Object
Dynamically define a predicate method for an attribute
41 42 43 44 45 |
# File 'lib/paysafe/result.rb', line 41 def define_predicate_method(key1, key2 = key1) define_method(:"#{key1}?") do !attr_falsey_or_empty?(key2) end end |
.object_attribute(klass, key1) ⇒ Object
Define object methods from attributes
19 20 21 22 |
# File 'lib/paysafe/result.rb', line 19 def object_attribute(klass, key1) define_attribute_method(key1, klass) define_predicate_method(key1) end |
Instance Method Details
#empty? ⇒ Boolean
60 61 62 |
# File 'lib/paysafe/result.rb', line 60 def empty? @attributes.empty? end |