Class: Cardboard::Field
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Cardboard::Field
- 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_castnew(*attributes, &block) ⇒ Object
Allow “type” to be passed in nested forms.
Instance Method Summary collapse
- #required? ⇒ Boolean
- #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_castnew(*attributes, &block) ⇒ Object
Allow “type” to be passed in nested forms
19 20 21 22 23 24 25 |
# File 'app/models/cardboard/field.rb', line 19 def new_with_castnew(*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_castnew(*attributes, &block) end |
Instance Method Details
#required? ⇒ Boolean
62 63 64 65 66 67 |
# File 'app/models/cardboard/field.rb', line 62 def required? return false if (field_name = self.identifier.to_sym) == :company_name required = self.object_with_field.template[field_name][:required] required = true if required.nil? required end |
#type ⇒ Object
44 45 46 |
# File 'app/models/cardboard/field.rb', line 44 def type @_type ||= self[:type].demodulize.underscore end |
#type=(val) ⇒ Object
overwritten setter
39 40 41 42 43 |
# File 'app/models/cardboard/field.rb', line 39 def type=(val) return super if val =~ /^Cardboard::Field::/ || val.nil? @_type = val.to_s.downcase self[:type] = "Cardboard::Field::#{@_type.camelize}" end |