Module: Platanus::Canned2::Definition::ClassMethods
- Defined in:
- lib/platanus/canned2.rb
Constant Summary collapse
- @@tests =
{}
- @@profiles =
{}
Instance Method Summary collapse
- #can?(_ctx, _profile, _action) ⇒ Boolean
-
#profile(_name, _options = {}, &_block) ⇒ Object
Creates a new profile and evaluates the given block using the profile context.
-
#test(_name, &_block) ⇒ Object
Defines a new test that can be used in “certifies” instructions.
Instance Method Details
#can?(_ctx, _profile, _action) ⇒ Boolean
331 332 333 334 335 336 337 338 339 340 |
# File 'lib/platanus/canned2.rb', line 331 def can?(_ctx, _profile, _action) profile = @@profiles[_profile.to_s] return if profile.nil? profile.rules[_action].any? do |rule| next true if rule.nil? rule_ctx = RuleContext.new _ctx, @@tests, profile.def_matcher, profile.def_resource rule_ctx.instance_eval(&rule) rule_ctx.passed? end end |
#profile(_name, _options = {}, &_block) ⇒ Object
Creates a new profile and evaluates the given block using the profile context.
321 322 323 324 325 326 327 328 |
# File 'lib/platanus/canned2.rb', line 321 def profile(_name, ={}, &_block) profile = @@profiles[_name.to_s] = Profile.new( @@profiles[.fetch(:inherits, nil).to_s], .fetch(:matcher, :equals), .fetch(:resource, nil) ) profile.instance_eval &_block end |
#test(_name, &_block) ⇒ Object
Defines a new test that can be used in “certifies” instructions
IMPORTANT Tests are executed in the controller’s context and passed the tested resource as parameter (only if arity == 1)
308 309 310 311 312 |
# File 'lib/platanus/canned2.rb', line 308 def test(_name, &_block) raise SetupError.new "Invalid test arity for '#{_name}'" if _block.arity > 1 raise SetupError.new "Duplicated test identifier" if @@tests.has_key? _name @@tests[_name] = _block end |