Class: AdminIt::SingleContext
- Inherits:
-
Context
- Object
- Context
- AdminIt::SingleContext
show all
- Defined in:
- lib/admin_it/context/single_context.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#entity ⇒ Object
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
|
.sections ⇒ Object
88
89
90
|
# File 'lib/admin_it/context/single_context.rb', line 88
def self.sections
(@sections ||= {}).values
end
|
.single? ⇒ 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
|
#section ⇒ Object
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
@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
|
#values ⇒ Object
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
|