Class: Jsus::Tag
- Inherits:
-
Object
- Object
- Jsus::Tag
- Defined in:
- lib/jsus/tag.rb
Overview
Tag is basically just a string that contains a package name and a name for class (or not necessarily a class) which the given SourceFile provides/requires/extends/replaces.
"Core/Class" is a tag
Constant Summary collapse
- SEPARATOR =
Default separator of full name parts
"/".freeze
Instance Attribute Summary collapse
-
#namespace ⇒ String
Name without namespace.
Class Method Summary collapse
-
.[](*args) ⇒ Object
Alias for Tag.new.
-
.new(tag_or_name, *args, &block) ⇒ Object
Instantiates a tag.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#empty? ⇒ Boolean
Whether name is empty.
- #eql?(other) ⇒ Boolean
-
#full_name ⇒ String
(also: #to_s)
Full name, including namespace.
-
#full_name=(full_name) ⇒ Object
Assigns full name.
- #hash ⇒ Object
-
#initialize(full_name) ⇒ Tag
constructor
Creates a tag from given string.
-
#inspect ⇒ String
Human-readable representation.
-
#name ⇒ String
Returns the last part of the tag.
-
#name=(name) ⇒ Object
Set name.
-
#normalize(string) ⇒ String
Normalizes name or namespace (converts snake_case to MixedCase).
Constructor Details
#initialize(full_name) ⇒ Tag
Creates a tag from given string.
25 26 27 |
# File 'lib/jsus/tag.rb', line 25 def initialize(full_name) self.full_name = full_name end |
Instance Attribute Details
#namespace ⇒ String
Name without namespace
91 92 93 |
# File 'lib/jsus/tag.rb', line 91 def namespace @namespace end |
Class Method Details
.[](*args) ⇒ Object
Alias for Tag.new
65 66 67 |
# File 'lib/jsus/tag.rb', line 65 def self.[](*args) new(*args) end |
.new(tag_or_name, *args, &block) ⇒ Object
When given a tag instead of tag name, returns the input
Instantiates a tag.
55 56 57 58 59 60 61 |
# File 'lib/jsus/tag.rb', line 55 def self.new(tag_or_name, *args, &block) if tag_or_name.kind_of?(Tag) tag_or_name else super end end |
Instance Method Details
#==(other) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/jsus/tag.rb', line 118 def ==(other) if other.kind_of?(Tag) self.name == other.name && self.namespace == other.namespace else super end end |
#empty? ⇒ Boolean
Returns whether name is empty.
113 114 115 |
# File 'lib/jsus/tag.rb', line 113 def empty? !@name || @name.empty? end |
#eql?(other) ⇒ Boolean
127 128 129 |
# File 'lib/jsus/tag.rb', line 127 def eql?(other) self.==(other) end |
#full_name ⇒ String Also known as: to_s
Full name, including namespace
32 33 34 35 36 37 38 |
# File 'lib/jsus/tag.rb', line 32 def full_name if namespace "#{namespace}#{SEPARATOR}#{name}" else "#{name}" end end |
#full_name=(full_name) ⇒ Object
Assigns full name
45 46 47 48 49 50 |
# File 'lib/jsus/tag.rb', line 45 def full_name=(full_name) @full_name = full_name name_parts = @full_name.split(SEPARATOR) self.namespace = name_parts[0..-2].join(SEPARATOR) if name_parts.size > 1 self.name = name_parts[-1] end |
#hash ⇒ Object
132 133 134 |
# File 'lib/jsus/tag.rb', line 132 def hash [self.name, self.namespace].hash end |
#inspect ⇒ String
Returns human-readable representation.
138 139 140 |
# File 'lib/jsus/tag.rb', line 138 def inspect "<Jsus::Tag: #{full_name}>" end |
#name ⇒ String
Returns the last part of the tag.
76 77 78 |
# File 'lib/jsus/tag.rb', line 76 def name @name end |
#name=(name) ⇒ Object
Set name.
83 84 85 |
# File 'lib/jsus/tag.rb', line 83 def name=(name) @name = normalize(name) end |
#normalize(string) ⇒ String
Normalizes name or namespace (converts snake_case to MixedCase)
104 105 106 107 108 109 |
# File 'lib/jsus/tag.rb', line 104 def normalize(string) return unless string return string if string.include?("*") parts = string.split(SEPARATOR) parts.map {|part| Util::Inflection.random_case_to_mixed_case_preserve_dots(part) }.join(SEPARATOR) end |