Class: Muffin::Attribute
- Inherits:
-
Object
- Object
- Muffin::Attribute
- Defined in:
- lib/muffin/attribute.rb
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#permit ⇒ Object
readonly
Returns the value of attribute permit.
-
#permitted_values ⇒ Object
readonly
Returns the value of attribute permitted_values.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #array? ⇒ Boolean
- #coercise(value) ⇒ Object
-
#initialize(name:, type:, array:, default:, permit:, permitted_values:, block:) ⇒ Attribute
constructor
A new instance of Attribute.
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
#default ⇒ Object (readonly)
Returns the value of attribute default.
15 16 17 |
# File 'lib/muffin/attribute.rb', line 15 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
15 16 17 |
# File 'lib/muffin/attribute.rb', line 15 def name @name end |
#permit ⇒ Object (readonly)
Returns the value of attribute permit.
15 16 17 |
# File 'lib/muffin/attribute.rb', line 15 def permit @permit end |
#permitted_values ⇒ Object (readonly)
Returns the value of attribute permitted_values.
15 16 17 |
# File 'lib/muffin/attribute.rb', line 15 def permitted_values @permitted_values end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
15 16 17 |
# File 'lib/muffin/attribute.rb', line 15 def type @type end |
Instance Method Details
#coercise(value) ⇒ Object
21 22 23 |
# File 'lib/muffin/attribute.rb', line 21 def coercise(value) convert value end |