Module: FsApi::Resource::ClassMethods

Included in:
Client, Invoice, InvoicesPayment, Product
Defined in:
lib/fs_api/resource/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



55
56
57
# File 'lib/fs_api/resource/resource.rb', line 55

def attributes
  @attributes
end

#nillable_attributesObject (readonly)

Returns the value of attribute nillable_attributes.



55
56
57
# File 'lib/fs_api/resource/resource.rb', line 55

def nillable_attributes
  @nillable_attributes
end

Instance Method Details

#has_attributes(attributes) ⇒ Object



57
58
59
# File 'lib/fs_api/resource/resource.rb', line 57

def has_attributes(attributes)
  attr_accessor(*@attributes = attributes)
end

#has_boolean_attributes(attributes) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/fs_api/resource/resource.rb', line 65

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



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/fs_api/resource/resource.rb', line 84

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_nillable_attributes(attributes) ⇒ Object



61
62
63
# File 'lib/fs_api/resource/resource.rb', line 61

def has_nillable_attributes(attributes)
  @nillable_attributes = attributes
end