Class: MyConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/tmc-client/my_config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMyConfig

Returns a new instance of MyConfig.



4
5
6
# File 'lib/tmc-client/my_config.rb', line 4

def initialize
  @config = get_config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



2
3
4
# File 'lib/tmc-client/my_config.rb', line 2

def config
  @config
end

Instance Method Details

#authObject



53
54
55
# File 'lib/tmc-client/my_config.rb', line 53

def auth
  @config[:auth] unless @config.nil?
end

#auth=(auth) ⇒ Object



48
49
50
51
# File 'lib/tmc-client/my_config.rb', line 48

def auth=(auth)
  @config[:auth] = auth
  save_config
end

#course_idObject



30
31
32
# File 'lib/tmc-client/my_config.rb', line 30

def course_id
  @config[:course_id]
end

#course_id=(id) ⇒ Object



34
35
36
# File 'lib/tmc-client/my_config.rb', line 34

def course_id=(id)
  @config[:course_id] = id
end

#get_configObject



8
9
10
11
12
13
14
15
# File 'lib/tmc-client/my_config.rb', line 8

def get_config
  begin
    yaml = YAML::load(File.open(File.join(File.dirname(File.expand_path(__FILE__)), "config.yml")))
  rescue
    raise "Error loading config.yml"
  end
  if yaml then yaml else {} end
end

#save_configObject



17
18
19
# File 'lib/tmc-client/my_config.rb', line 17

def save_config
  File.open(File.open(File.join(File.dirname(File.expand_path(__FILE__)), "config.yml")), "w") {|f| f.write(config.to_yaml) }
end

#save_course_pathObject



38
39
40
# File 'lib/tmc-client/my_config.rb', line 38

def save_course_path
  @config[:save_course_path]
end

#save_course_path=(path) ⇒ Object



42
43
44
45
46
# File 'lib/tmc-client/my_config.rb', line 42

def save_course_path=(path)
  path= "#{path}/" unless path[-1] == "/"
  @config[:save_course_path]=path
  save_config
end

#server_urlObject



21
22
23
# File 'lib/tmc-client/my_config.rb', line 21

def server_url
  @config[:server_url] unless @config.nil?
end

#server_url=(url) ⇒ Object



25
26
27
28
# File 'lib/tmc-client/my_config.rb', line 25

def server_url=(url)
  @config[:server_url] = url
  save_config
end