yacl 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/HISTORY.rdoc +5 -0
  2. data/LICENSE +16 -0
  3. data/Manifest.txt +48 -0
  4. data/README.rdoc +55 -0
  5. data/Rakefile +308 -0
  6. data/example/myapp-simple/bin/myapp +16 -0
  7. data/example/myapp-simple/config/database.yml +8 -0
  8. data/example/myapp-simple/config/host.yml +2 -0
  9. data/example/myapp-simple/config/pipeline.yml +1 -0
  10. data/example/myapp-simple/lib/myapp.rb +53 -0
  11. data/example/myapp/bin/myapp +17 -0
  12. data/example/myapp/bin/myapp-job +10 -0
  13. data/example/myapp/config/database.yml +8 -0
  14. data/example/myapp/config/httpserver.yml +3 -0
  15. data/example/myapp/config/pipeline.yml +1 -0
  16. data/example/myapp/lib/myapp.rb +6 -0
  17. data/example/myapp/lib/myapp/cli.rb +92 -0
  18. data/example/myapp/lib/myapp/defaults.rb +28 -0
  19. data/example/myapp/lib/myapp/job.rb +56 -0
  20. data/lib/yacl.rb +12 -0
  21. data/lib/yacl/define.rb +9 -0
  22. data/lib/yacl/define/cli.rb +7 -0
  23. data/lib/yacl/define/cli/options.rb +97 -0
  24. data/lib/yacl/define/cli/parser.rb +112 -0
  25. data/lib/yacl/define/cli/runner.rb +82 -0
  26. data/lib/yacl/define/defaults.rb +58 -0
  27. data/lib/yacl/define/plan.rb +197 -0
  28. data/lib/yacl/loader.rb +80 -0
  29. data/lib/yacl/loader/env.rb +103 -0
  30. data/lib/yacl/loader/yaml_dir.rb +137 -0
  31. data/lib/yacl/loader/yaml_file.rb +102 -0
  32. data/lib/yacl/properties.rb +144 -0
  33. data/lib/yacl/simple.rb +52 -0
  34. data/spec/data/yaml_dir/database.yml +8 -0
  35. data/spec/data/yaml_dir/httpserver.yml +3 -0
  36. data/spec/define/cli/options_spec.rb +47 -0
  37. data/spec/define/cli/parser_spec.rb +64 -0
  38. data/spec/define/cli/runner_spec.rb +57 -0
  39. data/spec/define/defaults_spec.rb +24 -0
  40. data/spec/define/plan_spec.rb +77 -0
  41. data/spec/loader/env_spec.rb +32 -0
  42. data/spec/loader/yaml_dir_spec.rb +43 -0
  43. data/spec/loader/yaml_file_spec.rb +80 -0
  44. data/spec/loader_spec.rb +16 -0
  45. data/spec/properties_spec.rb +60 -0
  46. data/spec/simple_spec.rb +85 -0
  47. data/spec/spec_helper.rb +31 -0
  48. data/spec/version_spec.rb +8 -0
  49. metadata +207 -0
@@ -0,0 +1,60 @@
1
+ require 'spec_helper'
2
+ require 'yacl/properties'
3
+
4
+ describe 'Yacl::Properties' do
5
+ before do
6
+ @properties = Yacl::Properties.new( 'my.a' => 'foo', 'my.b' => 'bar', 'other.c' => 'baz', 'other.deep.foo' => 'wibble' )
7
+ end
8
+ it "can be initialized with a hash" do
9
+ p = Yacl::Properties.new( 'a' => 'foo', 'b' => 'bar' )
10
+ p['a'].must_equal 'foo'
11
+ p.a.must_equal 'foo'
12
+ end
13
+
14
+ it "can access values with a dot notiation" do
15
+ @properties.my.b.must_equal 'bar'
16
+ end
17
+
18
+ it "can be scoped by a prefix" do
19
+ s = @properties.scoped_by( 'my' )
20
+ s['a'].must_equal 'foo'
21
+ s.a.must_equal 'foo'
22
+ s['b'].must_equal 'bar'
23
+ s.b.must_equal 'bar'
24
+ s.has_key?( 'c' ).must_equal false
25
+ s.c?.must_equal false
26
+ end
27
+
28
+ it "can say what its scopes are" do
29
+ @properties.scopes.must_equal %w[ my other ]
30
+ end
31
+
32
+ it "can say that it has a given scope" do
33
+ @properties.has_scope?( 'my' ).must_equal true
34
+ end
35
+
36
+ it "can scope to multiple levels via dotted notation" do
37
+ s = @properties.scoped_by('other.deep')
38
+ s.foo.must_equal 'wibble'
39
+ end
40
+
41
+ it "can scope to multiple levels via args notation" do
42
+ s = @properties.scoped_by(:other, :deep)
43
+ s.foo.must_equal 'wibble'
44
+ end
45
+
46
+ it "returns a blank property if scoped by someting that doesn't exist" do
47
+ s = @properties.scoped_by( :does, :not, :exist )
48
+ s.length.must_equal 0
49
+ end
50
+
51
+ it "can say that it does not have a scope" do
52
+ @properties.has_scope?( 'your' ).must_equal false
53
+ end
54
+
55
+ it "can merge with another property" do
56
+ @properties.merge!( Yacl::Properties.new( 'c' => 'baz', 'my.b' => 'blah' ) )
57
+ @properties.c.must_equal 'baz'
58
+ @properties.my.b.must_equal 'blah'
59
+ end
60
+ end
@@ -0,0 +1,85 @@
1
+ require 'spec_helper'
2
+ require 'yacl/simple'
3
+
4
+ class Yacl::Spec::Simple < Yacl::Simple
5
+
6
+ defaults do
7
+ default 'host.name', 'localhost'
8
+ default 'host.port', 80
9
+ end
10
+
11
+ parser do
12
+ banner "MySimpleApp version 4.2"
13
+ opt 'host.port', :long => 'port', :short => 'p', :description => "The port to listen on", :cast => :int
14
+ opt 'host.bind', :long => 'address', :short => 'a', :description => "The address to listen at", :cast => :string
15
+ opt 'config.dir', :long => 'config', :short => 'c', :description => "The configuration directory", :cast => :string
16
+ opt 'log.level', :long => 'log-level', :short => 'l', :description => "The system setting", :cast => :string
17
+ end
18
+
19
+ plan do
20
+ try Yacl::Spec::Simple.parser
21
+ try Yacl::Loader::Env, :prefix => 'MY_APP'
22
+ try Yacl::Loader::YamlDir, :parameter => 'config.dir'
23
+ try Yacl::Spec::Simple.defaults
24
+
25
+ on_error do |exception|
26
+ $stderr.puts "ERROR: #{exception}"
27
+ $stderr.puts "Try --help for help"
28
+ end
29
+ end
30
+
31
+ def run
32
+ properties
33
+ end
34
+
35
+ end
36
+
37
+ describe Yacl::Simple do
38
+
39
+ it "#defaults creates a child class of Yacl::Define::Defaults" do
40
+ dklass = Yacl::Simple.defaults do
41
+ default 'host.bind', 'localhost'
42
+ default 'host.port', 80
43
+ default 'config.dir', '/tmp'
44
+ default 'log.level', 'error'
45
+ end
46
+ d = dklass.new
47
+
48
+ d.must_be_kind_of Yacl::Define::Defaults
49
+ d.host.bind.must_equal 'localhost'
50
+ d.host.port.must_equal 80
51
+
52
+ end
53
+
54
+ it "#parser creates a child class of Yacl::Define::Parser" do
55
+ klass = Yacl::Simple.parser do
56
+ banner "MySimpleApp version 4.2"
57
+ opt 'host.port', :long => 'port', :short => 'p', :description => "The port to listen on", :cast => :int
58
+ opt 'host.bind', :long => 'address', :short => 'a', :description => "The address to listen at", :cast => :string
59
+ opt 'directory', :long => 'directory', :short => 'd', :description => "The directory to operate out of", :cast => :string
60
+ opt 'log.level', :long => 'log-level', :short => 'l', :description => "The system setting", :cast => :string
61
+ end
62
+
63
+ argv = [ '--directory' , Dir.pwd, '--port' , "4321", '--address', 'localhost' ]
64
+ p = klass.new( :argv => argv )
65
+ p.banner.must_equal 'MySimpleApp version 4.2'
66
+ props = p.properties
67
+ props.directory.must_equal Dir.pwd
68
+ props.host.port.must_equal 4321
69
+ props.host.bind.must_equal 'localhost'
70
+ end
71
+
72
+ it "can define a full plan" do
73
+ config_dir = File.join( Yacl::Spec::Helpers.proj_root, 'example/myapp-simple/myapp/config' )
74
+ argv = [ '--config' , config_dir , '--log-level', 'info' ]
75
+ simple = Yacl::Spec::Simple.go( argv )
76
+ simple.host.port.must_equal 4321
77
+ end
78
+
79
+ it "can use the on_error exception" do
80
+ out, err = capture_io do
81
+ Yacl::Spec::Simple.go
82
+ end
83
+ err.must_match( /Try --help for help/m )
84
+ end
85
+ end
@@ -0,0 +1,31 @@
1
+ if RUBY_VERSION >= '1.9.2' then
2
+ require 'simplecov'
3
+ puts "Using coverage!"
4
+ SimpleCov.start if ENV['COVERAGE']
5
+ end
6
+
7
+ gem 'minitest'
8
+ require 'yacl'
9
+ require 'minitest/autorun'
10
+ require 'minitest/pride'
11
+ require 'tmpdir'
12
+
13
+ module Yacl
14
+ module Spec
15
+ module Helpers
16
+ def self.tmpfile_with_contents( full_path, contents )
17
+ File.open( full_path, "w+" ) do |f|
18
+ f.write( contents )
19
+ end
20
+ end
21
+
22
+ def self.spec_dir( *other )
23
+ ::File.join( proj_root, 'spec', other )
24
+ end
25
+
26
+ def self.proj_root
27
+ ::File.expand_path( "../../", __FILE__)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Yacl::VERSION' do
4
+ it 'should have a #.#.# format' do
5
+ Yacl::VERSION.must_match( /\A\d+\.\d+\.\d+\Z/ )
6
+ Yacl::VERSION.to_s.must_match( /\A\d+\.\d+\.\d+\Z/ )
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yacl
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Jeremy Hinegardner
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-28 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: map
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 39
29
+ segments:
30
+ - 6
31
+ - 2
32
+ - 0
33
+ version: 6.2.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: trollop
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 47
45
+ segments:
46
+ - 1
47
+ - 16
48
+ version: "1.16"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rake
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 11
60
+ segments:
61
+ - 0
62
+ - 9
63
+ - 2
64
+ - 2
65
+ version: 0.9.2.2
66
+ type: :development
67
+ version_requirements: *id003
68
+ - !ruby/object:Gem::Dependency
69
+ name: minitest
70
+ prerelease: false
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ hash: 11
77
+ segments:
78
+ - 3
79
+ - 3
80
+ - 0
81
+ version: 3.3.0
82
+ type: :development
83
+ version_requirements: *id004
84
+ - !ruby/object:Gem::Dependency
85
+ name: rdoc
86
+ prerelease: false
87
+ requirement: &id005 !ruby/object:Gem::Requirement
88
+ none: false
89
+ requirements:
90
+ - - ~>
91
+ - !ruby/object:Gem::Version
92
+ hash: 31
93
+ segments:
94
+ - 3
95
+ - 12
96
+ version: "3.12"
97
+ type: :development
98
+ version_requirements: *id005
99
+ description: YACL is your application configuration library.
100
+ email: jeremy@copiousfreetime.org
101
+ executables: []
102
+
103
+ extensions: []
104
+
105
+ extra_rdoc_files:
106
+ - HISTORY.rdoc
107
+ - Manifest.txt
108
+ - README.rdoc
109
+ files:
110
+ - HISTORY.rdoc
111
+ - LICENSE
112
+ - Manifest.txt
113
+ - README.rdoc
114
+ - Rakefile
115
+ - example/myapp-simple/bin/myapp
116
+ - example/myapp-simple/config/database.yml
117
+ - example/myapp-simple/config/host.yml
118
+ - example/myapp-simple/config/pipeline.yml
119
+ - example/myapp-simple/lib/myapp.rb
120
+ - example/myapp/bin/myapp
121
+ - example/myapp/bin/myapp-job
122
+ - example/myapp/config/database.yml
123
+ - example/myapp/config/httpserver.yml
124
+ - example/myapp/config/pipeline.yml
125
+ - example/myapp/lib/myapp.rb
126
+ - example/myapp/lib/myapp/cli.rb
127
+ - example/myapp/lib/myapp/defaults.rb
128
+ - example/myapp/lib/myapp/job.rb
129
+ - lib/yacl.rb
130
+ - lib/yacl/define.rb
131
+ - lib/yacl/define/cli.rb
132
+ - lib/yacl/define/cli/options.rb
133
+ - lib/yacl/define/cli/parser.rb
134
+ - lib/yacl/define/cli/runner.rb
135
+ - lib/yacl/define/defaults.rb
136
+ - lib/yacl/define/plan.rb
137
+ - lib/yacl/loader.rb
138
+ - lib/yacl/loader/env.rb
139
+ - lib/yacl/loader/yaml_dir.rb
140
+ - lib/yacl/loader/yaml_file.rb
141
+ - lib/yacl/properties.rb
142
+ - lib/yacl/simple.rb
143
+ - spec/data/yaml_dir/database.yml
144
+ - spec/data/yaml_dir/httpserver.yml
145
+ - spec/define/cli/options_spec.rb
146
+ - spec/define/cli/parser_spec.rb
147
+ - spec/define/cli/runner_spec.rb
148
+ - spec/define/defaults_spec.rb
149
+ - spec/define/plan_spec.rb
150
+ - spec/loader/env_spec.rb
151
+ - spec/loader/yaml_dir_spec.rb
152
+ - spec/loader/yaml_file_spec.rb
153
+ - spec/loader_spec.rb
154
+ - spec/properties_spec.rb
155
+ - spec/simple_spec.rb
156
+ - spec/spec_helper.rb
157
+ - spec/version_spec.rb
158
+ homepage: http://github.com/copiousfreetime/yacl
159
+ licenses: []
160
+
161
+ post_install_message:
162
+ rdoc_options:
163
+ - --main
164
+ - README.rdoc
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ none: false
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ hash: 3
173
+ segments:
174
+ - 0
175
+ version: "0"
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
184
+ version: "0"
185
+ requirements: []
186
+
187
+ rubyforge_project:
188
+ rubygems_version: 1.8.15
189
+ signing_key:
190
+ specification_version: 3
191
+ summary: YACL is your application configuration library.
192
+ test_files:
193
+ - spec/data/yaml_dir/database.yml
194
+ - spec/data/yaml_dir/httpserver.yml
195
+ - spec/define/cli/options_spec.rb
196
+ - spec/define/cli/parser_spec.rb
197
+ - spec/define/cli/runner_spec.rb
198
+ - spec/define/defaults_spec.rb
199
+ - spec/define/plan_spec.rb
200
+ - spec/loader/env_spec.rb
201
+ - spec/loader/yaml_dir_spec.rb
202
+ - spec/loader/yaml_file_spec.rb
203
+ - spec/loader_spec.rb
204
+ - spec/properties_spec.rb
205
+ - spec/simple_spec.rb
206
+ - spec/spec_helper.rb
207
+ - spec/version_spec.rb