Class: Brujula::TypeExtender::ResourceType

Inherits:
Object
  • Object
show all
Defined in:
lib/brujula/type_extender/resource_type.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(definition:) ⇒ ResourceType

Returns a new instance of ResourceType.



6
7
8
# File 'lib/brujula/type_extender/resource_type.rb', line 6

def initialize(definition:)
  @definition = definition
end

Instance Attribute Details

#definitionObject (readonly)

Returns the value of attribute definition.



4
5
6
# File 'lib/brujula/type_extender/resource_type.rb', line 4

def definition
  @definition
end

Instance Method Details

#callObject



10
11
12
13
14
# File 'lib/brujula/type_extender/resource_type.rb', line 10

def call
  return definition if definition.type.nil?

  extended_object
end

#extended_objectObject



24
25
26
27
28
# File 'lib/brujula/type_extender/resource_type.rb', line 24

def extended_object
  @extended_object ||= Brujula::Mergers::ObjectMerger.new(
    superinstance: parent_definition, instance: definition
  ).call
end

#parent_definitionObject



16
17
18
19
20
21
22
# File 'lib/brujula/type_extender/resource_type.rb', line 16

def parent_definition
  if within_root_resource_types?  # maybe its not preload
    definition.parent.fetch(definition.type)
  else
    definition.root.resource_types.fetch(definition.type)
  end
end

#within_root_resource_types?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/brujula/type_extender/resource_type.rb', line 30

def within_root_resource_types?
  definition.parent.is_a?(Brujula::MapObject) &&
  definition.parent.parent.is_a?(Brujula::Raml::V1_0::Root)
end