Class: Shale::Schema::Compiler::Complex Private
- Inherits:
-
Object
- Object
- Shale::Schema::Compiler::Complex
- 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
Instance Attribute Summary collapse
-
#id ⇒ String
readonly
private
Return id.
-
#properties ⇒ Array<Shale::Schema::Compiler::Property>
readonly
private
Return properties.
-
#root_name ⇒ String
private
Return base name.
Instance Method Summary collapse
-
#add_property(property) ⇒ Object
private
Add property to Object.
-
#file_name ⇒ String
private
Return file name.
-
#initialize(id, root_name, package) ⇒ Complex
constructor
private
Initialize object.
-
#modules ⇒ Array<String>
private
Return module names.
-
#name ⇒ String
private
Return namespaced name.
-
#references ⇒ Array<Shale::Schema::Compiler::Property>
private
Return references.
-
#relative_path(target) ⇒ String
private
Return relative path to target.
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
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
#id ⇒ String (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
17 18 19 |
# File 'lib/shale/schema/compiler/complex.rb', line 17 def id @id end |
#properties ⇒ Array<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 |
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
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_name ⇒ 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 file name
79 80 81 |
# File 'lib/shale/schema/compiler/complex.rb', line 79 def file_name Utils.snake_case(name) end |
#modules ⇒ Array<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
70 71 72 |
# File 'lib/shale/schema/compiler/complex.rb', line 70 def modules (@package || '').split('::') end |
#name ⇒ 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 namespaced name
61 62 63 |
# File 'lib/shale/schema/compiler/complex.rb', line 61 def name Utils.classify([@package, @root_name].compact.join('::')) end |
#references ⇒ Array<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
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 |