Class: Praxis::ApiDefinition
- Inherits:
-
Object
- Object
- Praxis::ApiDefinition
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/praxis/api_definition.rb
Instance Attribute Summary collapse
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
-
#traits ⇒ Object
readonly
Returns the value of attribute traits.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ApiDefinition
constructor
A new instance of ApiDefinition.
- #response(name) ⇒ Object
- #response_template(name, &block) ⇒ Object
- #trait(name, &block) ⇒ Object
Constructor Details
#initialize ⇒ ApiDefinition
Returns a new instance of ApiDefinition.
22 23 24 25 |
# File 'lib/praxis/api_definition.rb', line 22 def initialize @responses = Hash.new @traits = Hash.new end |
Instance Attribute Details
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
11 12 13 |
# File 'lib/praxis/api_definition.rb', line 11 def responses @responses end |
#traits ⇒ Object (readonly)
Returns the value of attribute traits.
10 11 12 |
# File 'lib/praxis/api_definition.rb', line 10 def traits @traits end |
Class Method Details
.define(&block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/praxis/api_definition.rb', line 13 def self.define(&block) if block.arity == 0 self.instance.instance_eval(&block) else yield(self.instance) end end |
Instance Method Details
#response(name) ⇒ Object
31 32 33 34 35 |
# File 'lib/praxis/api_definition.rb', line 31 def response(name) return @responses.fetch(name) do raise ArgumentError, "no response template defined with name #{name.inspect}. Are you forgetting to register it with ApiDefinition?" end end |
#response_template(name, &block) ⇒ Object
27 28 29 |
# File 'lib/praxis/api_definition.rb', line 27 def response_template(name, &block) @responses[name] = Praxis::ResponseTemplate.new(name, &block) end |
#trait(name, &block) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/praxis/api_definition.rb', line 37 def trait(name, &block) if self.traits.has_key? name raise Exceptions::InvalidTrait.new("Overwriting a previous trait with the same name (#{name})") end self.traits[name] = block end |