Module: Moneybird::Resource::ClassMethods
- Included in:
- Administration, Contact, CustomField, DocumentStyle, Documents::GeneralDocument, Documents::GeneralJournalDocument, Documents::PurchaseInvoice, Documents::Receipt, Documents::TypelessDocument, Estimate, ExternalSalesInvoice, FinancialAccount, FinancialMutation, Generic::Event, Generic::Note, Identity, Invoice::Details, Invoice::Payment, LedgerAccount, Product, RecurringSalesInvoice, SalesInvoice, Synchronization, TaxRate, Webhook, Workflow, Webhook
- Defined in:
- lib/moneybird/resource.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
- #logger ⇒ Object
-
#nillable_attributes ⇒ Object
readonly
Returns the value of attribute nillable_attributes.
Instance Method Summary collapse
- #build(attributes) ⇒ Object
- #has_attributes(attributes) ⇒ Object
- #has_boolean_attributes(attributes) ⇒ Object
- #has_datetime_attributes(attributes) ⇒ Object
- #has_integer_attributes(attributes) ⇒ Object
- #has_nillable_attributes(attributes) ⇒ Object
- #resource ⇒ Object
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
53 54 55 |
# File 'lib/moneybird/resource.rb', line 53 def attributes @attributes end |
#logger ⇒ Object
60 61 62 63 64 |
# File 'lib/moneybird/resource.rb', line 60 def logger @logger ||= begin Logger.new(STDOUT) end end |
#nillable_attributes ⇒ Object (readonly)
Returns the value of attribute nillable_attributes.
53 54 55 |
# File 'lib/moneybird/resource.rb', line 53 def nillable_attributes @nillable_attributes end |
Instance Method Details
#build(attributes) ⇒ Object
56 57 58 |
# File 'lib/moneybird/resource.rb', line 56 def build(attributes) new(attributes) end |
#has_attributes(attributes) ⇒ Object
70 71 72 |
# File 'lib/moneybird/resource.rb', line 70 def has_attributes(attributes) attr_accessor(*@attributes = attributes) end |
#has_boolean_attributes(attributes) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/moneybird/resource.rb', line 78 def has_boolean_attributes(attributes) attributes.each do |attribute| define_method(attribute) do input = instance_variable_get('@' + attribute) if input.kind_of?(String) if input == 'true' true elsif input == 'false' false else nil end else input end end end end |
#has_datetime_attributes(attributes) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/moneybird/resource.rb', line 110 def has_datetime_attributes(attributes) attributes.each do |attribute| define_method(attribute) do input = instance_variable_get('@' + attribute) if input.kind_of?(Time) input elsif input.kind_of?(Date) input.to_time elsif input.kind_of?(String) input.strip == '' ? nil : Time.parse(input) end end end end |
#has_integer_attributes(attributes) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/moneybird/resource.rb', line 97 def has_integer_attributes(attributes) attributes.each do |attribute| define_method(attribute) do input = instance_variable_get('@' + attribute) if input.kind_of?(String) input.to_i else input end end end end |
#has_nillable_attributes(attributes) ⇒ Object
74 75 76 |
# File 'lib/moneybird/resource.rb', line 74 def has_nillable_attributes(attributes) @nillable_attributes = attributes end |
#resource ⇒ Object
66 67 68 |
# File 'lib/moneybird/resource.rb', line 66 def resource self.name.split('::').last.underscore end |