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.



105
106
107
# File 'lib/admin_it/context/single_context.rb', line 105

def entity
  @entity
end

Class Method Details

.path(entity) ⇒ Object



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

def self.path(entity)
  AdminIt::Engine.routes.url_helpers.send(
    "#{resource.name}_path",
    entity
  )
end

.sectionsObject



88
89
90
# File 'lib/admin_it/context/single_context.rb', line 88

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

.single?Boolean

Returns:

  • (Boolean)


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

def self.single?
  true
end

Instance Method Details

#path(_entity: nil) ⇒ Object



120
121
122
123
# File 'lib/admin_it/context/single_context.rb', line 120

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

#sectionObject



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

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

#section=(value) ⇒ Object



129
130
131
132
133
134
135
136
137
# File 'lib/admin_it/context/single_context.rb', line 129

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



139
140
141
142
# File 'lib/admin_it/context/single_context.rb', line 139

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

#valuesObject



115
116
117
118
# File 'lib/admin_it/context/single_context.rb', line 115

def values
  return {} if @entity.nil?
  Hash[fields(scope: :readable).map { |f| [f.name, f.read(@entity)] }]
end