Class: Aerogel::Routes::Namespace

Inherits:
Object
  • Object
show all
Defined in:
lib/aerogel/core/routes/namespace.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base, path, &block) ⇒ Namespace

Returns a new instance of Namespace.



5
6
7
8
9
# File 'lib/aerogel/core/routes/namespace.rb', line 5

def initialize( base, path, &block )
  @base = base
  @prefix_path = path
  instance_eval &block
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



11
12
13
# File 'lib/aerogel/core/routes/namespace.rb', line 11

def method_missing( method, *args, &block )
  @base.send method, *args, &block
end

Class Method Details

.prefix(*methods) ⇒ Object



28
29
30
31
32
# File 'lib/aerogel/core/routes/namespace.rb', line 28

def self.prefix( *methods )
  methods.each do |method|
    define_method(method) {|*args, &block| prefixed( method, *args, &block ) }
  end
end

Instance Method Details

#prefixed(method, *args, &block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/aerogel/core/routes/namespace.rb', line 15

def prefixed( method, *args, &block )
  options = Hash === args.last ? args.pop : {}
  routes = [*(args.pop || '*')]
  routes, args = routes+args, [] unless method == :route
  routes.map!{|r| @prefix_path+r }
  routes = [routes] if method == :route
  p_args = []
  p_args += args unless args.empty?
  p_args += routes # unless routes.empty?
  p_args += options unless options.empty?
  @base.send method, *p_args, &block
end