Class: RbsActivesupport::Include

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_activesupport/include.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options) #: void
  @context = context
  @module_path = module_path
  @options = options
end

Instance Attribute Details

#contextObject (readonly)

: RBS::Namespace



7
8
9
# File 'lib/rbs_activesupport/include.rb', line 7

def context
  @context
end

#module_pathObject (readonly)

: RBS::Namespace



8
9
10
# File 'lib/rbs_activesupport/include.rb', line 8

def module_path
  @module_path
end

#optionsObject (readonly)

: Hash[Symbol, untyped]



9
10
11
# File 'lib/rbs_activesupport/include.rb', line 9

def options
  @options
end

Instance Method Details

#classmethods?Boolean

: boolish

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


54
55
56
# File 'lib/rbs_activesupport/include.rb', line 54

def explicit? #: bool
  !implicit?
end

#implicit?Boolean

: bool

Returns:

  • (Boolean)


58
59
60
# File 'lib/rbs_activesupport/include.rb', line 58

def implicit? #: bool
  options.fetch(:implicit, false)
end

#method_calls_in_included_blockObject

: 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

#moduleObject



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_nameObject



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_includesObject

: 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

#private?Boolean

: bool

Returns:

  • (Boolean)


82
83
84
# File 'lib/rbs_activesupport/include.rb', line 82

def private? #: bool
  options.fetch(:private, false)
end

#public?Boolean

: bool

Returns:

  • (Boolean)


78
79
80
# File 'lib/rbs_activesupport/include.rb', line 78

def public? #: bool
  !private?
end