Class: CodeNode::DSL::GraphDefiner
- Inherits:
-
Object
- Object
- CodeNode::DSL::GraphDefiner
- Defined in:
- lib/code_node/dsl/graph_definer.rb
Overview
Specify rules for generating the graph
Instance Method Summary collapse
-
#ignore(name = nil) {|node| ... } ⇒ nil
Specify an ignore rule for the graph.
-
#initialize(graph) ⇒ GraphDefiner
constructor
A new instance of GraphDefiner.
-
#style(name = nil, style = {}) {|node| ... } ⇒ nil
Specify a rule for styling nodes.
Constructor Details
#initialize(graph) ⇒ GraphDefiner
Returns a new instance of GraphDefiner.
11 12 13 |
# File 'lib/code_node/dsl/graph_definer.rb', line 11 def initialize(graph) @graph = graph end |
Instance Method Details
#ignore(name = nil) {|node| ... } ⇒ nil
Specify an ignore rule for the graph. Nodes matching the ignore rule will not be included in the graph. Ignore rules can be given in one of three ways,
-
String
provide a fully qualified path which will have to match IR::Node::QueryMethods#path exactly -
Regexp
provide a pattern that will be tested against the IR::Node::QueryMethods#path -
Proc
provide a block. If the block returnstrue
the node will be ignored
40 41 42 43 44 45 46 47 |
# File 'lib/code_node/dsl/graph_definer.rb', line 40 def ignore(name=nil, &block) if (name.nil? && block.nil?) || (name && block) raise ArgumentError.new('Provide either a name or a block') end matcher = IR::NodeMatcher.new name || block @graph.instance_eval {@exclude_matchers << matcher} nil end |
#style(name = nil, style = {}) {|node| ... } ⇒ nil
Specify a rule for styling nodes. Nodes matching the given rule will have the provided style attributes applied. Rules can be given in one of three ways,
-
String
provide a fully qualified path which will have to match IR::Node::QueryMethods#path exactly -
Regexp
provide a pattern that will be tested against the IR::Node::QueryMethods#path -
Proc
provide a block
75 76 77 78 79 80 81 82 83 |
# File 'lib/code_node/dsl/graph_definer.rb', line 75 def style(name=nil, style={}, &block) style, name = name, nil if name.is_a?(Hash) if (name.nil? && block.nil?) || (name && block) raise ArgumentError.new('Provide either a name or a block') end matcher = IR::NodeMatcher.new name || block @graph.instance_eval {@style_matchers << [matcher, style]} nil end |