Class: SupportPal::Configure

Inherits:
Object
  • Object
show all
Defined in:
lib/supportpal/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Configure

Returns a new instance of Configure.



36
37
38
39
40
41
42
43
44
# File 'lib/supportpal/config.rb', line 36

def initialize(config = nil)
  default_config
  @valid_config_keys = @config.keys
  if config.class == Hash then
    configure(config)
  elsif config.class == String then
    configure_with(config)
  end
end

Instance Method Details

#configObject



32
33
34
# File 'lib/supportpal/config.rb', line 32

def config
  @config
end

#configure(opts = {}) ⇒ Object



17
18
19
# File 'lib/supportpal/config.rb', line 17

def configure(opts = {})
  opts.each {|k,v| @config[k.to_sym] = v if @valid_config_keys.include? k.to_sym}
end

#configure_with(path_to_yaml_file) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/supportpal/config.rb', line 21

def configure_with(path_to_yaml_file)
  begin
    config = YAML::load(IO.read(path_to_yaml_file))
  rescue Errno::ENOENT
    puts "YAML configuration file couldn't be found. Using defaults."; return
  rescue Psych::SyntaxError
    puts "YAML configuration file contains invalid syntax. Using defaults."; return
  end
  configure(config)
end

#default_configObject



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/supportpal/config.rb', line 5

def default_config
  @config = {
    :ticket_status                  => 1, # Open
    :ticket_priority                => 1, # Low
    :ticket_user_id                 => nil, # Operator or user
    :ticket_department_id           => nil,
    :ticket_send_user_email         => false, # Send an email to the user who opens the ticket when ticket opens
    :ticket_send_operators_email    => false, # Send an email to all operators when ticket opens
    :auth_token                     => nil, # SupportPal token
  }
end