Class: HttpRouter::Node::Arbitrary

Inherits:
HttpRouter::Node show all
Defined in:
lib/http_router/node/arbitrary.rb

Instance Attribute Summary collapse

Attributes inherited from HttpRouter::Node

#router

Instance Method Summary collapse

Methods inherited from HttpRouter::Node

#add_arbitrary, #add_destination, #add_free_match, #add_glob, #add_glob_regexp, #add_lookup, #add_match, #add_request, #add_spanning_match, #add_variable, #depth, #inspect, #inspect_label, #inspect_matchers_body

Constructor Details

#initialize(router, parent, sallow_partial, blk, param_names) ⇒ Arbitrary

Returns a new instance of Arbitrary.



6
7
8
9
# File 'lib/http_router/node/arbitrary.rb', line 6

def initialize(router, parent, sallow_partial, blk, param_names)
  @allow_partial, @blk, @param_names = allow_partial, blk, param_names
  super(router, parent)
end

Instance Attribute Details

#allow_partialObject (readonly)

Returns the value of attribute allow_partial.



4
5
6
# File 'lib/http_router/node/arbitrary.rb', line 4

def allow_partial
  @allow_partial
end

#blkObject (readonly)

Returns the value of attribute blk.



4
5
6
# File 'lib/http_router/node/arbitrary.rb', line 4

def blk
  @blk
end

#param_namesObject (readonly)

Returns the value of attribute param_names.



4
5
6
# File 'lib/http_router/node/arbitrary.rb', line 4

def param_names
  @param_names
end

Instance Method Details

#to_codeObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/http_router/node/arbitrary.rb', line 15

def to_code
  b, method_name = @blk, :"blk_#{root.next_counter}"
  inject_root_methods { define_method(method_name) { b } }
  "#{"if request.path_finished?" unless @allow_partial}
    request.continue = proc { |state|
      if state
        #{super}
      end
    }
    #{method_name}[request, #{@param_names.nil? || @param_names.empty? ? '{}' : "Hash[#{@param_names.inspect}.zip(request.params)]"}]
    request.continue = nil
  #{"end" unless @allow_partial}"
end

#usable?(other) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/http_router/node/arbitrary.rb', line 11

def usable?(other)
  other.class == self.class && other.allow_partial == allow_partial && other.blk == blk && other.param_names == param_names
end