Class: Restspec::Requirements::Requirement
- Inherits:
-
Object
- Object
- Restspec::Requirements::Requirement
- Defined in:
- lib/restspec/requirements/requirement.rb
Class Attribute Summary collapse
-
.requirements ⇒ Object
readonly
Returns the value of attribute requirements.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #add_error(error) ⇒ Object
- #assert! ⇒ Object
- #execute ⇒ Object
- #execution(&execution_block) ⇒ Object
-
#initialize(name) ⇒ Requirement
constructor
A new instance of Requirement.
Constructor Details
#initialize(name) ⇒ Requirement
Returns a new instance of Requirement.
6 7 8 9 10 |
# File 'lib/restspec/requirements/requirement.rb', line 6 def initialize(name) self.name = name self.errors = [] extend Restspec::RSpec::ApiHelpers end |
Class Attribute Details
.requirements ⇒ Object
Returns the value of attribute requirements.
35 36 37 |
# File 'lib/restspec/requirements/requirement.rb', line 35 def requirements @requirements end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
4 5 6 |
# File 'lib/restspec/requirements/requirement.rb', line 4 def errors @errors end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/restspec/requirements/requirement.rb', line 4 def name @name end |
Class Method Details
.create(name) ⇒ Object
45 46 47 |
# File 'lib/restspec/requirements/requirement.rb', line 45 def create(name) self.new(name).tap { |r| requirements << r } end |
.find_by_name(name) ⇒ Object
41 42 43 |
# File 'lib/restspec/requirements/requirement.rb', line 41 def find_by_name(name) requirements.find { |r| r.name == name } end |
.get_or_create(name) ⇒ Object
37 38 39 |
# File 'lib/restspec/requirements/requirement.rb', line 37 def get_or_create(name) find_by_name(name) || create(name) end |
Instance Method Details
#add_error(error) ⇒ Object
26 27 28 |
# File 'lib/restspec/requirements/requirement.rb', line 26 def add_error(error) errors << error end |
#assert! ⇒ Object
19 20 21 22 23 24 |
# File 'lib/restspec/requirements/requirement.rb', line 19 def assert! execute if errors.any? raise errors.join(' | ') end end |
#execute ⇒ Object
16 17 |
# File 'lib/restspec/requirements/requirement.rb', line 16 def execute end |
#execution(&execution_block) ⇒ Object
12 13 14 |
# File 'lib/restspec/requirements/requirement.rb', line 12 def execution(&execution_block) define_singleton_method(:execute, &execution_block) end |