Methods
- E
- F
- N
- S
- T
- U
- V
Class Public methods
Source: show
# 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
Source: show
# File lib/bitmask_attributes/value_proxy.rb, line 27 def to_i inject(0) { |memo, value| memo | @mapping[value] } end
Instance Private methods
Source: show
# 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
Source: show
# 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
Source: show
# File lib/bitmask_attributes/value_proxy.rb, line 54 def serialize! @record.send(:write_attribute, @attribute, to_i) end
Source: show
# File lib/bitmask_attributes/value_proxy.rb, line 43 def symbolize! orig_replace(map(&:to_sym)) end
Source: show
# File lib/bitmask_attributes/value_proxy.rb, line 47 def updated! validate! symbolize! uniq! serialize! end
Source: show
# 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