module FsApi::Resource::ClassMethods

Attributes

attributes[R]
nillable_attributes[R]

Public Instance Methods

has_attributes(attributes) click to toggle source
# File lib/fs_api/resource/resource.rb, line 57
def has_attributes(attributes)
  attr_accessor(*@attributes = attributes)
end
has_boolean_attributes(attributes) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/fs_api/resource/resource.rb, line 61
def has_nillable_attributes(attributes)
  @nillable_attributes = attributes
end