Class: ActiveWorker::ModesMap

Inherits:
Object
  • Object
show all
Defined in:
lib/active_worker/modes_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModesMap

Returns a new instance of ModesMap.



6
7
8
9
10
11
12
# File 'lib/active_worker/modes_map.rb', line 6

def initialize
  @modes_hash = Hash.new do |hash, key|
    inner_hash = {}
    hash[key] = inner_hash
    inner_hash
  end
end

Instance Attribute Details

#modes_hashObject (readonly)

Returns the value of attribute modes_hash.



4
5
6
# File 'lib/active_worker/modes_map.rb', line 4

def modes_hash
  @modes_hash
end

Instance Method Details

#add_mode(mode_name, field_maps) ⇒ Object



14
15
16
# File 'lib/active_worker/modes_map.rb', line 14

def add_mode(mode_name, field_maps)
  modes_hash[normalize_mode_name(mode_name)].merge! field_maps
end

#mode(mode_name) ⇒ Object



30
31
32
33
34
# File 'lib/active_worker/modes_map.rb', line 30

def mode(mode_name)
  if supports? mode_name
    modes_hash[normalize_mode_name(mode_name)]
  end
end

#modesObject



22
23
24
# File 'lib/active_worker/modes_map.rb', line 22

def modes
  modes_hash.keys
end

#normalize_mode_name(mode_name) ⇒ Object



18
19
20
# File 'lib/active_worker/modes_map.rb', line 18

def normalize_mode_name(mode_name)
  mode_name.to_sym
end

#supports?(mode_name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/active_worker/modes_map.rb', line 26

def supports?(mode_name)
  modes.include? normalize_mode_name(mode_name)
end