Class: Cardboard::Field
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cardboard::Field
- Includes:
- RankedModel
- Defined in:
- app/models/cardboard/field.rb
Direct Known Subclasses
Boolean, Date, Decimal, ExternalLink, File, Image, Integer, ResourceLink, RichText, String, Text
Defined Under Namespace
Classes: Boolean, Date, Decimal, ExternalLink, File, Image, Integer, ResourceLink, RichText, String, Text
Instance Attribute Summary collapse
-
#default ⇒ Object
Returns the value of attribute default.
-
#seeding ⇒ Object
Returns the value of attribute seeding.
Class Method Summary collapse
-
.new_with_cast(*attributes, &block) ⇒ Object
Allow “type” to be passed in nested forms.
Instance Method Summary collapse
- #type ⇒ Object
-
#type=(val) ⇒ Object
overwritten setter.
Instance Attribute Details
#default ⇒ Object
Returns the value of attribute default.
3 4 5 |
# File 'app/models/cardboard/field.rb', line 3 def default @default end |
#seeding ⇒ Object
Returns the value of attribute seeding.
3 4 5 |
# File 'app/models/cardboard/field.rb', line 3 def seeding @seeding end |
Class Method Details
.new_with_cast(*attributes, &block) ⇒ Object
Allow “type” to be passed in nested forms
22 23 24 25 26 27 28 |
# File 'app/models/cardboard/field.rb', line 22 def new_with_cast(*attributes, &block) if (h = attributes.first).is_a?(Hash) && !h.nil? && (type = h.delete(:type) || h.delete('type')) && type.present? && (klass = type.constantize) != self raise "Field type #{type} does not inherit from Cardboard::Field" unless klass <= self return klass.new(*attributes, &block) end new_without_cast(*attributes, &block) end |
Instance Method Details
#type ⇒ Object
38 39 40 |
# File 'app/models/cardboard/field.rb', line 38 def type @_type ||= self[:type].demodulize.underscore end |
#type=(val) ⇒ Object
overwritten setter
33 34 35 36 37 |
# File 'app/models/cardboard/field.rb', line 33 def type=(val) return super if val =~ /^Cardboard::Field::/ || val.nil? @_type = val.to_s.downcase self[:type] = "Cardboard::Field::#{@_type.camelize}" end |