Class: Muffin::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/muffin/attribute.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, array:, default:, permit:, permitted_values:, block:) ⇒ Attribute

Returns a new instance of Attribute.



3
4
5
6
7
8
9
10
11
12
13
# File 'lib/muffin/attribute.rb', line 3

def initialize(name:, type:, array:, default:, permit:, permitted_values:, block:)
  array = true if array == nil && (type&.is_a?(Array) || block)
  array ||= false
  type = type.first if type&.is_a? Array
  @name = name
  @type = type
  @array = array
  @default = default
  @permit = permit
  @permitted_values = permitted_values
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



15
16
17
# File 'lib/muffin/attribute.rb', line 15

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



15
16
17
# File 'lib/muffin/attribute.rb', line 15

def name
  @name
end

#permitObject (readonly)

Returns the value of attribute permit.



15
16
17
# File 'lib/muffin/attribute.rb', line 15

def permit
  @permit
end

#permitted_valuesObject (readonly)

Returns the value of attribute permitted_values.



15
16
17
# File 'lib/muffin/attribute.rb', line 15

def permitted_values
  @permitted_values
end

#typeObject (readonly)

Returns the value of attribute type.



15
16
17
# File 'lib/muffin/attribute.rb', line 15

def type
  @type
end

Instance Method Details

#array?Boolean

Returns:



17
18
19
# File 'lib/muffin/attribute.rb', line 17

def array?
  @array
end

#coercise(value) ⇒ Object



21
22
23
# File 'lib/muffin/attribute.rb', line 21

def coercise(value)
  convert value
end