Class: DepsGrapher::Configuration

Inherits:
Object
  • Object
show all
Includes:
PluginDSL
Defined in:
lib/deps_grapher/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PluginDSL

#with_plugin

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



25
26
27
28
29
30
31
32
33
# File 'lib/deps_grapher/configuration.rb', line 25

def initialize
  self.logger = Logger.new($stderr).tap do
    _1.formatter = ->(_, _, _, msg) { "#{msg}\n" }
  end

  self.visualizer = Visualizer::Registry.default_visualizer

  @layers = {}
end

Instance Attribute Details

#layersObject

Returns the value of attribute layers.



23
24
25
# File 'lib/deps_grapher/configuration.rb', line 23

def layers
  @layers
end

Instance Method Details

#ast_processor_policy(&block) ⇒ Object



59
60
61
# File 'lib/deps_grapher/configuration.rb', line 59

def ast_processor_policy(&block)
  AstProcessorPolicy.new context, &block
end

#available_visualizersObject



35
36
37
# File 'lib/deps_grapher/configuration.rb', line 35

def available_visualizers
  Visualizer::Registry.available_visualizers
end

#contextObject



94
95
96
# File 'lib/deps_grapher/configuration.rb', line 94

def context
  @context ||= Context.new self
end

#inputObject



49
50
51
# File 'lib/deps_grapher/configuration.rb', line 49

def input
  @input ||= Input.new(self)
end

#layer(&block) ⇒ Object



53
54
55
56
57
# File 'lib/deps_grapher/configuration.rb', line 53

def layer(&block)
  Layer.new(&block).tap do |layer|
    @layers[layer.name] = layer
  end
end

#load!(file) ⇒ Object

Raises:

  • (ArgumentError)


69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/deps_grapher/configuration.rb', line 69

def load!(file)
  return unless file

  file = File.expand_path file
  raise ArgumentError, "no such file: #{file}" unless File.exist?(file)

  self.path = file

  content = File.read file

  self.cache_key = Digest::MD5.hexdigest content

  DSL.new(self).instance_eval content, file

  return unless dump

  at_exit do
    warn ""
    warn "=============================="
    warn " Configuration"
    warn "=============================="
    puts content
  end
end

#load_plugin!Object



39
40
41
# File 'lib/deps_grapher/configuration.rb', line 39

def load_plugin!
  PluginLoader.load! plugin_dir
end

#merge!(options) ⇒ Object



43
44
45
46
47
# File 'lib/deps_grapher/configuration.rb', line 43

def merge!(options)
  options.each do |key, value|
    send "#{key}=", value if respond_to?("#{key}=") && !value.nil?
  end
end

#plugin_dir(dir = nil) ⇒ Object



63
64
65
66
67
# File 'lib/deps_grapher/configuration.rb', line 63

def plugin_dir(dir = nil)
  return @plugin_dir unless dir

  @plugin_dir = dir
end