Module: ActsAsBytefield::ClassMethods

Defined in:
lib/acts_as_bytefield.rb

Instance Method Summary collapse

Instance Method Details

#acts_as_bytefield(column, options = {}) ⇒ Object



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

def acts_as_bytefield(column, options = {})
  fail(
    ArgumentError,
    "Hash expected, got #{options.class.name}"
  ) unless options.is_a?(Hash) || options.empty?

  unless respond_to?(:bytefields)
    class_eval { cattr_accessor :bytefields }
    self.bytefields = {}
  end

  column = column.to_sym
  bytefields[column] = create_field_hash(options[:keys])
  bytefields[column].keys.each do |key|
    define_bytefield_methods(column, key)
  end

  include ActsAsBytefield::InstanceMethods
end