Class: SettingCrazy::Template::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/settingcrazy/template/base.rb

Class Method Summary collapse

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 available_options(key=nil)
  key.nil? ? enums : enums[key.to_sym]
end

.defaultsObject



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, options={}, &block)
  enums[id] = SettingCrazy::Template::Enum.new(name, options, &block)
end

.enum_options(key) ⇒ Object



15
16
17
# File 'lib/settingcrazy/template/base.rb', line 15

def enum_options(key)
  enums[key].options
end

.enumsObject



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:

options_for_select(GoogleSettings::Campaign.options(:platform))


24
25
26
27
28
# File 'lib/settingcrazy/template/base.rb', line 24

def options(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

Returns:

  • (Boolean)


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
  available_options.keys.include?(key)
end