module SmarterListing::Helper

Public Instance Methods

_resource_params() click to toggle source
# File lib/smarter_listing/helper.rb, line 26
def _resource_params
  method = "#{resource_sym}_params".to_sym
  return send method if respond_to? method
  resource_params
end
action_copy(object, path) click to toggle source
# File lib/smarter_listing/helper.rb, line 81
def action_copy(object, path)
  {
      name: :copy,
      custom_url: path,
      custom_icon: SmartListing.config.classes(:icon_copy),
      custom_title: 'Copy'
  }
end
action_destroy(object, path) click to toggle source
# File lib/smarter_listing/helper.rb, line 94
def action_destroy(object, path)
  {name: :destroy, url: path}
end
action_edit(object, path) click to toggle source
# File lib/smarter_listing/helper.rb, line 90
def action_edit(object, path)
  {name: :edit, url: path}
end
collection_ivar() click to toggle source
# File lib/smarter_listing/helper.rb, line 8
def collection_ivar
  "@#{collection_sym}"
end
collection_sym() click to toggle source
# File lib/smarter_listing/helper.rb, line 4
def collection_sym
  @collection_sym ||= model.to_s.underscore.sub('/','_').pluralize.to_sym
end
current_engine() click to toggle source
# File lib/smarter_listing/helper.rb, line 36
def current_engine
  object = instance_variables.include?(:@_controller) ? @_controller : self
  object.class.module_parent == Object ? '' : object.class.module_parent.to_s.underscore
end
model() click to toggle source
# File lib/smarter_listing/helper.rb, line 41
def model
  controller = instance_variables.include?(:@_controller) ? @_controller : self
  @model ||= begin
               # First priority is the namespaced model, e.g. User::Group
    resource_class ||= begin
      namespaced_class = controller.class.name.sub(/Controller/, '').singularize
      namespaced_class.constantize
    rescue NameError
      nil
    end

    # Second priority is the top namespace model, e.g. EngineName::Article for EngineName::Admin::ArticlesController
    resource_class ||= begin
      namespaced_classes = controller.class.name.sub(/Controller/, '').split('::')
      namespaced_class = [namespaced_classes.first, namespaced_classes.last].join('::').singularize
      namespaced_class.constantize
    rescue NameError
      nil
    end

    # Third priority the camelcased c, i.e. UserGroup
    resource_class ||= begin
      camelcased_class = controller.class.name.sub(/Controller/, '').gsub('::', '').singularize
      camelcased_class.constantize
    rescue NameError
      nil
    end

    # Otherwise use the Group class, or fail
    resource_class ||= begin
      class_name = controller.controller_name.classify
      class_name.constantize
    rescue NameError => e
      raise unless e.message.include?(class_name)
      nil
    end
    resource_class
  end
end
resource_ivar() click to toggle source
# File lib/smarter_listing/helper.rb, line 22
def resource_ivar
  "@#{resource_sym}"
end
resource_sym() click to toggle source
# File lib/smarter_listing/helper.rb, line 12
def resource_sym
  @resource_sym ||= model.to_s.underscore.sub('/','_').to_sym
end
resource_view_path() click to toggle source
# File lib/smarter_listing/helper.rb, line 16
def resource_view_path
  path = model.name.tableize
  path = "#{current_engine}/#{path}" unless path.start_with?("#{current_engine}/")
  path
end
table_name() click to toggle source
# File lib/smarter_listing/helper.rb, line 32
def table_name
  model.name.demodulize.tableize.to_sym
end