Class: TreasureData::Config
- Inherits:
-
Object
- Object
- TreasureData::Config
- Defined in:
- lib/td/config.rb
Constant Summary collapse
- @@path =
class variables
ENV['TREASURE_DATA_CONFIG_PATH'] || ENV['TD_CONFIG_PATH'] || File.join(ENV['HOME'], '.td', 'td.conf')
- @@apikey =
nil
- @@cl_apikey =
flag to indicate whether an apikey has been provided through the command-line
false
- @@endpoint =
nil
- @@cl_endpoint =
flag to indicate whether an endpoint has been provided through the command-line
false
- @@import_endpoint =
nil
- @@cl_import_endpoint =
flag to indicate whether an endpoint has been provided through the command-line option
false
- @@secure =
true
- @@retry_post_requests =
false
Class Method Summary collapse
Instance Method Summary collapse
- #[](cate_key) ⇒ Object
- #[]=(cate_key, val) ⇒ Object
- #delete(cate_key) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #read(path = @path) ⇒ Object
- #save(path = @path||Config.path) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
30 31 32 33 |
# File 'lib/td/config.rb', line 30 def initialize @path = nil @conf = {} # section.key = val end |
Class Method Details
.read(path = Config.path, create = false) ⇒ Object
35 36 37 |
# File 'lib/td/config.rb', line 35 def self.read(path=Config.path, create=false) new.read(path) end |
Instance Method Details
#[](cate_key) ⇒ Object
39 40 41 |
# File 'lib/td/config.rb', line 39 def [](cate_key) @conf[cate_key] end |
#[]=(cate_key, val) ⇒ Object
43 44 45 |
# File 'lib/td/config.rb', line 43 def []=(cate_key, val) @conf[cate_key] = val end |
#delete(cate_key) ⇒ Object
47 48 49 |
# File 'lib/td/config.rb', line 47 def delete(cate_key) @conf.delete(cate_key) end |
#read(path = @path) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/td/config.rb', line 51 def read(path=@path) @path = path begin data = File.read(@path) rescue e = ConfigNotFoundError.new($!.to_s) e.set_backtrace($!.backtrace) raise e end section = "" data.each_line {|line| line.strip! case line when /^#/ next when /\[(.+)\]/ section = $~[1] when /^(\w+)\s*=\s*(.+?)\s*$/ key = $~[1] val = $~[2] @conf["#{section}.#{key}"] = val else raise ConfigParseError, "invalid config line '#{line}' at #{@path}" end } self end |
#save(path = @path||Config.path) ⇒ Object
82 83 84 85 |
# File 'lib/td/config.rb', line 82 def save(path=@path||Config.path) @path = path write end |