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.
184 185 186 187 188 189 |
# File 'app/models/setting.rb', line 184 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.
179 180 181 |
# File 'app/models/setting.rb', line 179 def label @label end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
179 180 181 |
# File 'app/models/setting.rb', line 179 def order @order end |
Class Method Details
.[](label) ⇒ Object
214 215 216 |
# File 'app/models/setting.rb', line 214 def [](label) @@by_label[label.to_sym] end |
.all ⇒ Object
218 219 220 |
# File 'app/models/setting.rb', line 218 def all @@all end |
.default ⇒ Object
222 223 224 |
# File 'app/models/setting.rb', line 222 def default @@default end |
.define(label, options = {}) ⇒ Object
237 238 239 240 241 242 243 244 245 246 |
# File 'app/models/setting.rb', line 237 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
226 227 228 229 230 231 232 233 234 235 |
# File 'app/models/setting.rb', line 226 def with_default_tab(label) original = @@default begin @@default = label.to_sym yield ensure @@default = original end end |
Instance Method Details
#<=>(other) ⇒ Object
207 208 209 210 211 |
# File 'app/models/setting.rb', line 207 def <=>(other) result = order <=> other.order result = label <=> other.label if result == 0 result end |
#[](section_label) ⇒ Object
202 203 204 205 |
# File 'app/models/setting.rb', line 202 def [](section_label) Setting::Section.by_tab_and_label[label] ||= {} Setting::Section.by_tab_and_label[label][section_label.to_sym] end |
#localized ⇒ Object
191 192 193 194 195 |
# File 'app/models/setting.rb', line 191 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
197 198 199 200 |
# File 'app/models/setting.rb', line 197 def sections Setting::Section.by_tab_and_label[label] ||= {} Setting::Section.by_tab_and_label[label].values.sort.map &:label end |