Class: GRApiManager::RouteGroup

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

Overview


RouteGroup — provides nested route grouping with shared prefixes and options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server, prefix = '', options = {}) ⇒ RouteGroup

Returns a new instance of RouteGroup.



489
490
491
492
493
# File 'lib/gr_api_manager.rb', line 489

def initialize(server, prefix = '', options = {})
  @server  = server
  @prefix  = prefix.to_s
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



487
488
489
# File 'lib/gr_api_manager.rb', line 487

def options
  @options
end

#prefixObject (readonly)

Returns the value of attribute prefix.



487
488
489
# File 'lib/gr_api_manager.rb', line 487

def prefix
  @prefix
end

#serverObject (readonly)

Returns the value of attribute server.



487
488
489
# File 'lib/gr_api_manager.rb', line 487

def server
  @server
end

Instance Method Details

#group(sub_prefix = '', sub_options = {}, &block) ⇒ Object

Nested sub-grouping.



510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/gr_api_manager.rb', line 510

def group(sub_prefix = '', sub_options = {}, &block)
  combined_prefix = File.join('/', @prefix, sub_prefix.to_s).gsub(%r{/+}, '/')
  merged_options  = @options.merge(sub_options)

  if @options[:requires] && sub_options[:requires]
    merged_options[:requires] = merge_requires(@options[:requires], sub_options[:requires])
  end

  sub_group = RouteGroup.new(@server, combined_prefix, merged_options)
  block.call(sub_group) if block
  sub_group
end