Class: Ircbot::Client::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/ircbot/client/config/channels.rb,
lib/ircbot/client/config.rb,
lib/ircbot/client/config/plugins.rb,
lib/ircbot/client/config/generator.rb
Overview
Defined Under Namespace
Classes: Generator
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(obj) ⇒ Config
29
30
31
|
# File 'lib/ircbot/client/config.rb', line 29
def initialize(obj)
@obj = Mash.new(obj)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/ircbot/client/config.rb', line 38
def method_missing(name, *args)
if args.empty?
self[name]
else
super
end
end
|
Class Method Details
.read(path) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/ircbot/client/config.rb', line 8
def self.read(path)
path = Pathname(path)
ext = path.extname.delete(".")
ext = "yml" if ext.empty?
reader = "read_#{ext}"
if respond_to?(reader)
Mash.new(__send__(reader, path))
else
raise NotImplementedError, "Cannot read #{path}: Format(#{ext})is not supported"
end
end
|
.read_yml(path) ⇒ Object
21
22
23
24
25
|
# File 'lib/ircbot/client/config.rb', line 21
def self.read_yml(path)
require 'yaml'
path = Pathname(path)
YAML.load(path.read{})
end
|
Instance Method Details
33
34
35
|
# File 'lib/ircbot/client/config.rb', line 33
def [](key)
@obj[key]
end
|
10
11
12
13
14
15
16
17
|
# File 'lib/ircbot/client/config/channels.rb', line 10
def channels
case (val = super)
when Array
val
else
val.to_s.split
end
end
|
6
7
8
9
10
11
12
13
|
# File 'lib/ircbot/client/config/plugins.rb', line 6
def plugins
case (val = super)
when Array
val
else
val.to_s.split
end
end
|