Class: Raml::AbstractResource

Inherits:
PropertiesNode show all
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

Resource, ResourceType::Instance

Instance Attribute Summary collapse

Attributes included from Parent

#children

Attributes included from Documentable

#description, #display_name

Attributes inherited from PropertiesNode

#optional

Attributes inherited from Node

#name, #parent

Instance Method Summary collapse

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

#merge_properties

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

#initialize

Constructor Details

This class inherits a constructor from Raml::PropertiesNode

Instance Attribute Details

#base_uri_parametersHash<String, Raml::Parameter::BaseUriParameter> (readonly)

Returns the base URI parameters, keyed by the parameter name.

Returns:



# File 'lib/raml/node/abstract_resource.rb', line 12

#methodsHash<String, Raml::Method> (readonly)

Returns the methods, keyed by the method name.

Returns:



# File 'lib/raml/node/abstract_resource.rb', line 20

#traitsArray<Raml::Trait, Raml::TraitReference> (readonly)

Returns the traits and trait references.

Returns:



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}?" }

#typeRaml::ResourceType, Raml::ResourceTypeReference (readonly)

Returns ] the resource type or resource type references, if any.

Returns:



4
# File 'lib/raml/node/abstract_resource_circular.rb', line 4

child_of :type, [ Raml::ResourceType, Raml::ResourceTypeReference ]

#uri_parametersHash<String, Raml::Parameter::UriParameter> (readonly)

Returns the URI parameters, keyed by the parameter name.

Returns:



# File 'lib/raml/node/abstract_resource.rb', line 16

Instance Method Details

#apply_resource_typeObject



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

Raises:



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_pathString

Returns the resource’s full path.

Returns:

  • (String)

    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_nameString

Returns the last non regex resource name

Returns:

  • (String)

    the last non request 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