Class: DepsGrapher::AstProcessorPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/deps_grapher/ast_processor_policy.rb

Instance Method Summary collapse

Constructor Details

#initialize(context, &block) ⇒ AstProcessorPolicy

Returns a new instance of AstProcessorPolicy.



5
6
7
8
# File 'lib/deps_grapher/ast_processor_policy.rb', line 5

def initialize(context, &block)
  @context = context
  DSL.new(self).instance_eval(&block)
end

Instance Method Details

#advanced_const_resolver(callable = nil, &block) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
# File 'lib/deps_grapher/ast_processor_policy.rb', line 38

def advanced_const_resolver(callable = nil, &block)
  raise ArgumentError, "You must provide a block or callable" unless block || callable
  raise ArgumentError, "The provided object must respond to #call" if callable && !callable.respond_to?(:call)

  @context.advanced_const_resolver = block || callable
end

#const(matcher, &block) ⇒ Object



10
11
12
# File 'lib/deps_grapher/ast_processor_policy.rb', line 10

def const(matcher, &block)
  event_processor matcher, :const_name, &block
end

#event_processor(matcher, prop, &block) ⇒ Object



34
35
36
# File 'lib/deps_grapher/ast_processor_policy.rb', line 34

def event_processor(matcher, prop, &block)
  @context.event_processors[matcher] = [prop, block]
end

#exclude_const(matcher) ⇒ Object



18
19
20
# File 'lib/deps_grapher/ast_processor_policy.rb', line 18

def exclude_const(matcher)
  const matcher, &:skip_processing!
end

#exclude_location(matcher) ⇒ Object



30
31
32
# File 'lib/deps_grapher/ast_processor_policy.rb', line 30

def exclude_location(matcher)
  location matcher, &:skip_processing!
end

#include_const(matcher) ⇒ Object



14
15
16
# File 'lib/deps_grapher/ast_processor_policy.rb', line 14

def include_const(matcher)
  const matcher, &:processing!
end

#include_location(matcher) ⇒ Object



26
27
28
# File 'lib/deps_grapher/ast_processor_policy.rb', line 26

def include_location(matcher)
  location matcher, &:processing!
end

#location(matcher, &block) ⇒ Object



22
23
24
# File 'lib/deps_grapher/ast_processor_policy.rb', line 22

def location(matcher, &block)
  event_processor matcher, :location, &block
end