Class: DataMapper::Types::Flag
- Defined in:
- lib/gems/dm-types-0.9.9/lib/dm-types/flag.rb
Class Method Summary collapse
- .[](*flags) ⇒ Object
- .dump(value, property) ⇒ Object
- .flag_map ⇒ Object
- .flag_map=(value) ⇒ Object
- .inherited(target) ⇒ Object
- .load(value, property) ⇒ Object
- .new(*flags) ⇒ Object
- .typecast(value, property) ⇒ Object
Class Method Details
.[](*flags) ⇒ Object
27 28 29 |
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/flag.rb', line 27 def self.[](*flags) new(*flags) end |
.dump(value, property) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/flag.rb', line 46 def self.dump(value, property) return if value.nil? 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 ⇒ Object
8 9 10 |
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/flag.rb', line 8 def self.flag_map @flag_map end |
.flag_map=(value) ⇒ Object
12 13 14 |
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/flag.rb', line 12 def self.flag_map=(value) @flag_map = value end |
.inherited(target) ⇒ Object
4 5 6 |
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/flag.rb', line 4 def self.inherited(target) target.instance_variable_set("@primitive", self.primitive) end |
.load(value, property) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/flag.rb', line 31 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 |