lib/extend_at/configuration.rb in extend_at-0.2.1 vs lib/extend_at/configuration.rb in extend_at-0.2.2
- old
+ new
@@ -1,21 +1,49 @@
require File.expand_path('../environment', __FILE__)
module ExtendModelAt
class Configuration
- def self.run(env=nil,model=nil)
- return expand_options env, { :not_call_symbol => [:boolean], :not_expand => [:validate, :default] }, model if env.kind_of? Hash
+ def run(env=nil,model=nil)
+ if env.kind_of? Hash
+ hash = expand_options env, { :not_call_symbol => [:boolean], :not_expand => [:validate, :default] }, model.clone
+ hash[:columns] = init_columns hash[:columns]
+ return hash
+ end
if not env.kind_of? Proc
return {}
else
Environment.new.run env, model
end
end
protected
- def self.expand_options(options={}, opts={}, model=nil)
+ def init_columns(columns={})
+ new = {}
+ columns.each do |column, config|
+ new[column] = config
+ # Stablish the type
+ if config[:type].class == Class
+ # If exist :type, is a static column
+ new[column][:type] = get_type_for_class config[:type]
+ end
+ end
+ new
+ end
+
+ def get_type_for_class(type)
+ type = type.name
+ return :any if type == 'NilClass'
+ return :float if type == 'Float'
+ return :integer if type == 'Fixnum'
+ return :text if type == 'String '
+ return :timestamp if type == 'Time'
+ return :datetime if type == 'Date'
+ return :any
+ end
+
+ def expand_options(options={}, opts={}, model=nil)
options = get_value_of options, model
config_opts = {
:not_expand => [],
:not_call_symbol => []
}.merge! opts
@@ -36,10 +64,10 @@
else
return get_value_of options, model
end
end
- def self.get_value_of(value, model=nil)
+ def get_value_of(value, model=nil)
if value.kind_of? Symbol
# If the function exist, we execute it
if model.respond_to? value
return model.send value
# if the the function not exist, whe set te symbol as a value
\ No newline at end of file