Module: Filthy::ClassMethods

Defined in:
lib/filthy.rb

Instance Method Summary collapse

Instance Method Details

#filthy_attributes(*args) ⇒ Object

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/filthy.rb', line 8

def filthy_attributes(*args)
  raise ArgumentError if args.empty?
  class_attribute :filthy_columns, :filthy_attribute_methods

  if defined?(self.superclass.filthy_columns) && self.superclass.filthy_columns.present?
    self.filthy_columns = args + self.superclass.filthy_columns
  else
    self.filthy_columns = args
  end
  self.filthy_attribute_methods = self.filthy_columns.collect { |attribute| :"#{attribute}_filthy" }
  
  self.filthy_attribute_methods.each do |method|
    attr_accessor method
    
    send(:define_method, :"#{method}?") do
      !!send(method)
    end
  end
end