Class: DataMapper::Types::Flag
- Object
- DataMapper::Types::Flag
Public Visibility
Public Instance Methods Inherited from Object
Public Class Method Details
[]
public
[](*flags)
[View source]
24 25 26
# File 'dm-more/dm-types/lib/dm-types/flag.rb', line 24 def self.[](*flags) new(*flags) end
dump
public
dump(value, property)
[View source]
43 44 45 46 47
# File 'dm-more/dm-types/lib/dm-types/flag.rb', line 43 def self.dump(value, property) flags = value.is_a?(Array) ? value : [value] flags.map!{|f| f.to_sym} flag_map.invert.values_at(*flags.flatten).compact.inject(0) {|sum, i| sum + i} end
flag_map
public
flag_map=(value)
[View source]
9 10 11
# File 'dm-more/dm-types/lib/dm-types/flag.rb', line 9 def self.flag_map=(value) @flag_map = value end
load
public
load(value, property)
[View source]
28 29 30 31 32 33 34 35 36 37 38 39 40 41
# File 'dm-more/dm-types/lib/dm-types/flag.rb', line 28 def self.load(value, property) begin matches = [] 0.upto((Math.log(value) / Math.log(2)).ceil) do |i| pow = 2 ** i matches << flag_map[pow] if value & pow == pow end matches.compact rescue TypeError, Errno::EDOM [] end end