fun_with_configurations 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,8 +1,75 @@
1
- = fun_with_configurations
1
+ = fun_with_configurations : Your objects must be configurized!
2
+
3
+ Configuration and settings are the beating heart and dark, twisted soul of your operation.
4
+
5
+ Let's do some example code:
6
+
7
+ """class Computer; end;
8
+
9
+ Computers.install_fwc_config do
10
+ servers do
11
+ hopeful_host do
12
+ ip "192.168.0.25"
13
+ services :mysql, :memcached, :email, :backup
14
+ uptime `uptime`.strip
15
+ config_script "/var/configurations/hopeful.conf"
16
+ end
17
+
18
+ squishy_host do
19
+ ip "192.168.0.27"
20
+ services :postresql, :couchdb
21
+ uptime `uptime`.strip
22
+ config_script "/var/configurations/squishy.conf"
23
+ end
24
+ end
25
+
26
+ workstations do
27
+ betty do
28
+ ip "192.168.0.14"
29
+ os "Ubuntu Linux 13.04"
30
+ end
31
+
32
+ veronica do
33
+ ip "192.168.0.15"
34
+ os "Solaris 10"
35
+ end
36
+ end
37
+ end
38
+
39
+ Computers.config.servers.hopeful_host.ip # "192.168.0.25"
40
+ Computers.config.workstations.betty.ip # "192.168.0.14"
41
+ Computers.config.try.servers.grumpy_host.ip.success? # false (doesn't have that configuration setting)
42
+ """
43
+
44
+ You can also load from a hash:
45
+
46
+ """@obj.install_fwc_config_from_hash({
47
+ servers: {
48
+ hopeful_host: {
49
+ ip: "192.168.0.25",
50
+ services :mysql, :memcached, :email, :backup
51
+
52
+ ... (and so on)
53
+ }
54
+ }
55
+ })
56
+
57
+ @obj.config.servers.hopeful_host.services # [:mysql, :memcached, :email, :backup]
58
+ """
59
+
60
+ Or from a yaml string:
61
+
62
+ """@obj.install_fwc_config_from_yaml( YAML.load( File.read( "~/data/configs/circumstantial.yml" ) ) )
63
+ """
64
+
65
+ The file should represent hashes of hashes. Anything not a hash will be treated as a leaf setting (arrays, etc.).
66
+
67
+
2
68
 
3
- Description goes here.
4
69
 
5
70
  == Contributing to fun_with_configurations
71
+
72
+ [Boilerplate from Jeweler. Seems reasonable.]
6
73
 
7
74
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
75
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -100,10 +100,31 @@ module FunWith
100
100
 
101
101
  t
102
102
  end
103
-
103
+
104
+ def to_ruby_code( indent = 0 )
105
+ code = ""
106
+ if indent == 0
107
+ code << "FunWith::Configurations::Config.new do\n"
108
+ code << self.to_ruby_code( 2 )
109
+ code << "end\n"
110
+ else
111
+ for k, v in @config_vars
112
+ if v.is_a?( Config )
113
+ code << (" " * indent) + "#{k} do\n"
114
+ code << v.to_ruby_code( indent + 2 )
115
+ code << (" " * indent) + "end\n"
116
+ else
117
+ code << (" " * indent) + "#{k} #{v.inspect}\n"
118
+ end
119
+ end
120
+ end
121
+
122
+ code
123
+ end
124
+
104
125
  def self.from_hash( hash )
105
126
  config = self.new
106
-
127
+
107
128
  for k, v in hash
108
129
  config.send( k, v.is_a?( Hash ) ? self.from_hash( v ) : v )
109
130
  end
@@ -190,4 +190,24 @@ class TestFunWithConfigurations < Test::Unit::TestCase
190
190
  assert_equal "definitely", @obj3.config.servers.puppymonster.services.oauth
191
191
  end
192
192
  end
193
+
194
+ context "testing code writer" do
195
+ setup do
196
+ @obj = Object.new
197
+
198
+ @obj.install_fwc_config do
199
+ scream 1,2,3,4,5
200
+ yell [1,2,3,4,5]
201
+ whisper do
202
+ secret1 "80888"
203
+ secret2 "12345"
204
+ secret3 "99999" # the most secret combination, cuz it's the last one anyone tries
205
+ end
206
+ end
207
+ end
208
+
209
+ should "do stuff" do
210
+ assert_match /\[1, 2, 3, 4, 5\]/, @obj.config.to_ruby_code
211
+ end
212
+ end
193
213
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fun_with_configurations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -144,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
144
  version: '0'
145
145
  segments:
146
146
  - 0
147
- hash: 4158279720265668030
147
+ hash: -296390958680094426
148
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
149
  none: false
150
150
  requirements: