Methods
E
F
N
S
T
U
V
Class Public methods
new(record, attribute, &extension)
# File lib/bitmask_attributes/value_proxy.rb, line 4
def initialize(record, attribute, &extension)
  @record = record
  @attribute = attribute
  find_mapping
  instance_eval(&extension) if extension
  super(extract_values)
end
Instance Public methods
to_i()
# File lib/bitmask_attributes/value_proxy.rb, line 27
def to_i
  inject(0) { |memo, value| memo | @mapping[value] }
end
Instance Private methods
extract_values()
# File lib/bitmask_attributes/value_proxy.rb, line 58
def extract_values
  stored = [@record.send(:read_attribute, @attribute) || 0, 0].max
  @mapping.inject([]) do |values, (value, bitmask)|
    values.tap do
      values << value.to_sym if (stored & bitmask > 0)
    end
  end        
end
find_mapping()
# File lib/bitmask_attributes/value_proxy.rb, line 67
def find_mapping
  unless (@mapping = @record.class.bitmasks[@attribute])
    raise ArgumentError, "Could not find mapping for bitmask attribute :#{@attribute}"
  end
end
serialize!()
# File lib/bitmask_attributes/value_proxy.rb, line 54
def serialize!
  @record.send(:write_attribute, @attribute, to_i)
end
symbolize!()
# File lib/bitmask_attributes/value_proxy.rb, line 43
def symbolize!
  orig_replace(map(&:to_sym))
end
updated!()
# File lib/bitmask_attributes/value_proxy.rb, line 47
def updated!
  validate!
  symbolize!
  uniq!
  serialize!
end
validate!()
# File lib/bitmask_attributes/value_proxy.rb, line 33
def validate!
  each do |value|
    if @mapping.key? value
      true
    else
      raise ArgumentError, "Unsupported value for `#{@attribute}': #{value.inspect}"
    end
  end
end