Module: Iord::ResourceUrl

Extended by:
ActiveSupport::Concern
Included in:
Controller
Defined in:
lib/iord/resource_url.rb

Instance Method Summary collapse

Instance Method Details

#collection_url(options = {}) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/iord/resource_url.rb', line 49

def collection_url(options = {})
  if options.present?
    if options == true
      options = collection_url_defaults
    else
      options = collection_url_defaults.merge(options)
    end
    return self.public_send collection_url_method, options
  else
    @collection_url ||= self.public_send collection_url_method
  end
end

#collection_url_defaultsObject



45
46
47
# File 'lib/iord/resource_url.rb', line 45

def collection_url_defaults
  @collection_url_defaults ||= Hash.new
end

#collection_url_methodObject



27
28
29
# File 'lib/iord/resource_url.rb', line 27

def collection_url_method
  @collection_url_method ||= (action_path.pluralize + '_url').to_sym
end

#edit_resource_url(resource = nil) ⇒ Object



78
79
80
81
82
# File 'lib/iord/resource_url.rb', line 78

def edit_resource_url(resource = nil)
  resource ||= @resource
  resource = nil unless has_collection?
  self.public_send(edit_resource_url_method, resource)
end

#edit_resource_url?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/iord/resource_url.rb', line 75

def edit_resource_url?
  self.respond_to?(edit_resource_url_method)
end

#edit_resource_url_methodObject



72
73
74
# File 'lib/iord/resource_url.rb', line 72

def edit_resource_url_method
  @edit_resource_url_method ||= "edit_#{resource_url_method}".to_sym
end

#form_resource_urlObject



31
32
33
34
35
36
37
# File 'lib/iord/resource_url.rb', line 31

def form_resource_url
  if @resource.persisted? or not has_collection?
    resource_url
  else
    collection_url
  end
end

#has_collection?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/iord/resource_url.rb', line 19

def has_collection?
  @has_collection ||= self.respond_to? collection_url_method
end

#new_resource_urlObject



68
69
70
# File 'lib/iord/resource_url.rb', line 68

def new_resource_url
  @new_resource_url ||= self.public_send(new_resource_url_method)
end

#new_resource_url?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/iord/resource_url.rb', line 65

def new_resource_url?
  self.respond_to?(new_resource_url_method)
end

#new_resource_url_methodObject



62
63
64
# File 'lib/iord/resource_url.rb', line 62

def new_resource_url_method
  @new_resource_url_method ||= "new_#{resource_url_method}".to_sym
end

#resource_url(resource = nil) ⇒ Object



39
40
41
42
43
# File 'lib/iord/resource_url.rb', line 39

def resource_url(resource = nil)
  resource ||= @resource
  resource = nil unless has_collection?
  self.public_send resource_url_method.to_sym, resource
end

#resource_url_methodObject



23
24
25
# File 'lib/iord/resource_url.rb', line 23

def resource_url_method
  @resource_url_method ||= action_path.singularize + '_url'
end