Class: Shale::Schema::Compiler::Complex Private

Inherits:
Object
  • Object
show all
Defined in:
lib/shale/schema/compiler/complex.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class representing Shale’s complex type

Direct Known Subclasses

XMLComplex

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, root_name, package) ⇒ Complex

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize object

Parameters:



40
41
42
43
44
45
# File 'lib/shale/schema/compiler/complex.rb', line 40

def initialize(id, root_name, package)
  @id = id
  @root_name = root_name
  @package = package ? Utils.classify(package) : nil
  @properties = []
end

Instance Attribute Details

#idString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return id

Returns:



17
18
19
# File 'lib/shale/schema/compiler/complex.rb', line 17

def id
  @id
end

#propertiesArray<Shale::Schema::Compiler::Property> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return properties



24
25
26
# File 'lib/shale/schema/compiler/complex.rb', line 24

def properties
  @properties
end

#root_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return base name

Returns:



52
53
54
# File 'lib/shale/schema/compiler/complex.rb', line 52

def root_name
  Utils.classify(@root_name)
end

Instance Method Details

#add_property(property) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Add property to Object

Parameters:



124
125
126
127
128
# File 'lib/shale/schema/compiler/complex.rb', line 124

def add_property(property)
  unless @properties.find { |e| e.mapping_name == property.mapping_name }
    @properties << property
  end
end

#file_nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return file name

Returns:



79
80
81
# File 'lib/shale/schema/compiler/complex.rb', line 79

def file_name
  Utils.snake_case(name)
end

#modulesArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return module names

Returns:



70
71
72
# File 'lib/shale/schema/compiler/complex.rb', line 70

def modules
  (@package || '').split('::')
end

#nameString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return namespaced name

Returns:



61
62
63
# File 'lib/shale/schema/compiler/complex.rb', line 61

def name
  Utils.classify([@package, @root_name].compact.join('::'))
end

#referencesArray<Shale::Schema::Compiler::Property>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return references



112
113
114
115
116
117
# File 'lib/shale/schema/compiler/complex.rb', line 112

def references
  @properties
    .filter { |e| e.type.is_a?(self.class) && e.type != self }
    .uniq { |e| e.type.id }
    .sort { |a, b| a.type.file_name <=> b.type.file_name }
end

#relative_path(target) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return relative path to target

Parameters:

Returns:



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/shale/schema/compiler/complex.rb', line 90

def relative_path(target)
  base_paths = file_name.split('/')
  target_paths = target.split('/')

  common_paths_length = 0

  base_paths.length.times do |i|
    break if base_paths[i] != target_paths[i]
    common_paths_length += 1
  end

  unique_base_paths = base_paths[common_paths_length..-1]
  unique_target_paths = target_paths[common_paths_length..-1]

  ((0...unique_base_paths.length - 1).map { '..' } + unique_target_paths).join('/')
end