Module: SmartCurrency::ClassMethods

Defined in:
lib/smart_currency.rb

Instance Method Summary collapse

Instance Method Details

#smart_currency(skip_on: []) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/smart_currency.rb', line 9

def smart_currency(skip_on: [])

  if !smart_currency? && table_exists?
      include InstanceMethods
      auto_attributes = []

      self.skip_time_zone_conversion_for_attributes = []

      self.send(:attr_accessor, :disable_smart_currency)

      attributes = self.columns.select {|c| (c.type == :integer || c.type == :decimal) && !c.name.match("id") }

      attributes.each do |a|

        next if skip_on.include?(a.name.to_s.to_sym) || skip_on.include?(a.name.to_s)
        define_method("#{a.name}=") do |val|
          self[a.name.to_sym] = (disable_smart_currency == true ? val : currency_to_db(val))
        end
      end

  end
end

#smart_currency?Boolean

Returns:



32
33
34
# File 'lib/smart_currency.rb', line 32

def smart_currency?
  self.included_modules.include?(InstanceMethods)
end