Class: AdminIt::SingleContext
- Inherits:
-
Context
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
Returns the value of attribute entity.
95
96
97
|
# File 'lib/admin_it/context/single_context.rb', line 95
def entity
@entity
end
|
Class Method Details
.path(entity) ⇒ Object
87
88
89
90
91
92
|
# File 'lib/admin_it/context/single_context.rb', line 87
def self.path(entity)
AdminIt::Engine.routes.url_helpers.send(
"#{resource.name}_path",
entity
)
end
|
79
80
81
|
# File 'lib/admin_it/context/single_context.rb', line 79
def self.sections
(@sections ||= {}).values
end
|
.single? ⇒ Boolean
83
84
85
|
# File 'lib/admin_it/context/single_context.rb', line 83
def self.single?
true
end
|
Instance Method Details
#path(_entity: nil) ⇒ Object
110
111
112
113
|
# File 'lib/admin_it/context/single_context.rb', line 110
def path(_entity: nil)
_entity ||= entity
self.class.path(_entity)
end
|
115
116
117
|
# File 'lib/admin_it/context/single_context.rb', line 115
def section
@section ||= sections.empty? ? :none : :general
end
|
#section=(value) ⇒ Object
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/admin_it/context/single_context.rb', line 119
def section=(value)
value = value.downcase.to_sym if value.is_a?(String)
return unless value.is_a?(Symbol)
if sections.empty?
return if section != :none
else
return unless sections.map(&:name).include?(value)
end
@section = section
end
|
105
106
107
108
|
# File 'lib/admin_it/context/single_context.rb', line 105
def values
return {} if @entity.nil?
Hash[fields(scope: :readable).map { |f| [f.name, f.read(@entity)] }]
end
|