Class: Usher::Util::Generators::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/usher/util/generate.rb

Direct Known Subclasses

URL

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#usherObject

Returns the value of attribute usher.



7
8
9
# File 'lib/usher/util/generate.rb', line 7

def usher
  @usher
end

Instance Method Details

#generate(name, params) ⇒ Object



9
10
11
# File 'lib/usher/util/generate.rb', line 9

def generate(name, params)
  generate_path_for_base_params(@usher.named_routes[name].find_matching_path(params), params)
end

#generate_path_for_base_params(path, params) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/usher/util/generate.rb', line 13

def generate_path_for_base_params(path, params)
  raise UnrecognizedException.new unless path
  case params
  when nil, Hash
    generate_path_for_base_params_with_hash(path, params)
  else
    generate_path_for_base_params_with_array(path, Array(params))
  end
end

#generate_path_for_base_params_with_array(path, params) ⇒ Object



27
28
29
# File 'lib/usher/util/generate.rb', line 27

def generate_path_for_base_params_with_array(path, params)
  path.generate(*params.slice!(0, path.dynamic_parts.size))
end

#generate_path_for_base_params_with_hash(path, params) ⇒ Object



23
24
25
# File 'lib/usher/util/generate.rb', line 23

def generate_path_for_base_params_with_hash(path, params)
  path.generate_from_hash(params)
end