class DaisybillApi::Ext::Attributes::Attribute

Attributes

name[RW]
options[RW]
type[RW]
value[R]

Public Class Methods

new(name, type, options = {}) click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 9
def initialize(name, type, options = {})
  @name = name.to_s
  @type = type
  @options = options
  @value = [] if collection?
end

Public Instance Methods

param_name() click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 24
def param_name
  if collection?
    simple_collection? ? name : "#{name}_attributes"
  else
    simple_type? ? name : "#{name}_attributes"
  end
end
param_value() click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 32
def param_value
  if collection?
    simple_collection? ? value : value.map(&:to_params)
  else
    simple_type? ? value : (value && value.to_params)
  end
end
readonly?() click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 20
def readonly?
  !!options[:readonly]
end
to_param() click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 40
def to_param
  readonly? ? {} : { param_name => param_value }
end
value=(value) click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 16
def value=(value)
  @value = TypeCastings.convert_to(value, type)
end

Private Instance Methods

collection?() click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 50
def collection?
  type.is_a? Array
end
simple_collection?() click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 54
def simple_collection?
  collection? && type.first.is_a?(Symbol)
end
simple_type?() click to toggle source
# File lib/daisybill_api/ext/attributes/attribute.rb, line 46
def simple_type?
  type.is_a? Symbol
end