Class: CurlyMustache::Attributes::Definition
- Inherits:
-
Object
- Object
- CurlyMustache::Attributes::Definition
- Defined in:
- lib/curly_mustache/attributes/definition.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #cast(value) ⇒ Object
-
#initialize(name, type, options = {}) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(name, type, options = {}) ⇒ Definition
Returns a new instance of Definition.
6 7 8 9 10 11 12 |
# File 'lib/curly_mustache/attributes/definition.rb', line 6 def initialize(name, type, = {}) @options = .symbolize_keys.reverse_merge :default => nil, :allow_nil => true @name = name.to_sym @type = type.to_sym @caster = Types[type].caster end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/curly_mustache/attributes/definition.rb', line 4 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/curly_mustache/attributes/definition.rb', line 4 def type @type end |
Instance Method Details
#cast(value) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/curly_mustache/attributes/definition.rb', line 14 def cast(value) if value.nil? and @options[:allow_nil] nil else @caster.call(value) end end |