class AdminIt::SingleContext

Attributes

entity[RW]

Public Class Methods

path(entity) click to toggle source
# File lib/admin_it/context/single_context.rb, line 101
def self.path(entity)
  AdminIt::Engine.routes.url_helpers.send(
    "#{resource.name}_path",
    entity
  )
end
sections() click to toggle source

def self.before_configure()

@show_resource_link = true

end

# File lib/admin_it/context/single_context.rb, line 93
def self.sections
  (@sections ||= {}).values
end
single?() click to toggle source
# File lib/admin_it/context/single_context.rb, line 97
def self.single?
  true
end

Public Instance Methods

path(_entity: nil) click to toggle source
# File lib/admin_it/context/single_context.rb, line 125
def path(_entity: nil)
  _entity ||= entity
  self.class.path(_entity)
end
section() click to toggle source
# File lib/admin_it/context/single_context.rb, line 130
def section
  @section ||= sections.empty? ? :none : :general
end
section=(value) click to toggle source
# File lib/admin_it/context/single_context.rb, line 134
    def section=(value)
      value = value.ensure_symbol(downcase: true) || return
#      if s.empty?
#        return if section != :none
#      else
#        return unless s.map(&:name).include?(value.to_s)
#      end
      @section = value
    end
url_params(**params) click to toggle source
Calls superclass method AdminIt::Context#url_params
# File lib/admin_it/context/single_context.rb, line 144
def url_params(**params)
  params[:section] = section unless params.key?(:section)
  super(**params)
end
values() click to toggle source
# File lib/admin_it/context/single_context.rb, line 120
def values
  return {} if @entity.nil?
  Hash[fields(scope: :readable).map { |f| [f.name, f.read(@entity)] }]
end

Protected Instance Methods

load_context() click to toggle source
# File lib/admin_it/context/single_context.rb, line 151
def load_context
  self.entity =
    if entity_getter.nil?
      getter = "#{resource.name}_#{name}_entity".to_sym
      if controller.respond_to?(getter)
        controller.send(getter)
      else
        getter = "#{name}_entity"
        if controller.respond_to?(getter)
          controller.send(getter, entity_class)
        else
          load_entity
        end
      end
    else
      entity_getter.call(controller.params)
    end
end
load_entity(identity: nil) click to toggle source
# File lib/admin_it/context/single_context.rb, line 170
def load_entity(identity: nil)
  []
end