Class: Digup::Setting

Inherits:
Object show all
Defined in:
lib/digup/setting.rb

Constant Summary collapse

RESPONSE_TYPE =
[:js, :json, :html]
LOG_TO =
[:console, :html_body, :db, :file]
BOOLEAN_SETTINGS =
[:cursor_info]
DEFAULT_SETTINGS =
{
  :response_type => [:js, :json, :html],
  :log_to => [:console, :html_body],
  :cursor_info => true
}

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/digup/setting.rb', line 15

def options
  @options
end

Class Method Details

.build_functionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/digup/setting.rb', line 17

def build_functions
  RESPONSE_TYPE.each do |rt|
    self.class.send(:define_method, "handle_#{rt}?") { options[:response_type].include?(rt) }
  end

  LOG_TO.each do |lt|
    self.class.send(:define_method, "log_to_#{lt}?") { options[:log_to].include?(lt) }
  end

  BOOLEAN_SETTINGS.each do |s|
    self.class.send(:define_method, "#{s}?") { options[s] }
  end
end

.content_type_to_handleObject



56
57
58
59
60
61
62
# File 'lib/digup/setting.rb', line 56

def content_type_to_handle
  content_type = []
  content_type << 'text/html' if handle_html?
  content_type << 'text/javascript' if handle_js?
  content_type << 'application/json' if handle_json?
  content_type
end

.enabled?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/digup/setting.rb', line 31

def enabled?
  @options.present?
end

.option_to_array(options, key) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/digup/setting.rb', line 47

def option_to_array(options, key)
  return DEFAULT_SETTINGS[key] unless options[key]
  if options[key].is_a? Array
    options[key]
  else
    [options[key]]
  end & DEFAULT_SETTINGS[key]
end