jeckyl 0.3.7 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NTVhZDM0YjllODFmZmViOGFjMmE1YzkwNmEzNDc5ODAwMTE4Y2Q1NA==
4
+ ZWFjY2JkYjIxZWQwMjRiMjM5MzlhZmQxOTk3NzJkZTlmN2ZjZTQzNg==
5
5
  data.tar.gz: !binary |-
6
- Y2E5NWYxZjllYzI5ODE4YTk3MWRkODgxMWQ5NDY4MTQ2MjlmNzRjOA==
6
+ ODBkN2VmMmE1Y2QwOTFiOTM4NzYzMWI2YTc1NzhkMjM2ZTE5YzU4MA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- YzY0MTQ5YjNjZWZlZmU2ODFlY2E4Njg0MmYzYjZlODg4MWIzNDQ2MmNiYTVk
10
- MzdhN2NmNDZkNmNkZGM0YWJkOTU0YmQ2ZjFjODNhZDlkYzFiNzAyNGEzMDVl
11
- MDcyMjFmNjNiZGM5NDJiNmQwZWQwMDYyOGVlMWEzZTk3ZjI4YWE=
9
+ MmQ4ZDFmODUxYmM2MGJkMWVhYmE1NThkNWMzM2I4MjI1MjE1MWNhNmM2MTA5
10
+ MWFiMDgzMGNmNjQ2OWEyNDU5NDcxNjYxNWRlMzRjMDZiZTIyZWRiYWU1NDRh
11
+ Y2ZjYjZmNWVkODMxODdhNTlkNmFiNWIwOGQ5OWU3MjA2YjBkNzU=
12
12
  data.tar.gz: !binary |-
13
- MzhhYjQ1MTRiNGMwOGFlZTM2Mjg3OTZkNDQ4YzYzNjQ1N2YyOTY5NDVhNzBi
14
- MmUwMWJiMThlYTQ3ZmRjNmIwZmQ4N2Q1MjhlNTRlM2IzZWUwNTE0MmZjMjdm
15
- YTViNDYxMjg3ZDcyMjcwOTQwZGFiOTRhN2UwZWNmMDkyMjAzM2Q=
13
+ ZmQzNjNkNGMxMjJjZjA5NmQ4NDdmZmM4NzM1OWU0YzlkY2NkNjRiNzRkODdj
14
+ ZWI3YzYwNWY3YzdmNTY5OTdkMGUzYjI4NWE1MDE5ZTQ1OTg0MjRmY2U1N2Ni
15
+ NWY0MjJjYTY2YzM2NmY0MzBjNWYzZjJkZDUwYWEyYzI4YTdkOGE=
data/Bugs.rdoc CHANGED
@@ -14,5 +14,6 @@
14
14
  force_again = options[:force_init]
15
15
  => false
16
16
 
17
- Very strange and unexpected behaviour.
17
+ Very strange and unexpected behaviour, but it does not happen very often. Unable to reproduce
18
+ in controlled conditions.
18
19
 
data/Gemfile CHANGED
@@ -1,8 +1,5 @@
1
1
  #@markup ruby
2
2
 
3
- # for the command line
4
- # gem 'thor' not any more
5
- # gem 'term-ansicolor'
6
-
3
+ # for jeckyl command line processing
7
4
  gem 'optplus', '>=0.0.6'
8
5
 
@@ -4,6 +4,19 @@
4
4
 
5
5
  == History
6
6
 
7
+ [jeckyl-0.4.0 01-Oct-2014]
8
+
9
+ General tidy up of gem (README, rspec tests etc) to bring things up to date.
10
+
11
+ [jeckyl-0.3.9 27-Jun-2014]
12
+
13
+ Fix #to_s to return a string and not output!
14
+
15
+ [jeckyl-0.3.8 24-Jun-2014]
16
+
17
+ Added compound names to klass action for 'jeckyl' command, used to generate class
18
+ files
19
+
7
20
  [jeckyl-0.3.7 19-Sep-2013]
8
21
 
9
22
  Corrected some minor yard issues
data/README.md CHANGED
@@ -1,12 +1,17 @@
1
1
  #JECKYL
2
2
 
3
- (a.k.a. Jumpin' Ermin's Configurator for Kwick and easY Linux services)
4
-
5
- Jeckyl can be used to create a parameters hash from a simple config file written in Ruby, having run whatever checks you want
6
- on the file to ensure the values passed in are valid. All you need to do is define a class inheriting from Jeckyl, methods for
7
- each parameter, its default, whatever checking rules are appropriate and even a comment for generating templates etc.
8
- This is then used to parse a Ruby config file and create the parameters hash. Jeckyl
9
- comes complete with a utility to check a config file against a given class and to generate a default file for you to tailor.
3
+ Jeckyl is a versatile configuration file manager. It provides a simple way of defining
4
+ and checking configuration parameters (including defaults) that can then be written as ruby in a config file.
5
+ It can also be used to add/override parameters from the command line (using optparse) or
6
+ even on the fly through an API. It comes with a handy utility that can generate a default
7
+ config file, with comments, from the defined config class and check existing config
8
+ files. It even creates a markdown file from the config class to make documentation easier.
9
+
10
+ Jeckyl can be used for simple parameters or complex structures with multiple calls. It provides
11
+ a single place to define and check all inputs so that you don't have to include any parameter
12
+ checking anywhere else in your code. Classes can be inherited to add further parameters, and
13
+ the config file generated by the jeckyl command is conveniently divided to reflect this. Config
14
+ files can also be merged so that multiple config files can be used (e.g. local/per-user/system).
10
15
 
11
16
  **GitHub:** [https://github.com/osburn-sharp/jeckyl](https://github.com/osburn-sharp/jeckyl)
12
17
 
@@ -22,11 +27,10 @@ Jeckyl comes as a gem. It can be installed in the usual way:
22
27
 
23
28
  gem install jeckyl
24
29
 
25
- That is all you need to do. Type 'jeckyl' to see usage and references to documentation.
30
+ That is practically all you need to do. Type 'jeckyl' to see usage and references to documentation.
31
+
32
+ Otherwise start coding your jeckyl config file.
26
33
 
27
- Jeckyl can be used to set the default location for the config files it processes. This will
28
- be '/etc/jeckyl' unless you set the environment varibale 'JECKYL_CONFIG_DIR' to something else.
29
- This could be done on a system-wide basis by include a file with this variable in /etc/env.d.
30
34
 
31
35
  ## Getting Started
32
36
 
@@ -221,18 +225,101 @@ use conf.complement(hash) ({Jeckyl::Config#complement}).
221
225
  For example, the Jellog logger defines a set of logging parameters in Jellog::Config. These may be inherited
222
226
  by another service that adds its own parameters (such as Jerbil):
223
227
 
224
- options = Jerbil::Config.new(my_conf)
228
+ all_options = Jerbil::Config.new(my_conf)
229
+
230
+ log_opts = Jellog::Config.intersection(all_options)
225
231
 
226
- log_opts = Jellog::Config.intersection(options)
232
+ jerb_opts = all_options.complement(log_opts)
227
233
 
228
- jerb_opts = options.complement(log_opts)
234
+ ### Command Line Options - Jeckyl with Optparse
235
+
236
+ Jeckyl can also process command line options using optparse. This can be easily done by adding an option
237
+ method call to your parameter method, which has the same parameters as optparse:
238
+
239
+ def configure_param_with_option(param)
240
+ option_set = [:none, :some, :all]
241
+ default :none
242
+ comment "Sets the option type to be one of",
243
+ " :none - no options",
244
+ " :some - some options",
245
+ " :all - all options"
246
+
247
+ describe "set the option type"
248
+ option "-o", "--option Type", option_set
249
+
250
+ a_member_of(param, option_set)
251
+ end
229
252
 
230
- ### Some Internal Methods
253
+ The {Jeckyl::Config#describe describe} method allows a short usage style description
254
+ over the longer config-file comment, and the {Jeckyl::Config#option} method receives
255
+ the same parameters as the optparse#on method less the description bit.
231
256
 
257
+ Adding this to your parameter method does not actually do anything without then parsing
258
+ the options:
259
+
260
+ # create a config hash
261
+ opts = MyConfig.new
262
+ # parse command-line options with the default ARGV
263
+ opts.optparse
264
+
265
+ The {Jeckyl::Config#optparse optparse} method creates and Optparse object with the
266
+ options defined in your parameter methods (ignoring those with no option set), adds
267
+ a '-c' option for specifying a config file and a -h option for help. It also parses
268
+ the results.
269
+
270
+ The {Jeckyl::Config#optparse optparse} method can also yield the real Optparse object
271
+ into a block where you can add further options unrelated to Jeckyl. The parse! is done
272
+ automatically when the block returns.
273
+
274
+ # parse them with some extra options added
275
+ opts.optparse do |opts|
276
+ # receives the same methods as an optparse object
277
+ opts.on('-p', '--pretend', 'Do not do anything for real') do
278
+ @pretend = true
279
+ end
280
+ end
281
+ # parse! is done automatically at the end of the block
282
+
283
+ This does two things: it updates the parameters with option statements from the command line
284
+ and it also adds the options in the block but independent of the config object itself.
285
+
286
+ A word about the -c option. This is really only added so that it is shown in the help
287
+ results. The option is not used by the optparse method for fairly obvious reasons: the
288
+ instance method is applied to a config hash so the config file has already been evaluated.
289
+ To use the -c option you need to preprocess the command line with a class method:
290
+
291
+ # set the default config file
292
+ default_config_file = '/etc/my_app/config_file.rb'
293
+ # get the config options, if it exists
294
+ argv, config_file = MyConfig.get_config_opt(ARGV,default_config_file)
295
+ # now use the config file
296
+ @config = MyConfig.new(argv, config_file)
297
+
298
+ Note that {Jeckyl::Config.get_config_opt} returns the inputs if there is no option. And
299
+ at this time it only looks for '-c', so the bit about '--config' is a lie!
300
+
301
+ ### Using Parameter methods on the fly
302
+
303
+ Jeckyl can also be used without a config file, for example as part of an API where the
304
+ inputs are coded in. A config class and parameter methods are defined as usual, including
305
+ defaults. On the inside of the API, where you might explicitly check inputs, you instead
306
+ call the parameter method:
307
+
308
+ # somewhere, a default config hash is created
309
+ @config = MyConfig.new
310
+
311
+ # later, this is used to check a parameter:
312
+ @param = @config.param_with_option(param)
313
+
314
+ # if the param does not match the config requirements then an exception is called
315
+
316
+ This allows you to blend in config files if required and command line options as well.
317
+ The only messy bit is that your API will raise {Jeckyl::ConfigError} unless you trap this and then
318
+ convert it to your own local exception.
232
319
 
233
320
  ### Jeckyl::Config < Hash
234
321
 
235
- Finally, note that Jeckyl::Config is itself a subclass of Hash, and therefore Jeckyl config objects inherit
322
+ Finally, note that {Jeckyl::Config} is itself a subclass of Hash, and therefore Jeckyl config objects inherit
236
323
  all hash methods as well!
237
324
 
238
325
  ## The 'jeckyl' Command
@@ -322,7 +409,7 @@ For example, a config file might contain:
322
409
  greeting "Hello"
323
410
 
324
411
  There is no greeting method, so method_missing is called instead. This remembers the name of the "missing" method (:greeting),
325
- calls configure_greeting and stores the results in the instances hash. The main reason for doing this (as opposed to just
412
+ calls configure_greeting and stores the results in the instance's hash. The main reason for doing this (as opposed to just
326
413
  calling the method 'greeting') is to enable the evaluation of defaults and comments in the context of each parameter method.
327
414
  All of this is private and therefore under the bonnet.
328
415
 
@@ -330,13 +417,13 @@ All of this is private and therefore under the bonnet.
330
417
 
331
418
  See the {file:Gemfile} for details of dependencies.
332
419
 
333
- Tested on Ruby 1.8.7.
420
+ Tested on Ruby 1.9.3_p547 and 2.0.0_p481 (Gentoo 2.1 not yet unmasked at time of
421
+ writing - Oct 2014). Tested with RSpec 3.1.0 - see below.
334
422
 
335
423
  ## Testing Jeckyl
336
424
 
337
- There is an rspec test file to test the whole thing (spec/jeckyl_spec.rb). It uses the test subclass in "../test" and
338
- various config files in "../conf.d". There is another rspec file that tests the config_check function.
339
-
425
+ There is an rspec test file to test the whole thing (spec/jeckyl_spec.rb). It uses the test subclass in the "test" directory and
426
+ various config files in the "test/conf.d" directory. There is another rspec file that tests the config_check function.
340
427
 
341
428
  ## Why did I bother?
342
429
 
@@ -346,6 +433,10 @@ issues. In looking for yet another alternative, I came across the approach used
346
433
  Unicorn (the backend web machine I now use for Rails apps). I liked the concept but
347
434
  thought it could be made more general, which resulted in Jeckyl.
348
435
 
436
+ The name Jeckyl is one of those silly acronyms that means nothing in particular:
437
+ Jumpin' Ermin's Configurator for Kwick and easY Linux services
438
+
439
+
349
440
  ## Bugs etc
350
441
 
351
442
  Details of bugs can be found in {file:Bugs.rdoc}
@@ -356,7 +447,7 @@ I am Robert Sharp and you can contact me on [GitHub](http://github.com/osburn-sh
356
447
 
357
448
  ## Copyright and Licence
358
449
 
359
- Copyright (c) 2011-2012 Robert Sharp.
450
+ Copyright (c) 2011-2014 Robert Sharp.
360
451
 
361
452
  See {file:LICENCE.rdoc LICENCE} for details of the licence under which Jeckyl is released.
362
453
 
data/bin/jeckyl CHANGED
@@ -13,7 +13,7 @@
13
13
  #
14
14
  #
15
15
 
16
- require 'rubygems'
16
+ #require 'rubygems' # not required in ruby 1.9.3 +
17
17
  require 'optplus'
18
18
 
19
19
  require 'jeckyl'
@@ -130,17 +130,20 @@ class JeckylCli < Optplus::Parser
130
130
  describe "klass", "generate a simple class template"
131
131
  def klass
132
132
  name = next_argument_or_error("missing class name")
133
+ names = name.split("::")
134
+ mod_name = names[0]
135
+ class_name = names[1] || 'Config'
133
136
  parent = next_argument_or('Jeckyl::Config')
134
137
  puts <<EOTXT
135
138
  # Simple framework for defining Jeckyl options to put into a config hash
136
139
 
137
- module #{name}
140
+ module #{mod_name}
138
141
 
139
142
  # configuration parameters for #{name}
140
143
  #
141
144
  # @see file:<PATH_TO_CONFIG_MARKDOWN_FILE> #{name} Parameter Descriptions
142
145
  #
143
- class Config < #{parent}
146
+ class #{class_name} < #{parent}
144
147
 
145
148
  def configure_a_parameter(val)
146
149
  default "default"
@@ -154,10 +157,14 @@ end
154
157
  EOTXT
155
158
 
156
159
  end
157
- help :klass, "Generate a simple class file as a template for defining your",
158
- "own parameters. You can also specify a class to inherit if you want to",
159
- "pick up additional parameters. Otherwise the parent will default to",
160
- "Jeckyl::Config. Alternatives include Jellog::Config and JerbilService::Config."
160
+ help :klass, " jeckyl klass <name> [<parent_class>}]",
161
+ "",
162
+ "Generate a simple class file as a template for defining your",
163
+ "own parameters. You can also specify a class to inherit if you want as",
164
+ "an additional parameter. Otherwise the parent will default to",
165
+ "Jeckyl::Config. Alternatives include Jellog::Config and JerbilService::Config.",
166
+ "Note the class name can be compound and will be split into module and class.",
167
+ "For example: 'Module::Class'."
161
168
 
162
169
 
163
170
  describe "check", "check the given config file is valid for the given class"
@@ -327,7 +327,7 @@ module Jeckyl
327
327
  # @param [Array] args which should usually be ARGV
328
328
  # @yield self and optparse object to allow incidental options to be added
329
329
  # @return false if --help so that the caller can decide what to do (e.g. exit)
330
- def optparse(args)
330
+ def optparse(args=ARGV)
331
331
 
332
332
  # ensure calls to parameter methods do not trample on things
333
333
  @_last_symbol = nil
@@ -345,13 +345,6 @@ module Jeckyl
345
345
 
346
346
  options << @_descriptions[param] if @_descriptions.has_key?(param)
347
347
 
348
- # opt_str = ''
349
- # options.each do |os|
350
- # opt_str << os.inspect
351
- # end
352
-
353
- # puts "#{param}: #{opt_str}"
354
-
355
348
  # get the method itself to call with the given arg
356
349
  pref_method = self.method("#{prefix}_#{param}".to_sym)
357
350
 
@@ -385,17 +378,19 @@ module Jeckyl
385
378
  def to_s(opts={})
386
379
  keys = self.keys.collect {|k| k.to_s}
387
380
  cols = 0
381
+ strs = Array.new
388
382
  keys.each {|k| cols = k.length if k.length > cols}
389
383
  keys.sort.each do |key_s|
390
- print ' '
391
- print key_s.ljust(cols)
384
+ str = ' '
385
+ str << key_s.ljust(cols)
392
386
  key = key_s.to_sym
393
387
  desc = @_descriptions[key]
394
388
  value = self[key].inspect
395
- print ": #{value}"
396
- print " (#{desc})" unless desc.nil?
397
- puts
389
+ str << ": #{value}"
390
+ str << " (#{desc})" unless desc.nil?
391
+ strs << str
398
392
  end
393
+ return strs.join("\n")
399
394
  end
400
395
 
401
396
 
@@ -1,14 +1,13 @@
1
1
  # Created by Jevoom
2
2
  #
3
- # 19-Sep-2013
4
- # Corrected some minor yard issues
5
- #
3
+ # 01-Oct-2014
4
+ # General tidy up of gem (README, rspec tests etc) to bring things up to date.
6
5
 
7
6
  module Jeckyl
8
- # version set to 0.3.7
9
- Version = '0.3.7'
10
- # date set to 19-Sep-2013
11
- Version_Date = '19-Sep-2013'
12
- #ident string set to: jeckyl-0.3.7 19-Sep-2013
13
- Ident = 'jeckyl-0.3.7 19-Sep-2013'
7
+ # version set to 0.4.0
8
+ Version = '0.4.0'
9
+ # date set to 01-Oct-2014
10
+ Version_Date = '01-Oct-2014'
11
+ #ident string set to: jeckyl-0.4.0 01-Oct-2014
12
+ Ident = 'jeckyl-0.4.0 01-Oct-2014'
14
13
  end
@@ -12,45 +12,45 @@ describe "Jeckyl Config Checker" do
12
12
  # general tests
13
13
 
14
14
  it "should checkout a simple config" do
15
- conf_file = conf_path + '/jeckyl'
16
- rep_file = report_path + '/ok.txt'
15
+ conf_file = File.join conf_path, 'jeckyl'
16
+ rep_file = File.join report_path,'ok.txt'
17
17
  conf_ok = TestJeckyl.check_config(conf_file, rep_file)
18
- conf_ok.should be_true
18
+ conf_ok.should be true
19
19
  message = File.read(rep_file).chomp
20
20
  message.should == "No errors found in: #{conf_file}"
21
21
  end
22
22
 
23
23
 
24
24
  it "should complain if the config file does not exist" do
25
- conf_file = conf_path + "/never/likely/to/be/there"
26
- rep_file = report_path + '/not_ok.txt'
25
+ conf_file = File.join conf_path, 'never', 'likely', 'to', 'be', 'there'
26
+ rep_file = File.join report_path, 'not_ok.txt'
27
27
  conf_ok = TestJeckyl.check_config(conf_file, rep_file)
28
- conf_ok.should be_false
28
+ conf_ok.should be false
29
29
  message = File.read(rep_file).chomp
30
30
  message.should == "No such config file: #{conf_file}"
31
31
  end
32
32
 
33
33
  it "should return false if the config file has a syntax error" do
34
- conf_file = conf_path + "/syntax_error"
35
- rep_file = report_path + '/not_ok.txt'
34
+ conf_file = File.join conf_path, "syntax_error"
35
+ rep_file = File.join report_path, 'not_ok.txt'
36
36
  conf_ok = TestJeckyl.check_config(conf_file, rep_file)
37
- conf_ok.should be_false
37
+ conf_ok.should be false
38
38
  message = File.read(rep_file).chomp
39
- message.should match(/^compile error/)
39
+ message.should match(/^#{conf_file}:\d+: unterminated/)
40
40
  end
41
41
 
42
42
  it "should return false if the config file has an error" do
43
- conf_file = conf_path + "/not_a_bool"
44
- rep_file = report_path + '/not_ok.txt'
43
+ conf_file = File.join conf_path, "not_a_bool"
44
+ rep_file = File.join report_path, 'not_ok.txt'
45
45
  conf_ok = TestJeckyl.check_config(conf_file, rep_file)
46
- conf_ok.should be_false
46
+ conf_ok.should be false
47
47
  message = File.read(rep_file).chomp
48
48
  message.should match(/^\[debug\]:/)
49
49
  end
50
50
 
51
51
  it "should fail if it cannot write to the report file" do
52
- conf_file = conf_path + "/jeckyl"
53
- rep_file = report_path + '/no_such_directory/ok.txt'
52
+ conf_file = File.join conf_path, "jeckyl"
53
+ rep_file = File.join report_path, 'no_such_directory', 'ok.txt'
54
54
  lambda{conf_ok = TestJeckyl.check_config(conf_file, rep_file)}.should raise_error(Jeckyl::ReportFileError)
55
55
  end
56
56
 
@@ -29,7 +29,7 @@ describe "Jeckyl" do
29
29
  conf[:log_level].should == :verbose
30
30
  conf[:log_rotation].should == 5
31
31
  conf[:email].should == "robert@osburn-sharp.ath.cx"
32
- conf.has_key?(:sieve).should be_true
32
+ conf.has_key?(:sieve).should be true
33
33
  conf[:config_files].length.should == 1
34
34
  conf[:option_set][:peter].should == 37
35
35
  conf[:offset].should == 134
@@ -185,12 +185,12 @@ describe "Jeckyl" do
185
185
  opts.length.should == 4
186
186
  subopts = Aclass.intersection(opts)
187
187
  subopts.length.should ==2
188
- subopts.has_key?(:a_bool).should be_true
189
- subopts.has_key?(:no_def).should be_true
188
+ subopts.has_key?(:a_bool).should be true
189
+ subopts.has_key?(:no_def).should be true
190
190
  opts.complement(subopts)
191
191
  opts.length.should == 2
192
- opts.has_key?(:config_files).should be_true
193
- opts.has_key?(:another).should be_true
192
+ opts.has_key?(:config_files).should be true
193
+ opts.has_key?(:another).should be true
194
194
  end
195
195
  end
196
196
 
@@ -2,10 +2,12 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
2
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
3
  require 'jeckyl'
4
4
  require 'rspec'
5
- require 'rspec/autorun'
6
5
 
7
6
  RSpec.configure do |config|
8
- config.color_enabled = true
7
+ config.color = true
9
8
  config.formatter = :doc
10
-
9
+ # using older shoulds for the time being
10
+ config.expect_with :rspec do |c|
11
+ c.syntax = :should # disables `expect` and deprecation warnings
12
+ end
11
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jeckyl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.7
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Robert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-19 00:00:00.000000000 Z
11
+ date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: !binary |-
@@ -121,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  version: '0'
122
122
  requirements: []
123
123
  rubyforge_project:
124
- rubygems_version: 2.0.7
124
+ rubygems_version: 2.0.14
125
125
  signing_key:
126
126
  specification_version: 4
127
127
  summary: Create and manage configuration files in Ruby for Ruby.