Class: ApiBlueprint::Collection
- Inherits:
-
Object
- Object
- ApiBlueprint::Collection
- Defined in:
- lib/api-blueprint/collection.rb
Instance Attribute Summary collapse
-
#blueprints ⇒ Object
readonly
Returns the value of attribute blueprints.
-
#creates ⇒ Object
readonly
Returns the value of attribute creates.
Instance Method Summary collapse
- #create(args) ⇒ Object
-
#initialize(blueprints, creates = nil) ⇒ Collection
constructor
A new instance of Collection.
Constructor Details
#initialize(blueprints, creates = nil) ⇒ Collection
Returns a new instance of Collection.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/api-blueprint/collection.rb', line 6 def initialize(blueprints, creates = nil) unless blueprints.is_a?(Hash) raise DefinitionError, "a collection of blueprints must be a hash" end unless blueprints.values.all? { |bp| bp.is_a? Blueprint } raise DefinitionError, "all collection values must be blueprints" end @blueprints = blueprints @creates = creates end |
Instance Attribute Details
#blueprints ⇒ Object (readonly)
Returns the value of attribute blueprints.
4 5 6 |
# File 'lib/api-blueprint/collection.rb', line 4 def blueprints @blueprints end |
#creates ⇒ Object (readonly)
Returns the value of attribute creates.
4 5 6 |
# File 'lib/api-blueprint/collection.rb', line 4 def creates @creates end |
Instance Method Details
#create(args) ⇒ Object
19 20 21 |
# File 'lib/api-blueprint/collection.rb', line 19 def create(args) creates.present? ? creates.new(args) : args end |