Class: Raml::Method

Inherits:
AbstractMethod show all
Defined in:
lib/raml/node/method.rb

Constant Summary collapse

NAMES =
%w(options get head post put delete trace connect patch)

Instance Attribute Summary collapse

Attributes inherited from AbstractMethod

#protocols, #query_parameters, #responses

Attributes included from Headers

#headers

Attributes included from Bodies

#bodies

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

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



10
# File 'lib/raml/node/method.rb', line 10

non_scalar_property :is

Instance Method Details

#apply_traitsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/raml/node/method.rb', line 15

def apply_traits
  # We apply resource traits before method traits, and apply traits at each level in
  # the other they are listed (first to last, left to righ).  Later traits scalar
  # properties overwrite earlier ones.  We end by merging a copy of the method, so
  # that scalar properties in the method hierarchy overwrite those in the traits.
  # We must apply the traits against the method first, as they may contain optional
  # properties that depend on the method hiearchy.
  cloned_self = self.clone

  (@parent.traits + traits).
    map  { |trait| instantiate_trait trait }.
    each { |trait| merge trait }

  merge cloned_self
end

#merge(other) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/raml/node/method.rb', line 32

def merge(other)
  super

  merge_properties other, :headers
  merge_properties other, :query_parameters
  merge_properties other, :bodies
  merge_properties other, :responses

  # We may be applying a resource type, which will result in the merging of a method that may have
  # traits, instead of a trait that can't have no traits.
  if other.is_a? Method
    # 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)
  end

  self
end