Sha256: 0dc0f500ea36b9704bc66f1ba2e66f4e324f4312b9e216be17bf78187cab6bfc

Contents?: true

Size: 699 Bytes

Versions: 3

Compression:

Stored size: 699 Bytes

Contents

require 'bitmask_attributes/definition'
require 'bitmask_attributes/value_proxy'

module BitmaskAttributes
  extend ActiveSupport::Concern

  module ClassMethods
    def bitmask(attribute, options={}, &extension)
      unless options[:as] && options[:as].kind_of?(Array)
        raise ArgumentError, "Must provide an Array :as option"
      end
      bitmask_definitions[attribute] = Definition.new(attribute, options[:as].to_a, &extension)
      bitmask_definitions[attribute].install_on(self)
    end
    
    def bitmask_definitions
      @bitmask_definitions ||= {}
    end
    
    def bitmasks
      @bitmasks ||= {}
    end    
  end  
end

ActiveRecord::Base.send :include, BitmaskAttributes

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bitmask_attributes-0.2.1 lib/bitmask_attributes.rb
bitmask_attributes-0.1.1 lib/bitmask_attributes.rb
bitmask_attributes-0.1.0 lib/bitmask_attributes.rb