Module: Praxis::ResourceDefinition::ClassMethods
- Defined in:
- lib/praxis/resource_definition.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#responses ⇒ Object
readonly
Returns the value of attribute responses.
-
#routing_config ⇒ Object
readonly
Returns the value of attribute routing_config.
Instance Method Summary collapse
- #action(name, &block) ⇒ Object
- #describe ⇒ Object
- #description(text = nil) ⇒ Object
- #headers(**opts, &block) ⇒ Object
- #media_type(media_type = nil) ⇒ Object
- #params(type = Attributor::Struct, **opts, &block) ⇒ Object
- #payload(type = Attributor::Struct, **opts, &block) ⇒ Object
- #response(name, **args) ⇒ Object
-
#routing(&block) ⇒ Object
FIXME: this is inconsistent with the rest of the magic DSL convention.
- #use(trait_name) ⇒ Object
- #version(version = nil) ⇒ Object
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
18 19 20 |
# File 'lib/praxis/resource_definition.rb', line 18 def actions @actions end |
#controller ⇒ Object
Returns the value of attribute controller.
22 23 24 |
# File 'lib/praxis/resource_definition.rb', line 22 def controller @controller end |
#responses ⇒ Object (readonly)
Returns the value of attribute responses.
20 21 22 |
# File 'lib/praxis/resource_definition.rb', line 20 def responses @responses end |
#routing_config ⇒ Object (readonly)
Returns the value of attribute routing_config.
19 20 21 |
# File 'lib/praxis/resource_definition.rb', line 19 def routing_config @routing_config end |
Instance Method Details
#action(name, &block) ⇒ Object
43 44 45 |
# File 'lib/praxis/resource_definition.rb', line 43 def action(name, &block) @actions[name] = ActionDefinition.new(name, self, &block) end |
#describe ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/praxis/resource_definition.rb', line 71 def describe {}.tap do |hash| hash[:description] = description hash[:media_type] = media_type.name if media_type hash[:actions] = actions.values.map(&:describe) end end |
#description(text = nil) ⇒ Object
62 63 64 65 |
# File 'lib/praxis/resource_definition.rb', line 62 def description(text=nil) @description = text if text @description end |
#headers(**opts, &block) ⇒ Object
57 58 59 60 |
# File 'lib/praxis/resource_definition.rb', line 57 def headers(**opts, &block) return @headers unless block @headers = [opts, block] end |
#media_type(media_type = nil) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/praxis/resource_definition.rb', line 29 def media_type(media_type=nil) return @media_type unless media_type if media_type.kind_of?(String) media_type = SimpleMediaType.new(media_type) end @media_type = media_type end |
#params(type = Attributor::Struct, **opts, &block) ⇒ Object
47 48 49 50 |
# File 'lib/praxis/resource_definition.rb', line 47 def params(type=Attributor::Struct, **opts, &block) return @params if type == Attributor::Struct && !block @params = [type, opts, block] end |
#payload(type = Attributor::Struct, **opts, &block) ⇒ Object
52 53 54 55 |
# File 'lib/praxis/resource_definition.rb', line 52 def payload(type=Attributor::Struct, **opts, &block) return @payload if type == Attributor::Struct && !block @payload = [type, opts, block] end |
#response(name, **args) ⇒ Object
67 68 69 |
# File 'lib/praxis/resource_definition.rb', line 67 def response(name, **args) @responses[name] = args end |
#routing(&block) ⇒ Object
FIXME: this is inconsistent with the rest of the magic DSL convention.
25 26 27 |
# File 'lib/praxis/resource_definition.rb', line 25 def routing(&block) @routing_config = block end |
#use(trait_name) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/praxis/resource_definition.rb', line 79 def use(trait_name) unless ApiDefinition.instance.traits.has_key? trait_name raise Exceptions::InvalidTrait.new("Trait #{trait_name} not found") end self.instance_eval(&ApiDefinition.instance.traits[trait_name]) end |
#version(version = nil) ⇒ Object
38 39 40 41 |
# File 'lib/praxis/resource_definition.rb', line 38 def version(version=nil) return @version unless version @version = version end |