Class: Setting::Section

Inherits:
Object
  • Object
show all
Defined in:
app/models/setting.rb

Constant Summary collapse

@@all =
[]
@@by_tab_and_label =
{}
@@default =
:general

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(label, options = {}) ⇒ Section

Returns a new instance of Section.



266
267
268
269
270
271
# File 'app/models/setting.rb', line 266

def initialize(label, options = {})
  @label = label.to_sym
  @label_override = options[:label]
  @order = options[:order] || 1
  @tab = (options[:tab] || Setting::Tab.default).to_sym
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



261
262
263
# File 'app/models/setting.rb', line 261

def label
  @label
end

#orderObject (readonly)

Returns the value of attribute order.



261
262
263
# File 'app/models/setting.rb', line 261

def order
  @order
end

#tabObject (readonly)

Returns the value of attribute tab.



261
262
263
# File 'app/models/setting.rb', line 261

def tab
  @tab
end

Class Method Details

.allObject



290
291
292
# File 'app/models/setting.rb', line 290

def all
  @@all
end

.by_tab_and_labelObject



314
315
316
# File 'app/models/setting.rb', line 314

def by_tab_and_label
  @@by_tab_and_label
end

.defaultObject



294
295
296
# File 'app/models/setting.rb', line 294

def default
  @@default
end

.define(label, options = {}) ⇒ Object



298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'app/models/setting.rb', line 298

def define(label, options = {})
  section = Setting::Section.new label, options
  @@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



283
284
285
286
287
# File 'app/models/setting.rb', line 283

def <=>(other)
  result = order <=> other.order
  result = label <=> other.label if result == 0
  result
end

#localizedObject



273
274
275
276
277
# File 'app/models/setting.rb', line 273

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

#settingsObject



279
280
281
# File 'app/models/setting.rb', line 279

def settings
  Setting::Meta.by_tab_section_and_label[tab][label].values.sort.map &:label
end