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
- .cardinality(strategy) ⇒ Object
- .embedded?(strategy) ⇒ Boolean
- .gem_name ⇒ Object
- .has_strategy?(cardinality, strategy) ⇒ Boolean
- .inline_strategy?(strategy) ⇒ Boolean
- .role_dir ⇒ Object
- .role_strategies(cardinality) ⇒ Object
Class Method Details
.cardinality(strategy) ⇒ Object
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
16 17 18 |
# File 'lib/roles_generic/strategy.rb', line 16 def strategy strategy.to_s.include? 'embed' end |
.gem_name ⇒ Object
12 13 14 |
# File 'lib/roles_generic/strategy.rb', line 12 def gem_name :roles_generic end |
.has_strategy?(cardinality, strategy) ⇒ 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
29 30 31 |
# File 'lib/roles_generic/strategy.rb', line 29 def inline_strategy? strategy !NON_INLINE_STRATEGIES.include? strategy.to_sym end |
.role_dir ⇒ Object
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 |