Class: Orthoses::ActiveSupport::Concern
- Inherits:
-
Object
- Object
- Orthoses::ActiveSupport::Concern
- Defined in:
- lib/orthoses/active_support/concern.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(loader) ⇒ Concern
constructor
A new instance of Concern.
- #members_prototype_of(mod_name) ⇒ Object
Constructor Details
#initialize(loader) ⇒ Concern
Returns a new instance of Concern.
6 7 8 |
# File 'lib/orthoses/active_support/concern.rb', line 6 def initialize(loader) @loader = loader end |
Instance Method Details
#call ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/orthoses/active_support/concern.rb', line 10 def call lazy_tracer = Orthoses::CallTracer::Lazy.new store = lazy_tracer.trace('ActiveSupport::Concern#class_methods') do @loader.call end lazy_tracer.captures.each do |capture| receiver_name = Orthoses::Utils.module_name(capture.method.receiver) next unless receiver_name class_methods_name = "#{receiver_name}::ClassMethods" members = members_prototype_of(class_methods_name) writer = ::RBS::Writer.new(out: StringIO.new) members.each do |member| writer.write_member(member) end out = writer.out # NOTE: Should I remove the method that is accidentally added in prototype rb? store[class_methods_name].concat(out.string.each_line.to_a) end store end |
#members_prototype_of(mod_name) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/orthoses/active_support/concern.rb', line 36 def members_prototype_of(mod_name) mod = Object.const_get(mod_name) runtime = ::RBS::Prototype::Runtime.new(patterns: nil, env: nil, merge: false) type_name = TypeName(mod_name) [].tap do |members| runtime.generate_methods(mod, type_name, members) end end |