canfig 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/canfig/class.rb +15 -0
- data/lib/canfig/{configuration.rb → config.rb} +8 -4
- data/lib/canfig/module.rb +17 -0
- data/lib/canfig/object.rb +11 -0
- data/lib/canfig/open_config.rb +7 -0
- data/lib/canfig/version.rb +1 -1
- data/lib/canfig.rb +5 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 943269b9166513da09c866d6d4bae9e8bdb7f79c
|
4
|
+
data.tar.gz: d1988d15d10df3182c134075461db5640f0bd595
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23d2195e6ae6b208e3a411b2de8904bef726a15c8dc5a4bf06f787fede78161485e3c24404655e63adf450d7fb0a8c7302453f87ee659d87ed171b2f7b39c2b0
|
7
|
+
data.tar.gz: d04944fa211c31db6f20df83f45824bf486c22de4568ce92b38860f875526edf197915d7619b6b07530948534c3449f747c423c6265c08e475eb90ff27de6444
|
data/lib/canfig/class.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Canfig
|
2
|
+
module Class
|
3
|
+
def self.included(base)
|
4
|
+
base.send :cattr_reader, :configuration
|
5
|
+
base.send :class_variable_set, :@@configuration, Canfig::OpenConfig.new
|
6
|
+
base.send :extend, Canfig::Class::ClassMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def configure(&block)
|
11
|
+
(send :class_variable_get, :@@configuration).configure &block
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Canfig
|
2
|
-
class
|
2
|
+
class Config
|
3
3
|
|
4
4
|
def configure(argh={}, &block)
|
5
5
|
@options ||= {}
|
@@ -23,7 +23,7 @@ module Canfig
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def configure_option(key, val)
|
26
|
-
raise ArgumentError, "#{key} is not an allowed configuration option" unless
|
26
|
+
raise ArgumentError, "#{key} is not an allowed configuration option" unless allowed?(key)
|
27
27
|
|
28
28
|
save_state! do
|
29
29
|
@changed[key] = [@options[key], val]
|
@@ -71,12 +71,16 @@ module Canfig
|
|
71
71
|
@save_state
|
72
72
|
end
|
73
73
|
|
74
|
+
def allowed?(opt)
|
75
|
+
@allowed.include?(opt)
|
76
|
+
end
|
77
|
+
|
74
78
|
def method_missing(meth, *args, &block)
|
75
79
|
if meth.to_s.match(/=\Z/)
|
76
80
|
opt = meth.to_s.gsub(/=/,'').to_sym
|
77
|
-
return configure_option(opt, args.first) if
|
81
|
+
return configure_option(opt, args.first) if allowed?(meth)
|
78
82
|
else
|
79
|
-
return @options[meth] if
|
83
|
+
return @options[meth] if allowed?(meth)
|
80
84
|
end
|
81
85
|
|
82
86
|
super
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
2
|
+
|
3
|
+
module Canfig
|
4
|
+
module Module
|
5
|
+
def self.included(base)
|
6
|
+
base.send :cattr_reader, :configuration
|
7
|
+
base.send :class_variable_set, :@@configuration, Canfig::OpenConfig.new
|
8
|
+
base.send :extend, ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def configure(&block)
|
13
|
+
(send :class_variable_get, :@@configuration).configure &block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/canfig/version.rb
CHANGED
data/lib/canfig.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
require 'active_support/core_ext/array/extract_options'
|
2
2
|
require 'active_support/core_ext/hash/keys'
|
3
3
|
require 'canfig/version'
|
4
|
-
require 'canfig/
|
4
|
+
require 'canfig/config'
|
5
|
+
require 'canfig/open_config'
|
6
|
+
require 'canfig/module'
|
7
|
+
require 'canfig/class'
|
8
|
+
require 'canfig/object'
|
5
9
|
|
6
10
|
module Canfig
|
7
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
@@ -60,7 +60,11 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- lib/canfig.rb
|
63
|
-
- lib/canfig/
|
63
|
+
- lib/canfig/class.rb
|
64
|
+
- lib/canfig/config.rb
|
65
|
+
- lib/canfig/module.rb
|
66
|
+
- lib/canfig/object.rb
|
67
|
+
- lib/canfig/open_config.rb
|
64
68
|
- lib/canfig/version.rb
|
65
69
|
- spec/spec_helper.rb
|
66
70
|
homepage: http://github.com/markrebec/canfig
|