Module: DynamicAttributes::ClassMethods

Defined in:
app/models/concerns/dynamic_attributes.rb

Instance Method Summary collapse

Instance Method Details

#dynamic_attributes(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/concerns/dynamic_attributes.rb', line 12

def dynamic_attributes(*args)
  args.each do |attr|
    class_eval <<-ENDOFCODE
      def #{attr}
        read_dynamic_attribute(#{attr.inspect})
      end

      def #{attr}=(v)
        write_dynamic_attribute(#{attr.inspect}, v)
      end
    ENDOFCODE
  end
end

#partition_wheres(wheres) ⇒ Object

we only define this for classes with dynamic attributes so that unmodified classes work exactly as before



8
9
10
# File 'app/models/concerns/dynamic_attributes.rb', line 8

def partition_wheres(wheres)
  wheres.partition { |k, v| column_names.include?(k.to_s) || reflect_on_association(k.to_sym) }.map { |x| Hash[x] }
end