class Lolita::Configuration::Field::Base
Attributes
dbi[R]
dbi_field[RW]
nested_in[R]
Public Class Methods
new(dbi,name,*args, &block)
click to toggle source
# File lib/lolita/configuration/field.rb, line 37 def initialize dbi,name,*args, &block @dbi=dbi self.name = name options = args ? args.extract_options! : {} type = args[0] self.type = type || @@default_type self.set_attributes(options) if block_given? self.instance_eval(&block) end set_default_values validate end
Public Instance Methods
find_dbi_field()
click to toggle source
# File lib/lolita/configuration/field.rb, line 126 def find_dbi_field @dbi_field ||= self.dbi.fields.detect{|field| field.name.to_s == @name.to_s || (field.association && field.association.name.to_s == @name.to_s) } end
match_state_of?(record)
click to toggle source
# File lib/lolita/configuration/field.rb, line 73 def match_state_of?(record) if @on if @on.respond_to?(:call) @on.call(record) elsif @on.respond_to?(:detect) !!@on.detect{|state| record_state_matches_with(record,state)} else record_state_matches_with(record,@on) end else true end end
name=(value)
click to toggle source
# File lib/lolita/configuration/field.rb, line 69 def name=(value) @name= value ? value.to_sym : nil end
nested?()
click to toggle source
# File lib/lolita/configuration/field.rb, line 101 def nested? !self.nested_in.nil? end
nested_in=(dbi)
click to toggle source
# File lib/lolita/configuration/field.rb, line 91 def nested_in=(dbi) if !self.dbi.associations_class_names.include?(dbi.klass.to_s) && !dbi.associations_class_names.include?(self.dbi.klass.to_s) raise Lolita::ReferenceError, "There is no association between #{self.dbi.klass} and #{dbi.klass}" end if !dbi.is_a?(Lolita::DBI::Base) && !dbi.class.to_s.match(/Lolita::Adapter/) raise ArgumentError, "Field can be nested only in Lolita::DBI::Base object." end @nested_in=dbi end
nested_in?(dbi_or_class)
click to toggle source
# File lib/lolita/configuration/field.rb, line 105 def nested_in?(dbi_or_class) if dbi_or_class.respond_to?(:klass) self.nested_in && self.nested_in.klass==dbi_or_class.klass else self.nested_in && self.nested_in.klass==dbi_or_class end end
record_state_matches_with(record,state)
click to toggle source
# File lib/lolita/configuration/field.rb, line 87 def record_state_matches_with(record,state) @dbi.switch_record_state(record).state == state end
set_attributes(attributes)
click to toggle source
# File lib/lolita/configuration/field.rb, line 113 def set_attributes(attributes) excluded_keys = [:name,:type] attributes.each{|attr,value| unless excluded_keys.include?(attr.to_sym) if attr == :dbi_field self.dbi_field = value else self.send(:"#{attr}=",value) end end } end
title(new_title = nil)
click to toggle source
# File lib/lolita/configuration/field.rb, line 53 def title(new_title = nil) if new_title @title = new_title end Lolita::Utils.dynamic_string(@title, :default => @dbi.klass.human_attribute_name(@name)) end
type(value=nil)
click to toggle source
# File lib/lolita/configuration/field.rb, line 60 def type value=nil @type=value.to_s.underscore if value @type end
type=(value)
click to toggle source
# File lib/lolita/configuration/field.rb, line 65 def type=(value) @type=value ? value.to_s.underscore : nil end
Private Instance Methods
builder_local_variable_name()
click to toggle source
# File lib/lolita/configuration/field.rb, line 134 def builder_local_variable_name :field end
set_default_values()
click to toggle source
# File lib/lolita/configuration/field.rb, line 138 def set_default_values self.options||={} self.html_options ||= {} @html_options[:class] = if @html_options[:class] "#{@html_options[:class]} #{self.type}" else self.type.to_s end end
validate()
click to toggle source
# File lib/lolita/configuration/field.rb, line 148 def validate unless self.name raise Lolita::FieldNameError, "Field must have name." end end