-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rb
31 lines (27 loc) · 987 Bytes
/
config.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
module Appdata
$VERBOSE=nil
# we don't want to instantiate this class - it's a singleton,
# so just keep it as a self-extended module
extend self
# Appdata provides a basic single-method DSL with .parameter method
# being used to define a set of available settings.
# This method takes one or more symbols, with each one being
# a name of the configuration option.
def parameter(*names)
names.each do |name|
attr_accessor name
# For each given symbol we generate accessor method that sets option's
# value being called with an argument, or returns option's current value
# when called without arguments
define_method name do |*values|
value = values.first
value ? self.send("#{name}=", value) : instance_variable_get("@#{name}")
end
end
end
# And we define a wrapper for the configuration block, that we'll use to set up
# our set of options
def config(&block)
instance_eval(&block)
end
end