Class: ApiDiff::Type
- Inherits:
-
Object
- Object
- ApiDiff::Type
- Defined in:
- lib/api_diff/type.rb
Instance Attribute Summary collapse
-
#fully_qualified_name ⇒ Object
readonly
Returns the value of attribute fully_qualified_name.
-
#functions ⇒ Object
Returns the value of attribute functions.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parents ⇒ Object
Returns the value of attribute parents.
-
#properties ⇒ Object
Returns the value of attribute properties.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #declaration(fully_qualified_name: false) ⇒ Object
- #has_parents? ⇒ Boolean
-
#initialize(name, fully_qualified_name) ⇒ Type
constructor
A new instance of Type.
- #package ⇒ Object
- #sections ⇒ Object
- #to_s(fully_qualified_name: true) ⇒ Object
Constructor Details
#initialize(name, fully_qualified_name) ⇒ Type
Returns a new instance of Type.
10 11 12 13 14 15 16 |
# File 'lib/api_diff/type.rb', line 10 def initialize(name, fully_qualified_name) @name = name @fully_qualified_name = fully_qualified_name @parents = [] @functions = [] @properties = [] end |
Instance Attribute Details
#fully_qualified_name ⇒ Object (readonly)
Returns the value of attribute fully_qualified_name.
7 8 9 |
# File 'lib/api_diff/type.rb', line 7 def fully_qualified_name @fully_qualified_name end |
#functions ⇒ Object
Returns the value of attribute functions.
8 9 10 |
# File 'lib/api_diff/type.rb', line 8 def functions @functions end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/api_diff/type.rb', line 7 def name @name end |
#parents ⇒ Object
Returns the value of attribute parents.
8 9 10 |
# File 'lib/api_diff/type.rb', line 8 def parents @parents end |
#properties ⇒ Object
Returns the value of attribute properties.
8 9 10 |
# File 'lib/api_diff/type.rb', line 8 def properties @properties end |
Class Method Details
.type_name ⇒ Object
3 4 5 |
# File 'lib/api_diff/type.rb', line 3 def self.type_name name.split('::').last.downcase end |
Instance Method Details
#<=>(other) ⇒ Object
40 41 42 |
# File 'lib/api_diff/type.rb', line 40 def <=>(other) name <=> other.name end |
#declaration(fully_qualified_name: false) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/api_diff/type.rb', line 22 def declaration(fully_qualified_name: false) name = fully_qualified_name ? self.fully_qualified_name : self.name result = "#{self.class.type_name} #{name}" result += " : #{parents.join(", ")}" if has_parents? result end |
#has_parents? ⇒ Boolean
29 30 31 |
# File 'lib/api_diff/type.rb', line 29 def has_parents? not @parents.empty? end |
#package ⇒ Object
18 19 20 |
# File 'lib/api_diff/type.rb', line 18 def package fully_qualified_name.split(".")[0..-2].join(".") end |
#sections ⇒ Object
33 34 35 36 37 38 |
# File 'lib/api_diff/type.rb', line 33 def sections [ properties.sort, functions.sort ] end |
#to_s(fully_qualified_name: true) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/api_diff/type.rb', line 44 def to_s(fully_qualified_name: true) body = sections.map { |s| s.empty? ? nil : s }.compact # remove empty sections body.map! { |s| s.map { |entry| " #{entry}" } } # convert every entry in every section into a string and indent it body.map! { |s| s.join("\n") } # join all entries into a long string [ "#{declaration(fully_qualified_name: fully_qualified_name)} {", body.join("\n\n"), "}" ].join("\n") end |