class ActionCrud::Helpers::Route

Attributes

action[RW]
model[RW]
options[RW]
path[RW]
record[RW]
url[RW]

Public Class Methods

new(context, record = nil, action = nil, *options) click to toggle source
# File lib/action_crud/helpers/route.rb, line 6
def initialize(context, record = nil, action = nil, *options)
  @context = context
  @record  = record || @context.try(:current_record)
  @action  = action
  @options = Hash(options.first)
  @path    = route_uri true
  @url     = route_uri false
end

Public Instance Methods

namespace() click to toggle source
# File lib/action_crud/helpers/route.rb, line 27
def namespace
  if @context.respond_to? :controller
    @context.controller.try(:namespace)
  else
    @context.try(:namespace)
  end
end
namespaced_model() click to toggle source
# File lib/action_crud/helpers/route.rb, line 43
def namespaced_model
  if action == :new
    namespace.present? ? [:new, namespace, model] : [:new, model]
  else
    namespace.present? ? [namespace, model('plural')] : model('plural')
  end
end
namespaced_record() click to toggle source
# File lib/action_crud/helpers/route.rb, line 35
def namespaced_record
  if action == :edit
    namespace.present? ? [:edit, namespace, record] : [:edit, record]
  else
    namespace.present? ? [namespace, record] : [record]
  end
end
record?() click to toggle source
# File lib/action_crud/helpers/route.rb, line 19
def record?
  action.in? [:show, :edit, :delete, :destroy]
end
route_uri(only_path = false) click to toggle source
# File lib/action_crud/helpers/route.rb, line 51
def route_uri(only_path = false)
  args = record? ? namespaced_record : namespaced_model
  args = [args, options.merge(only_path: only_path)].flatten.reject(&:blank?)

  @context.url_for(args)
end
to_s(type = :path) click to toggle source
# File lib/action_crud/helpers/route.rb, line 15
def to_s(type = :path)
  instance_variable_get("@#{type}").to_s
end