Module: Canned::Definition::ClassMethods
- Defined in:
- lib/canned/definition.rb
Instance Method Summary collapse
-
#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.
-
#validate(_ctx, _acting_as, _action) ⇒ Object
Returns true if _action is avaliable for _profile under the given _ctx.
Instance Method Details
#profile(_name, _options = {}, &_block) ⇒ Object
Creates a new profile and evaluates the given block using the profile context.
56 57 58 59 60 61 62 63 |
# File 'lib/canned/definition.rb', line 56 def profile(_name, ={}, &_block) _name = _name.to_sym raise Canned::SetupError.new "Duplicated profile identifier '#{_name}'" if profiles.has_key? _name profile = Canned::Profile.new ProfileDsl.new(profile, profiles).instance_eval &_block profiles[_name] = profile end |
#test(_name, &_block) ⇒ Object
Defines a new test that can be used in “certifies” instructions
IMPORTANT Tests are executed in the same context as upon blocks,
47 48 49 |
# File 'lib/canned/definition.rb', line 47 def test(_name, &_block) raise SetupError.new "Duplicated test identifier" if tests.has_key? _name end |
#validate(_ctx, _acting_as, _action) ⇒ Object
Returns true if _action is avaliable for _profile under the given _ctx.
71 72 73 74 75 76 |
# File 'lib/canned/definition.rb', line 71 def validate(_ctx, _acting_as, _action) profile = profiles[_acting_as.to_sym] raise Canned::SetupError.new "Profile not found '#{_acting_as}'" if profile.nil? _ctx = Canned::Context::Default.new(_ctx, tests, InmmutableStack.new) profile.validate _ctx, Array(_action) end |