Class: RestfulDocGenerator::Resource
- Inherits:
-
Object
- Object
- RestfulDocGenerator::Resource
- Defined in:
- lib/praxis/tasks/api_docs.rb
Instance Attribute Summary collapse
-
#controller_config ⇒ Object
Returns the value of attribute controller_config.
-
#media_type ⇒ Object
Returns the value of attribute media_type.
-
#reachable_types ⇒ Object
Returns the value of attribute reachable_types.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #add_to_reachable(found) ⇒ Object
-
#id ⇒ Object
TODO: I think that the “id”/“name” of a resource should be provided by the definition/controller…not derived here.
-
#initialize(definition) ⇒ Resource
constructor
A new instance of Resource.
Constructor Details
#initialize(definition) ⇒ Resource
Returns a new instance of Resource.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/praxis/tasks/api_docs.rb', line 47 def initialize( definition ) @controller_config = definition if controller_config.version == 'n/a' @version = 'unversioned' else @version = controller_config.version end @media_type = controller_config.media_type @reachable_types = Set.new # Collect reachable types from the media_type if any (plus itself) if @media_type && ! @media_type.is_a?(Praxis::SimpleMediaType) add_to_reachable RestfulDocGenerator.inspect_attributes(@media_type) @media_type.attributes.each do |name, attr| add_to_reachable RestfulDocGenerator.inspect_attributes(attr) end @generated_example = @media_type.example(self.id) end # Collect reachable types from the params and payload definitions @controller_config.actions.each do |name, action_config| add_to_reachable RestfulDocGenerator.inspect_attributes(action_config.params) add_to_reachable RestfulDocGenerator.inspect_attributes(action_config.payload) end end |
Instance Attribute Details
#controller_config ⇒ Object
Returns the value of attribute controller_config.
45 46 47 |
# File 'lib/praxis/tasks/api_docs.rb', line 45 def controller_config @controller_config end |
#media_type ⇒ Object
Returns the value of attribute media_type.
45 46 47 |
# File 'lib/praxis/tasks/api_docs.rb', line 45 def media_type @media_type end |
#reachable_types ⇒ Object
Returns the value of attribute reachable_types.
45 46 47 |
# File 'lib/praxis/tasks/api_docs.rb', line 45 def reachable_types @reachable_types end |
#version ⇒ Object
Returns the value of attribute version.
45 46 47 |
# File 'lib/praxis/tasks/api_docs.rb', line 45 def version @version end |
Instance Method Details
#add_to_reachable(found) ⇒ Object
84 85 86 87 |
# File 'lib/praxis/tasks/api_docs.rb', line 84 def add_to_reachable( found ) return if found == nil @reachable_types += found end |
#id ⇒ Object
TODO: I think that the “id”/“name” of a resource should be provided by the definition/controller…not derived here
75 76 77 78 79 80 81 82 |
# File 'lib/praxis/tasks/api_docs.rb', line 75 def id if @controller_config.controller @controller_config.controller.name else # If an API doesn't quite have the controller defined, let's use the name from the resource definition @controller_config.name end end |