Class: ApiDiff::Api
- Inherits:
-
Object
- Object
- ApiDiff::Api
- Defined in:
- lib/api_diff/api.rb
Instance Attribute Summary collapse
-
#classes ⇒ Object
Returns the value of attribute classes.
-
#enums ⇒ Object
Returns the value of attribute enums.
-
#interfaces ⇒ Object
Returns the value of attribute interfaces.
-
#structs ⇒ Object
Returns the value of attribute structs.
Instance Method Summary collapse
- #class(named: nil, fully_qualified_name: nil) ⇒ Object
- #enum(named: nil, fully_qualified_name: nil) ⇒ Object
-
#initialize ⇒ Api
constructor
A new instance of Api.
- #interface(named: nil, fully_qualified_name: nil) ⇒ Object
- #struct(named: nil, fully_qualified_name: nil) ⇒ Object
- #to_s(fully_qualified_names: true, order: :global) ⇒ Object
Constructor Details
#initialize ⇒ Api
Returns a new instance of Api.
5 6 7 8 9 10 |
# File 'lib/api_diff/api.rb', line 5 def initialize @classes = [] @structs = [] @interfaces = [] @enums = [] end |
Instance Attribute Details
#classes ⇒ Object
Returns the value of attribute classes.
3 4 5 |
# File 'lib/api_diff/api.rb', line 3 def classes @classes end |
#enums ⇒ Object
Returns the value of attribute enums.
3 4 5 |
# File 'lib/api_diff/api.rb', line 3 def enums @enums end |
#interfaces ⇒ Object
Returns the value of attribute interfaces.
3 4 5 |
# File 'lib/api_diff/api.rb', line 3 def interfaces @interfaces end |
#structs ⇒ Object
Returns the value of attribute structs.
3 4 5 |
# File 'lib/api_diff/api.rb', line 3 def structs @structs end |
Instance Method Details
#class(named: nil, fully_qualified_name: nil) ⇒ Object
12 13 14 |
# File 'lib/api_diff/api.rb', line 12 def class(named: nil, fully_qualified_name: nil) classes.find { |c| c.name == named || c.fully_qualified_name == fully_qualified_name } end |
#enum(named: nil, fully_qualified_name: nil) ⇒ Object
24 25 26 |
# File 'lib/api_diff/api.rb', line 24 def enum(named: nil, fully_qualified_name: nil) enums.find { |e| e.name == named || e.fully_qualified_name == fully_qualified_name } end |
#interface(named: nil, fully_qualified_name: nil) ⇒ Object
20 21 22 |
# File 'lib/api_diff/api.rb', line 20 def interface(named: nil, fully_qualified_name: nil) interfaces.find { |i| i.name == named || i.fully_qualified_name == fully_qualified_name } end |
#struct(named: nil, fully_qualified_name: nil) ⇒ Object
16 17 18 |
# File 'lib/api_diff/api.rb', line 16 def struct(named: nil, fully_qualified_name: nil) structs.find { |s| s.name == named || s.fully_qualified_name == fully_qualified_name } end |
#to_s(fully_qualified_names: true, order: :global) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/api_diff/api.rb', line 28 def to_s(fully_qualified_names: true, order: :global) result = [] if order == "global" result << (enums + interfaces + classes).sort.map { |e| e.to_s(fully_qualified_name: fully_qualified_names) } elsif order == "fqn" types = enums + interfaces + classes type_order = { "enum" => 1, "interface" => 2, "class" => 3 } types.sort! do |t1, t2| [t1.package, type_order[t1.class.type_name], t1.name] <=> [t2.package, type_order[t2.class.type_name], t2.name] end result << types.map { |e| e.to_s(fully_qualified_name: fully_qualified_names) } else result << enums.sort.map { |e| e.to_s(fully_qualified_name: fully_qualified_names) } result << interfaces.sort.map { |i| i.to_s(fully_qualified_name: fully_qualified_names) } result << classes.sort.map { |c| c.to_s(fully_qualified_name: fully_qualified_names) } end result.flatten.join("\n\n") end |