Class: Raml::AbstractResource
- Inherits:
-
PropertiesNode
- Object
- Node
- PropertiesNode
- Raml::AbstractResource
- Includes:
- Documentable, Global, Merge, Parent, SecuredBy, Validation
- Defined in:
- lib/raml/node/abstract_resource.rb,
lib/raml/node/abstract_resource_circular.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base_uri_parameters ⇒ Hash<String, Raml::Parameter::BaseUriParameter>
readonly
The base URI parameters, keyed by the parameter name.
-
#methods ⇒ Hash<String, Raml::Method>
readonly
The methods, keyed by the method name.
-
#traits ⇒ Array<Raml::Trait, Raml::TraitReference>
readonly
The traits and trait references.
-
#type ⇒ Raml::ResourceType, Raml::ResourceTypeReference
readonly
] the resource type or resource type references, if any.
-
#uri_parameters ⇒ Hash<String, Raml::Parameter::UriParameter>
readonly
The URI parameters, keyed by the parameter name.
Attributes included from Parent
Attributes included from Documentable
Attributes inherited from PropertiesNode
Attributes inherited from Node
Instance Method Summary collapse
- #apply_resource_type ⇒ Object
- #merge(other) ⇒ Object
-
#resource_path ⇒ String
Returns the resource’s full path.
-
#resource_path_name ⇒ String
Returns the last non regex resource name.
Methods included from SecuredBy
#_validate_secured_by, #parse_secured_by
Methods included from Validation
#classes_to_s, #validate_array, #validate_hash, #validate_property, #validate_string
Methods included from Merge
Methods included from Global
#default_media_type, #resource_type_declarations, #schema_declarations, #security_scheme_declarations, #trait_declarations
Methods inherited from PropertiesNode
#_regexp_property, #initialize, #non_scalar_properties, #scalar_properties
Methods inherited from Node
Constructor Details
This class inherits a constructor from Raml::PropertiesNode
Instance Attribute Details
#base_uri_parameters ⇒ Hash<String, Raml::Parameter::BaseUriParameter> (readonly)
Returns the base URI parameters, keyed by the parameter name.
|
|
# File 'lib/raml/node/abstract_resource.rb', line 12
|
#methods ⇒ Hash<String, Raml::Method> (readonly)
Returns the methods, keyed by the method name.
|
|
# File 'lib/raml/node/abstract_resource.rb', line 20
|
#traits ⇒ Array<Raml::Trait, Raml::TraitReference> (readonly)
Returns the traits and trait references.
26 27 |
# File 'lib/raml/node/abstract_resource.rb', line 26 non_scalar_property :uri_parameters, :base_uri_parameters, :is, :type, :secured_by, *Raml::Method::NAMES, *Raml::Method::NAMES.map { |m| "#{m}?" } |
#type ⇒ Raml::ResourceType, Raml::ResourceTypeReference (readonly)
Returns ] the resource type or resource type references, if any.
4 |
# File 'lib/raml/node/abstract_resource_circular.rb', line 4 child_of :type, [ Raml::ResourceType, Raml::ResourceTypeReference ] |
#uri_parameters ⇒ Hash<String, Raml::Parameter::UriParameter> (readonly)
Returns the URI parameters, keyed by the parameter name.
|
|
# File 'lib/raml/node/abstract_resource.rb', line 16
|
Instance Method Details
#apply_resource_type ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/raml/node/abstract_resource.rb', line 37 def apply_resource_type if type # We clone the resource as it currently is; apply the resource type to the # resource, so that optional properties are correctly evaluated; then we # apply the cloned resource with the initial state, so that scalar properties # in the resource override the ones in the resource type. cloned_self = self.clone merge instantiate_resource_type merge cloned_self end end |
#merge(other) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/raml/node/abstract_resource.rb', line 50 def merge(other) raise MergeError, "Trying to merge #{other.class} into Resource." unless other.is_a? ResourceType::Instance or other.is_a? Resource super merge_properties other, :methods merge_properties other, :base_uri_parameters merge_properties other, :uri_parameters # merge traits. insert the non-matching ones in the front, so they have the least priority. match, no_match = other.traits.partition do |other_trait| if other_trait.is_a? Trait false else # TraitReference self.traits.any? do |self_trait| self_trait.is_a?(TraitReference) && self_trait.name == other_trait.name && self_trait.parameters == other_trait.parameters end end end @children.unshift(*no_match) self end |
#resource_path ⇒ String
Returns the resource’s full path.
78 79 80 |
# File 'lib/raml/node/abstract_resource.rb', line 78 def resource_path @parent.resource_path + self.name end |
#resource_path_name ⇒ String
Returns the last non regex resource name
85 86 87 88 89 |
# File 'lib/raml/node/abstract_resource.rb', line 85 def resource_path_name resource_path.split('/').reverse.detect do |pathPart| !pathPart.match(/[{}]/) end || "" end |