Class: MyConfig
- Inherits:
-
Object
- Object
- MyConfig
- Defined in:
- lib/tmc-client/my_config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
- #auth ⇒ Object
- #auth=(auth) ⇒ Object
- #course_id ⇒ Object
- #course_id=(id) ⇒ Object
- #get_config ⇒ Object
-
#initialize ⇒ MyConfig
constructor
A new instance of MyConfig.
- #save_config ⇒ Object
- #save_course_path ⇒ Object
- #save_course_path=(path) ⇒ Object
- #server_url ⇒ Object
- #server_url=(url) ⇒ Object
Constructor Details
#initialize ⇒ MyConfig
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
#config ⇒ Object
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
#auth ⇒ Object
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_id ⇒ Object
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_config ⇒ Object
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.(__FILE__)), "config.yml"))) rescue raise "Error loading config.yml" end if yaml then yaml else {} end end |
#save_config ⇒ Object
17 18 19 |
# File 'lib/tmc-client/my_config.rb', line 17 def save_config File.open(File.open(File.join(File.dirname(File.(__FILE__)), "config.yml")), "w") {|f| f.write(config.to_yaml) } end |
#save_course_path ⇒ Object
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_url ⇒ Object
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 |