Module: Shaf::UriHelperMethods

Included in:
UriHelper, UriHelper
Defined in:
lib/shaf/extensions/resource_uris.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.add_path_helpers(clazz, methods) ⇒ Object



51
52
53
# File 'lib/shaf/extensions/resource_uris.rb', line 51

def add_path_helpers(clazz, methods)
  path_helpers[clazz].concat Array(methods)
end

.eval_method(str) ⇒ Object



47
48
49
# File 'lib/shaf/extensions/resource_uris.rb', line 47

def eval_method(str)
  class_eval str
end

.path_helpersObject



60
61
62
# File 'lib/shaf/extensions/resource_uris.rb', line 60

def path_helpers
  @path_helpers ||= Hash.new { |hash, key| hash[key] = [] }
end

.path_helpers_for(clazz = nil) ⇒ Object



55
56
57
58
# File 'lib/shaf/extensions/resource_uris.rb', line 55

def path_helpers_for(clazz = nil)
  return path_helpers unless clazz
  path_helpers[clazz]
end

.register(name, &block) ⇒ Object



43
44
45
# File 'lib/shaf/extensions/resource_uris.rb', line 43

def register(name, &block)
  define_method(name, &block)
end

.remove_allObject

For cleaning up after tests



65
66
67
68
69
# File 'lib/shaf/extensions/resource_uris.rb', line 65

def remove_all
  helpers = instance_methods - [:path_helpers]
  remove_method(*helpers)
  @path_helpers = Hash.new { |hash, key| hash[key] = [] }
end

Instance Method Details

#path_helpersObject



72
73
74
75
# File 'lib/shaf/extensions/resource_uris.rb', line 72

def path_helpers
  clazz = is_a?(Class) ? self : self.class
  UriHelperMethods.path_helpers_for clazz
end