Module: Raml::Merge

Included in:
AbstractMethod, AbstractResource, Body, Parameter::AbstractParameter, Response
Defined in:
lib/raml/mixin/merge.rb

Instance Method Summary collapse

Instance Method Details

#merge(other) ⇒ Object


4
5
6
7
8
9
10
# File 'lib/raml/mixin/merge.rb', line 4

def merge(other)
  other.scalar_properties.each do |prop|
    prop_var  = "@#{prop}"
    prop_val = other.instance_variable_get prop_var
    instance_variable_set prop_var, prop_val unless prop_val.nil?
  end
end

#merge_properties(other, type) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
# File 'lib/raml/mixin/merge.rb', line 12

def merge_properties(other, type)
	match, no_match = other.send(type).values.partition { |param| self.send(type).has_key? param.name }

	match.each { |param| self.send(type)[param.name].merge param }

  # if its an optional property, and there is no match in self, don't merge it.
  no_match.reject! { |node| node.optional      }
  no_match.map!    { |node| node.clone         }
  no_match.each    { |node| node.parent = self }
	@children += no_match
end