Parent

Included Modules

DataMapper::Property::Flag

Public Class Methods

new(model, name, options = {}) click to toggle source
    # File lib/dm-types/flag.rb, line 10
10:       def initialize(model, name, options = {})
11:         super
12: 
13:         @flag_map = {}
14: 
15:         flags = options.fetch(:flags, self.class.flags)
16:         flags.each_with_index do |flag, i|
17:           flag_map[i] = flag
18:         end
19:       end

Public Instance Methods

dump(value) click to toggle source
    # File lib/dm-types/flag.rb, line 37
37:       def dump(value)
38:         unless value.nil?
39:           flags = Array(value).map { |flag| flag.to_sym }
40:           flags.uniq!
41: 
42:           flag = 0
43: 
44:           flag_map.invert.values_at(*flags).each do |i|
45:             next if i.nil?
46:             flag += (1 << i)
47:           end
48: 
49:           flag
50:         end
51:       end
load(value) click to toggle source
    # File lib/dm-types/flag.rb, line 21
21:       def load(value)
22:         return [] if value.nil? || value <= 0
23: 
24:         begin
25:           matches = []
26: 
27:           0.upto(flag_map.size - 1) do |i|
28:             matches << flag_map[i] if value[i] == 1
29:           end
30: 
31:           matches.compact
32:         rescue TypeError, Errno::EDOM
33:           []
34:         end
35:       end
typecast(value) click to toggle source
    # File lib/dm-types/flag.rb, line 53
53:       def typecast(value)
54:         case value
55:           when nil     then nil
56:           when ::Array then value.map { |v| v.to_sym }
57:           else [value.to_sym]
58:         end
59:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.