lib/lolita/configuration/column.rb in lolita-3.1.5 vs lib/lolita/configuration/column.rb in lolita-3.1.6
- old
+ new
@@ -5,17 +5,24 @@
include Lolita::Builder
MAX_TEXT_SIZE=20
lolita_accessor :name,:title,:type,:options,:sortable
- def initialize(*args,&block)
+ def initialize(dbi,*args,&block)
+ @dbi=dbi
self.set_attributes(*args)
self.instance_eval(&block) if block_given?
validate
set_default_values
end
+ def title(value=nil)
+ @title=value if value
+ @title||=@dbi.klass.human_attribute_name(@name.to_s)
+ @title
+ end
+
def sortable?
@sortable
end
def currently_sorting?(params)
@@ -29,28 +36,45 @@
"desc"
end
{:sc=>self.name,:sd=>direction}
end
- # Define format, for details see Lolita::Support::Formatter::Base and Lolita::Support::Formater::Rails
+ # Define format, for details see Lolita::Support::Formatter and Lolita::Support::Formater::Rails
def formatter(value=nil,&block)
if block_given?
@formatter=Lolita::Support::Formatter.new(value,&block)
elsif value || !@formatter
- @formatter=Lolita::Support::Formatter::Rails.new(value)
+ if value.kind_of?(Lolita::Support::Formatter)
+ @formatter=value
+ else
+ @formatter=Lolita::Support::Formatter::Rails.new(value)
+ end
end
@formatter
end
-
+
+ def formatter=(value)
+ if value.kind_of?(Lolita::Support::Formatter)
+ @formatter=value
+ else
+ @formatter=Lolita::Support::Formatter::Rails.new(value)
+ end
+ end
+
def set_attributes(*args)
if !args.empty?
if args[0].is_a?(Hash)
args[0].each{|m,value|
self.send("#{m}=".to_sym,value)
}
elsif args[0].is_a?(Symbol) || args[0].is_a?(String)
self.name=args[0].to_s
+ if args[1].is_a?(Hash)
+ args[1].each{|m,value|
+ self.send("#{m}=".to_sym,value)
+ }
+ end
else
raise ArgumentError.new("Lolita::Configuration::Column arguments must be Hash or Symbol or String instead of #{args[0].class}")
end
end
end
@@ -58,10 +82,9 @@
private
def set_default_values
@sortable||=true
@sort_direction||=:desc
- @title||=@name.to_s.humanize
end
def validate
raise ArgumentError.new("Column must have name.") unless self.name
end