Class: RbsActivesupport::Include
- Inherits:
-
Object
- Object
- RbsActivesupport::Include
- Defined in:
- lib/rbs_activesupport/include.rb,
sig/rbs_activesupport/include.rbs
Instance Attribute Summary collapse
-
#context ⇒ RBS::Namespace
readonly
: RBS::Namespace.
-
#module_path ⇒ RBS::Namespace
readonly
: RBS::Namespace.
-
#options ⇒ Hash[Symbol, untyped]
readonly
: Hash[Symbol, untyped].
Instance Method Summary collapse
-
#classmethods? ⇒ Boolean
: boolish.
-
#concern? ⇒ Boolean
: boolish.
-
#explicit? ⇒ Boolean
: bool.
-
#implicit? ⇒ Boolean
: bool.
-
#initialize(context, module_path, options) ⇒ Include
constructor
A new instance of Include.
-
#method_calls_in_included_block ⇒ Array[Parser::MethodCall]
: Array.
- #module ⇒ Module?
- #module_name ⇒ RBS::Namespace?
-
#nested_includes ⇒ Array[Parser::MethodCall]
: Array.
- #parser ⇒ Parser?
-
#private? ⇒ Boolean
: bool.
-
#public? ⇒ Boolean
: bool.
Constructor Details
#initialize(context, module_path, options) ⇒ Include
Returns a new instance of Include.
14 15 16 17 18 |
# File 'lib/rbs_activesupport/include.rb', line 14 def initialize(context, module_path, ) #: void @context = context @module_path = module_path = end |
Instance Attribute Details
#context ⇒ RBS::Namespace (readonly)
: RBS::Namespace
7 8 9 |
# File 'lib/rbs_activesupport/include.rb', line 7 def context @context end |
#module_path ⇒ RBS::Namespace (readonly)
: RBS::Namespace
8 9 10 |
# File 'lib/rbs_activesupport/include.rb', line 8 def module_path @module_path end |
#options ⇒ Hash[Symbol, untyped] (readonly)
: Hash[Symbol, untyped]
9 10 11 |
# File 'lib/rbs_activesupport/include.rb', line 9 def end |
Instance Method Details
#classmethods? ⇒ Boolean
: boolish
48 49 50 51 52 |
# File 'lib/rbs_activesupport/include.rb', line 48 def classmethods? #: boolish return false unless self.module self.module&.const_defined?(:ClassMethods) end |
#concern? ⇒ Boolean
: boolish
44 45 46 |
# File 'lib/rbs_activesupport/include.rb', line 44 def concern? #: boolish self.module&.singleton_class&.include?(ActiveSupport::Concern) end |
#explicit? ⇒ Boolean
: bool
54 55 56 |
# File 'lib/rbs_activesupport/include.rb', line 54 def explicit? #: bool !implicit? end |
#implicit? ⇒ Boolean
: bool
58 59 60 |
# File 'lib/rbs_activesupport/include.rb', line 58 def implicit? #: bool .fetch(:implicit, false) end |
#method_calls_in_included_block ⇒ Array[Parser::MethodCall]
: Array
70 71 72 73 74 75 76 |
# File 'lib/rbs_activesupport/include.rb', line 70 def method_calls_in_included_block #: Array[Parser::MethodCall] return [] unless module_name return [] unless parser method_calls = parser.method_calls[module_name] || [] method_calls.select(&:included) end |
#module ⇒ Module?
35 36 37 38 39 40 41 42 |
# File 'lib/rbs_activesupport/include.rb', line 35 def module #: Module? return unless module_name modname = module_name.to_s.delete_suffix("::") return unless Object.const_defined?(modname) Object.const_get(modname) end |
#module_name ⇒ RBS::Namespace?
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rbs_activesupport/include.rb', line 21 def module_name #: RBS::Namespace? namespace = @context loop do modname = namespace + module_path return modname if Object.const_defined?(modname.to_s.delete_suffix("::")) break if namespace.empty? namespace = namespace.parent end end |
#nested_includes ⇒ Array[Parser::MethodCall]
: Array
62 63 64 65 66 67 68 |
# File 'lib/rbs_activesupport/include.rb', line 62 def nested_includes #: Array[Parser::MethodCall] return [] unless module_name return [] unless parser method_calls = parser.method_calls[module_name] || [] method_calls.select { |call| call.name == :include && !call.included } end |
#parser ⇒ Parser?
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rbs_activesupport/include.rb', line 91 def parser #: Parser? return nil unless module_name @parser ||= begin path, = Object.const_source_location(module_name.to_s.delete_suffix("::")) #: String? if path && File.exist?(path) Parser.new(parse_included_block: true).tap do |parser| parser.parse(File.read(path)) end end end end |
#private? ⇒ Boolean
: bool
82 83 84 |
# File 'lib/rbs_activesupport/include.rb', line 82 def private? #: bool .fetch(:private, false) end |
#public? ⇒ Boolean
: bool
78 79 80 |
# File 'lib/rbs_activesupport/include.rb', line 78 def public? #: bool !private? end |