lib/maintain/maintainer.rb in maintain-0.2.9 vs lib/maintain/maintainer.rb in maintain-0.2.10

- old
+ new

@@ -39,11 +39,15 @@ !!@bitmask end def default(state = nil) if state - @default = state + if bitmask? + @default = (@default || 0) | states[state][:value] + else + @default = state + end else @default end end @@ -106,13 +110,10 @@ def state(name, value = nil, options = {}) if value.is_a?(Hash) options = value value = nil end - if options.has_key?(:default) - default(name) - end @increment ||= 0 if bitmask? unless value.is_a?(Integer) value = @increment end @@ -123,9 +124,15 @@ value ||= name states[name] = {:compare_value => !bitmask? && value.is_a?(Integer) ? value : @increment, :value => value} @increment += 1 if !maintainee.respond_to?(name) && back_end back_end.state maintainee, name, @attribute, value.is_a?(Symbol) ? value.to_s : value + end + + # We need the states hash to contain the compare_value for this guy before we can set defaults on the bitmask, + # since the default should actually be a bitmask of all possible default states + if options.has_key?(:default) + default(name) end # Now we're going to add proxies to test for state. These methods only get added if a # method of their name doesn't already exist. boolean_method = "#{name}?" \ No newline at end of file