Class: SettingCrazy::Template::Base
- Inherits:
-
Object
- Object
- SettingCrazy::Template::Base
- Defined in:
- lib/settingcrazy/template/base.rb
Class Method Summary collapse
-
.available_options(key = nil) ⇒ Object
Returns the available options for the setting object.
- .defaults ⇒ Object
- .enum(id, name = id.to_s, options = {}, &block) ⇒ Object
- .enum_options(key) ⇒ Object
- .enums ⇒ Object
- .name_for(id) ⇒ Object
-
.options(name) ⇒ Object
Returns an array suitable for use in options_for_select helper Example:.
-
.valid_option?(key) ⇒ Boolean
Returns whether single keyword valid TODO: Allow passing of key or array of keys.
Class Method Details
.available_options(key = nil) ⇒ Object
Returns the available options for the setting object
36 37 38 |
# File 'lib/settingcrazy/template/base.rb', line 36 def (key=nil) key.nil? ? enums : enums[key.to_sym] end |
.defaults ⇒ Object
47 48 49 |
# File 'lib/settingcrazy/template/base.rb', line 47 def defaults {} end |
.enum(id, name = id.to_s, options = {}, &block) ⇒ Object
7 8 9 |
# File 'lib/settingcrazy/template/base.rb', line 7 def enum(id, name=id.to_s, ={}, &block) enums[id] = SettingCrazy::Template::Enum.new(name, , &block) end |
.enum_options(key) ⇒ Object
15 16 17 |
# File 'lib/settingcrazy/template/base.rb', line 15 def (key) enums[key]. end |
.enums ⇒ Object
11 12 13 |
# File 'lib/settingcrazy/template/base.rb', line 11 def enums @enums ||= {} end |
.name_for(id) ⇒ Object
30 31 32 33 |
# File 'lib/settingcrazy/template/base.rb', line 30 def name_for(id) raise "No setting with id '#{id}'" unless enums.has_key?(id) enums[id].name end |
.options(name) ⇒ Object
Returns an array suitable for use in options_for_select helper Example:
(GoogleSettings::Campaign.(:platform))
24 25 26 27 28 |
# File 'lib/settingcrazy/template/base.rb', line 24 def (name) enum = enums[name] return [] if enum.blank? enum.to_a end |
.valid_option?(key) ⇒ Boolean
Returns whether single keyword valid TODO: Allow passing of key or array of keys
42 43 44 45 |
# File 'lib/settingcrazy/template/base.rb', line 42 def valid_option?(key) key = key.to_s.gsub(/\=$/,'').to_sym #strip setter (=) from key, so can just check options hash .keys.include?(key) end |