Class: Setting::Tab
- Inherits:
-
Object
- Object
- Setting::Tab
- Defined in:
- app/models/setting.rb
Constant Summary collapse
- @@all =
[]
- @@by_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.
Class Method Summary collapse
- .[](label) ⇒ Object
- .all ⇒ Object
- .default ⇒ Object
- .define(label, options = {}) ⇒ Object
- .with_default_tab(label) ⇒ Object
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #[](section_label) ⇒ Object
-
#initialize(label, options = {}) ⇒ Tab
constructor
A new instance of Tab.
- #localized ⇒ Object
- #sections ⇒ Object
Constructor Details
#initialize(label, options = {}) ⇒ Tab
Returns a new instance of Tab.
194 195 196 197 198 199 |
# File 'app/models/setting.rb', line 194 def initialize(label, = {}) @label = label.to_sym @label_override = [:label] @order = [:order] || 1 Setting::Section.by_tab_and_label[@label] ||= {} end |
Instance Attribute Details
#label ⇒ Object (readonly)
Returns the value of attribute label.
189 190 191 |
# File 'app/models/setting.rb', line 189 def label @label end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
189 190 191 |
# File 'app/models/setting.rb', line 189 def order @order end |
Class Method Details
.[](label) ⇒ Object
224 225 226 |
# File 'app/models/setting.rb', line 224 def [](label) @@by_label[label.to_sym] end |
.all ⇒ Object
228 229 230 |
# File 'app/models/setting.rb', line 228 def all @@all end |
.default ⇒ Object
232 233 234 |
# File 'app/models/setting.rb', line 232 def default @@default end |
.define(label, options = {}) ⇒ Object
247 248 249 250 251 252 253 254 255 256 |
# File 'app/models/setting.rb', line 247 def define(label, = {}) raise "Duplicate tab '#{label}' being defined" if @@by_label.include? label.to_sym tab = Setting::Tab.new label, @@all << tab @@by_label[label.to_sym] = tab with_default_tab label do yield if block_given? end end |
.with_default_tab(label) ⇒ Object
236 237 238 239 240 241 242 243 244 245 |
# File 'app/models/setting.rb', line 236 def with_default_tab(label) original = @@default begin @@default = label.to_sym yield ensure @@default = original end end |
Instance Method Details
#<=>(other) ⇒ Object
217 218 219 220 221 |
# File 'app/models/setting.rb', line 217 def <=>(other) result = order <=> other.order result = label <=> other.label if result == 0 result end |
#[](section_label) ⇒ Object
212 213 214 215 |
# File 'app/models/setting.rb', line 212 def [](section_label) Setting::Section.by_tab_and_label[label] ||= {} Setting::Section.by_tab_and_label[label][section_label.to_sym] end |
#localized ⇒ Object
201 202 203 204 205 |
# File 'app/models/setting.rb', line 201 def localized return @label_override.call if @label_override.respond_to? :call return @label_override if @label_override I18n.t @label, :scope => "settings.show.tabs" end |
#sections ⇒ Object
207 208 209 210 |
# File 'app/models/setting.rb', line 207 def sections Setting::Section.by_tab_and_label[label] ||= {} Setting::Section.by_tab_and_label[label].values.sort.map &:label end |