Class: ApiDiff::Type
- Inherits:
-
Object
show all
- Defined in:
- lib/api_diff/type.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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
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
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 body.map! { |s| s.map { |entry| " #{entry}" } } body.map! { |s| s.join("\n") } [
"#{declaration(fully_qualified_name: fully_qualified_name)} {",
body.join("\n\n"),
"}"
].join("\n")
end
|