Class: Traitee::ConflictSolver
- Inherits:
-
Object
- Object
- Traitee::ConflictSolver
- Defined in:
- lib/traitee/conflict_solver.rb
Instance Attribute Summary collapse
-
#conflicting_methods ⇒ Object
readonly
Returns the value of attribute conflicting_methods.
Instance Method Summary collapse
- #conflictless_method_map ⇒ Object
-
#initialize(methods) ⇒ ConflictSolver
constructor
A new instance of ConflictSolver.
- #method_in_conflict(method_name, method_a, method_b) ⇒ Object
-
#solve_possible_conflict(method_name, method_a, method_b) ⇒ Object
let it build, actual error will be raised later on all the usages of the method.
-
#this ⇒ Object
java reference :P, actual resolved module holder.
Constructor Details
#initialize(methods) ⇒ ConflictSolver
Returns a new instance of ConflictSolver.
8 9 10 11 |
# File 'lib/traitee/conflict_solver.rb', line 8 def initialize(methods) @methods = methods @conflicting_methods = {} end |
Instance Attribute Details
#conflicting_methods ⇒ Object (readonly)
Returns the value of attribute conflicting_methods.
6 7 8 |
# File 'lib/traitee/conflict_solver.rb', line 6 def conflicting_methods @conflicting_methods end |
Instance Method Details
#conflictless_method_map ⇒ Object
18 19 20 21 22 |
# File 'lib/traitee/conflict_solver.rb', line 18 def conflictless_method_map @methods.reduce({}) do |res, map| res.merge!(map) { |method_name, method_a, method_b| solve_possible_conflict(method_name, method_a, method_b) } end end |
#method_in_conflict(method_name, method_a, method_b) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/traitee/conflict_solver.rb', line 29 def method_in_conflict(method_name, method_a, method_b) conflict_solver = self @conflicting_methods[method_name] = [method_a, method_b] # define a method which raises an error - uncallable this.send(:define_method, method_name) do _method_a, _method_b = conflict_solver.conflicting_methods[method_name] fail MethodsInConflict.new "Modules are in conflict with method :#{method_name}" end this.instance_method(method_name) end |
#solve_possible_conflict(method_name, method_a, method_b) ⇒ Object
let it build, actual error will be raised later on all the usages of the method
25 26 27 |
# File 'lib/traitee/conflict_solver.rb', line 25 def solve_possible_conflict(method_name, method_a, method_b) method_a == method_b ? method_a : method_in_conflict(method_name, method_a, method_b) end |
#this ⇒ Object
java reference :P, actual resolved module holder
14 15 16 |
# File 'lib/traitee/conflict_solver.rb', line 14 def this @this ||= Module.new end |