Class: DaisybillApi::Ext::Attributes::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/daisybill_api/ext/attributes/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, options = {}) ⇒ Attribute

Returns a new instance of Attribute.



9
10
11
12
13
14
# 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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 6

def name
  @name
end

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 6

def options
  @options
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 6

def type
  @type
end

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 7

def value
  @value
end

Instance Method Details

#param_nameObject



24
25
26
27
28
29
30
# 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_valueObject



32
33
34
35
36
37
38
# 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?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 20

def readonly?
  !!options[:readonly]
end

#to_paramObject



40
41
42
# File 'lib/daisybill_api/ext/attributes/attribute.rb', line 40

def to_param
  readonly? ? {} : { param_name => param_value }
end