Class: MoneyRails::ActiveRecord::MigrationExtensions::OptionsExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/money-rails/active_record/migration_extensions/options_extractor.rb

Class Method Summary collapse

Class Method Details

.extract(attribute, table_name, accessor, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/money-rails/active_record/migration_extensions/options_extractor.rb', line 5

def self.extract(attribute, table_name, accessor, options = {})
  default = MoneyRails::Configuration.send("#{attribute}_column").merge(options[attribute] || {})

  default[:column_name] ||= [default[:prefix], accessor, default[:postfix]].join
  default[:table_name] = table_name

  excluded_keys = [:amount, :currency, :type, :prefix, :postfix, :present, :column_name, :table_name]
  default[:options] = default.except(*excluded_keys)

  default.slice(:present, :table_name, :column_name, :type, :options).values
end