kung_figure 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -83,6 +83,37 @@ Or inside instances of WorkHorse as config method.
83
83
 
84
84
  == CHANGE LOG
85
85
 
86
+ * 0.0.2 add MyModule.clear_config! (clear configs for all nested configs) and MyModule.clear_config (clear concrete configs) and KungFigure.clear_all_configs methods
87
+
88
+ == TODO
89
+
90
+ * Give the posibility clear one branch of configs
91
+
86
92
  == MORE
87
93
 
88
94
  For more info see tests and source code :)
95
+
96
+ == LICENSE:
97
+
98
+ (The MIT License)
99
+
100
+ Copyright (c) 2010 niquola
101
+
102
+ Permission is hereby granted, free of charge, to any person obtaining
103
+ a copy of this software and associated documentation files (the
104
+ 'Software'), to deal in the Software without restriction, including
105
+ without limitation the rights to use, copy, modify, merge, publish,
106
+ distribute, sublicense, and/or sell copies of the Software, and to
107
+ permit persons to whom the Software is furnished to do so, subject to
108
+ the following conditions:
109
+
110
+ The above copyright notice and this permission notice shall be
111
+ included in all copies or substantial portions of the Software.
112
+
113
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
114
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
115
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
116
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
117
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
118
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
119
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -28,7 +28,7 @@ PKG_FILES = FileList[ '[a-zA-Z]*', 'generators/**/*', 'lib/**/*', 'rails/**/*',
28
28
 
29
29
  spec = Gem::Specification.new do |s|
30
30
  s.name = "kung_figure"
31
- s.version = "0.0.1"
31
+ s.version = "0.0.2"
32
32
  s.author = "niquola"
33
33
  s.email = "niquola@gmail.com"
34
34
  s.homepage = "http://github.com/niquola/kung_figure"
data/lib/kung_figure.rb CHANGED
@@ -1,6 +1,30 @@
1
1
  module KungFigure
2
+ class << self
3
+ def clear_all_configs
4
+ KungFigure::Register.each do |klz|
5
+ klz.clear_config
6
+ end
7
+ end
8
+ end
9
+ class Register
10
+ class<< self
11
+ def items
12
+ @items ||=[]
13
+ end
14
+ def add(klazz)
15
+ items<< klazz
16
+ end
17
+
18
+ def each
19
+ items.each do |klz|
20
+ yield klz
21
+ end
22
+ end
23
+ end
24
+ end
2
25
 
3
26
  def self.included(base)
27
+ KungFigure::Register.add(base)
4
28
  base.extend(ClassMethods)
5
29
  end
6
30
 
@@ -21,6 +45,20 @@ module KungFigure
21
45
  @config ||= root_config_class.new
22
46
  end
23
47
 
48
+ def clear_config
49
+ @config = root_config_class.new
50
+ end
51
+
52
+ def clear_config!
53
+ KungFigure::Register.each do |klz|
54
+ #clear only branch for this module
55
+ reg = /^#{self.name}/
56
+ if klz.name.to_s =~ reg
57
+ klz.clear_config
58
+ end
59
+ end
60
+ end
61
+
24
62
  def configure(&block)
25
63
  config.instance_eval &block
26
64
  end
@@ -47,13 +85,13 @@ module KungFigure
47
85
  def camelize(str)
48
86
  str.split('_').map{|l| l.capitalize}.join('')
49
87
  end
50
-
88
+
51
89
  def get_from_enclosing_module(klazz_name)
52
90
  config_klazz_path=self.class.name.to_s.split('::')[0..-2]
53
91
  config_klazz_path<< klazz_name
54
92
  config_klazz_path.inject(Object){|parent,nxt|
55
- break unless parent.const_defined?(nxt.to_sym)
56
- parent.const_get(nxt.to_sym)
93
+ break unless parent.const_defined?(nxt.to_sym)
94
+ parent.const_get(nxt.to_sym)
57
95
  }
58
96
  end
59
97
 
@@ -75,5 +113,7 @@ module KungFigure
75
113
  @props[key].instance_eval(&block) if block_given?
76
114
  return @props[key]
77
115
  end
116
+ #end KungFigure::Base
78
117
  end
118
+ #end KungFigure module
79
119
  end
@@ -16,6 +16,13 @@ module MyModule
16
16
  end
17
17
  end
18
18
 
19
+ module Another
20
+ include KungFigure
21
+ class Config < KungFigure::Base
22
+ define_prop :prop,'default'
23
+ end
24
+ end
25
+
19
26
 
20
27
  module MyModule
21
28
  class WorkHorse
@@ -46,6 +53,7 @@ class TestKungFigure < Test::Unit::TestCase
46
53
  end
47
54
 
48
55
  def test_nested_config_declaration
56
+ MyModule.clear_config!
49
57
  assert_equal('default',MyModule.config.work_horse.my_config)
50
58
  assert_equal('default',MyModule::WorkHorse.config.my_config)
51
59
  MyModule.configure do
@@ -57,4 +65,14 @@ class TestKungFigure < Test::Unit::TestCase
57
65
  assert_equal('new value',MyModule::WorkHorse.config.my_config)
58
66
  assert_equal(MyModule::WorkHorse.config,MyModule::WorkHorse.new.config)
59
67
  end
68
+
69
+ def test_clear_configuration
70
+ MyModule.config.work_horse.my_config 'some config'
71
+ MyModule.config.prop1 'some config'
72
+ Another.config.prop 'some config'
73
+ MyModule.clear_config!
74
+ assert_equal('default',MyModule.config.work_horse.my_config)
75
+ assert_equal('default1',MyModule.config.prop1)
76
+ assert_equal('some config',Another.config.prop,'This branch not cleared')
77
+ end
60
78
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kung_figure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - niquola