Class: AdminIt::SingleContext

Inherits:
Context
  • Object
show all
Defined in:
lib/admin_it/context/single_context.rb

Direct Known Subclasses

SavableSingleContext, ShowContext

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from AdminIt::Context

Instance Attribute Details

#entityObject

Returns the value of attribute entity.



110
111
112
# File 'lib/admin_it/context/single_context.rb', line 110

def entity
  @entity
end

Class Method Details

.path(entity) ⇒ Object



101
102
103
104
105
106
# 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

.sectionsObject

def self.before_configure() @show_resource_link = true end



93
94
95
# File 'lib/admin_it/context/single_context.rb', line 93

def self.sections
  (@sections ||= {}).values
end

.single?Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/admin_it/context/single_context.rb', line 97

def self.single?
  true
end

Instance Method Details

#path(_entity: nil) ⇒ Object



125
126
127
128
# File 'lib/admin_it/context/single_context.rb', line 125

def path(_entity: nil)
  _entity ||= entity
  self.class.path(_entity)
end

#sectionObject



130
131
132
# File 'lib/admin_it/context/single_context.rb', line 130

def section
  @section ||= sections.empty? ? :none : :general
end

#section=(value) ⇒ Object



134
135
136
137
138
139
140
141
142
# 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) ⇒ Object



144
145
146
147
# File 'lib/admin_it/context/single_context.rb', line 144

def url_params(**params)
  params[:section] = section unless params.key?(:section)
  super(**params)
end

#valuesObject



120
121
122
123
# 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