Module: Rapids::Batch::ModelExtensions
- Included in:
- ColumnsHelper, CreateTable, CreateTrigger, InsertInto
- Defined in:
- lib/rapids/batch/model_extensions.rb
Instance Method Summary collapse
- #batch_table_name ⇒ Object
- #columns(model = @model) ⇒ Object
- #default_on_nil(value, column) ⇒ Object
-
#quote_bound_value(value) ⇒ Object
Stolen from ActiveRecord::Base.
- #sql_column_name(column, hash_path) ⇒ Object
Instance Method Details
#batch_table_name ⇒ Object
8 9 10 |
# File 'lib/rapids/batch/model_extensions.rb', line 8 def batch_table_name "$#{@model.table_name}_batch" end |
#columns(model = @model) ⇒ Object
4 5 6 |
# File 'lib/rapids/batch/model_extensions.rb', line 4 def columns(model = @model) model.columns.reject{|c|c.primary} end |
#default_on_nil(value, column) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rapids/batch/model_extensions.rb', line 30 def default_on_nil(value,column) if value.nil? case when %w{created_at updated_at}.include?(column.name) "UTC_TIMESTAMP()" else quote_bound_value(value) end else quote_bound_value(value) end end |
#quote_bound_value(value) ⇒ Object
Stolen from ActiveRecord::Base
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/rapids/batch/model_extensions.rb', line 44 def quote_bound_value(value) c = ActiveRecord::Base.connection if value.respond_to?(:map) && !value.acts_like?(:string) if value.respond_to?(:empty?) && value.empty? c.quote(nil) else value.map { |v| c.quote(v) }.join(',') end else c.quote(value) end end |
#sql_column_name(column, hash_path) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rapids/batch/model_extensions.rb', line 12 def sql_column_name(column,hash_path) prefix = if hash_path.empty? "" elsif path_type = hash_path.first and path_type.is_a?(Hash) and path_type[:type] == :update "update$" else "foc$" end association_list = (hash_path + [column.name]).map do |path_type| if path_type.is_a?(Hash) path_type[:name] else path_type.to_s end end.join("$") "`#{prefix+association_list}`" end |