Class: BrocadeVRouter::PathBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/brocade_vrouter/path_builder.rb

Constant Summary collapse

SEPARATOR =
'/'.freeze
SNAKE_TRANSFORM =
['_'.freeze, '-'.freeze].freeze
WHTSP_TRANSFORM =
[' '.freeze, SEPARATOR].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context = nil, base_path = nil, &blk) ⇒ PathBuilder

Returns a new instance of PathBuilder.



9
10
11
12
13
14
15
16
# File 'lib/brocade_vrouter/path_builder.rb', line 9

def initialize(context = nil, base_path = nil, &blk)
  @base_path, @paths, @context = base_path, [], context

  if block_given?
    @context ||= eval 'self', blk.binding
    instance_eval(&blk)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &blk) ⇒ Object (private)



40
41
42
43
44
# File 'lib/brocade_vrouter/path_builder.rb', line 40

def method_missing(*args, &blk)
  return @context.send(*args) if @context.respond_to?(args.first, true)
  @paths << generate_paths!(*args, &blk)
  @paths.last
end

Instance Attribute Details

#base_pathObject (readonly)

Returns the value of attribute base_path.



7
8
9
# File 'lib/brocade_vrouter/path_builder.rb', line 7

def base_path
  @base_path
end

Instance Method Details

#to_aObject



18
19
20
21
# File 'lib/brocade_vrouter/path_builder.rb', line 18

def to_a
  return @paths.flatten if !base_path || base_path.empty?
  @paths.flatten.map { |p| [base_path, p].join(SEPARATOR) }
end