Module: Roles::Strategy

Defined in:
lib/roles_generic/strategy.rb

Constant Summary collapse

NON_INLINE_STRATEGIES =
[:one_role, :many_roles, :embed_one_role, :embed_many_roles]

Class Method Summary collapse

Class Method Details

.cardinality(strategy) ⇒ Object

Raises:

  • (ArgumentError)


33
34
35
36
37
38
# File 'lib/roles_generic/strategy.rb', line 33

def cardinality strategy
  [:single, :multi].each do |cardinality|             
    return cardinality if has_strategy?(cardinality, strategy)
  end
  raise ArgumentError, "Strategy #{strategy}  is not registered as either a single or multi cardinality role strategy"
end

.embedded?(strategy) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/roles_generic/strategy.rb', line 16

def embedded? strategy
  strategy.to_s.include? 'embed'
end

.gem_nameObject



12
13
14
# File 'lib/roles_generic/strategy.rb', line 12

def gem_name
  :roles_generic
end

.has_strategy?(cardinality, strategy) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/roles_generic/strategy.rb', line 25

def has_strategy? cardinality, strategy
  role_strategies(cardinality).include?(strategy)
end

.inline_strategy?(strategy) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/roles_generic/strategy.rb', line 29

def inline_strategy? strategy
  !NON_INLINE_STRATEGIES.include? strategy.to_sym      
end

.role_dirObject



8
9
10
# File 'lib/roles_generic/strategy.rb', line 8

def role_dir
  File.dirname(__FILE__)
end

.role_strategies(cardinality) ⇒ Object



20
21
22
23
# File 'lib/roles_generic/strategy.rb', line 20

def role_strategies cardinality
  pattern = role_dir + "/strategy/#{cardinality}/*.rb"
  Dir.glob(pattern).file_names(:rb).to_symbols
end