Class: Cardboard::Field

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
RankedModel
Defined in:
app/models/cardboard/field.rb

Defined Under Namespace

Classes: Boolean, Date, Decimal, ExternalLink, File, Image, Integer, ResourceLink, RichText, String, Text

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#defaultObject

Returns the value of attribute default.



3
4
5
# File 'app/models/cardboard/field.rb', line 3

def default
  @default
end

#seedingObject

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

#typeObject



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