Class: Setting::Section
- Inherits:
-
Object
- Object
- Setting::Section
- Defined in:
- app/models/setting.rb
Constant Summary collapse
- @@all =
[]
- @@by_tab_and_label =
{}
- @@default =
:general
Instance Attribute Summary collapse
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#tab ⇒ Object
readonly
Returns the value of attribute tab.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(label, options = {}) ⇒ Section
constructor
A new instance of Section.
- #localized ⇒ Object
- #settings ⇒ Object
Constructor Details
#initialize(label, options = {}) ⇒ Section
Returns a new instance of Section.
254 255 256 257 258 259 |
# File 'app/models/setting.rb', line 254 def initialize(label, = {}) @label = label.to_sym @label_override = [:label] @order = [:order] || 1 @tab = ([:tab] || Setting::Tab.default).to_sym end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
249 250 251 |
# File 'app/models/setting.rb', line 249 def label @label end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
249 250 251 |
# File 'app/models/setting.rb', line 249 def order @order end |
#tab ⇒ Object (readonly)
Returns the value of attribute tab.
249 250 251 |
# File 'app/models/setting.rb', line 249 def tab @tab end |
Class Method Details
.all ⇒ Object
278 279 280 |
# File 'app/models/setting.rb', line 278 def all @@all end |
.by_tab_and_label ⇒ Object
302 303 304 |
# File 'app/models/setting.rb', line 302 def by_tab_and_label @@by_tab_and_label end |
.default ⇒ Object
282 283 284 |
# File 'app/models/setting.rb', line 282 def default @@default end |
.define(label, options = {}) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'app/models/setting.rb', line 286 def define(label, = {}) section = Setting::Section.new label, @@all << section @@by_tab_and_label[section.tab] ||= {} @@by_tab_and_label[section.tab][label.to_sym] = section begin @@default = label.to_sym Setting::Tab.with_default_tab section.tab do yield if block_given? end ensure @@default = :general end end |
Instance Method Details
#<=>(other) ⇒ Object
271 272 273 274 275 |
# File 'app/models/setting.rb', line 271 def <=>(other) result = order <=> other.order result = label <=> other.label if result == 0 result end |
#localized ⇒ Object
261 262 263 264 265 |
# File 'app/models/setting.rb', line 261 def localized return @label_override.call if @label_override.respond_to? :call return @label_override if @label_override I18n.t @label, :scope => "settings.show.sections.#{Setting::Tab[@tab].label}" end |
#settings ⇒ Object
267 268 269 |
# File 'app/models/setting.rb', line 267 def settings Setting::Meta.by_tab_section_and_label[tab][label].values.sort.map &:label end |