Skip to content

Commit

Permalink
indexmask
Browse files Browse the repository at this point in the history
  • Loading branch information
afly committed Feb 12, 2012
1 parent ede84ec commit 80f745d
Showing 1 changed file with 5 additions and 9 deletions.
Expand Up @@ -9,13 +9,14 @@ def initialize(attribute, values=[], &extension)
end

def install_on(model)
validate_for model
debugger
#validate_for model
#generate_bitmasks_on model
override model
#create_convenience_class_method_on model
#create_convenience_instance_methods_on model
#create_scopes_on model
#create_attribute_methods_on model
create_attribute_methods_on model
end

private
Expand Down Expand Up @@ -47,15 +48,15 @@ def override(model)
def override_getter_on(model)
model.class_eval %(
def #{attribute}
@#{attribute} ||= self.class.bitmask_definitions[:#{attribute}][(model.send(:read_attribute, @attribute) || -1)]
@#{attribute} ||= self.class.bitmask_definitions[:#{attribute}][( self[:#{attribute}] || -1)]
end
)
end

def override_setter_on(model)
model.class_eval %(
def #{attribute}=(raw_value)
@#{attribute} = self.class.bitmask_definitions[:#{attribute}].find_index raw_value
@#{attribute} = self.class.bitmask_definitions[:#{attribute}].find_index(raw_value )
end
)
end
Expand All @@ -66,11 +67,6 @@ def create_attribute_methods_on(model)
def self.values_for_#{attribute} # def self.values_for_numbers
#{values} # [:one, :two, :three]
end # end
def self.values_with_bitmask_for_#{attribute}
#{values}.map do |value|
[value, bitmasks[:#{attribute}][value] ]
end # [[:one,1], [:two,2], [:three,4]]
end
)
end

Expand Down

0 comments on commit 80f745d

Please sign in to comment.