confoog 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4336bba436a680049e0f664d3160f0be3089664
4
- data.tar.gz: 026279c492238be89eba517417e884e9dc992109
3
+ metadata.gz: 426cd876ac4934a3f852d3bd3a488d5eb67e2457
4
+ data.tar.gz: 49c365ae6ef73ba9dc8beac001aa2f08d5cd01b1
5
5
  SHA512:
6
- metadata.gz: d961c0d7fd8e277ff37a903d5cda39e229aa46bdaa2bb3eddb8f5dfee833c09a7aaf2001d2796fa070c9ed168bdc7df22824e4d1253fb1ab47f4f10afa7fd689
7
- data.tar.gz: af619574ceedd1841ee0ce75665344ff959613068b6286ada339695d31df2562a67230700558bc472b80aec36cf6b67a88e006ce663742ac99184bfcca01ad2c
6
+ metadata.gz: 1eeeced36fe38ce14adc23bc85a4502b1f2a7296b32fad3741b585d310ec7a4a830c5b592ca7a49e3b47bc9154fb83b6ba4f1cd16373b9965cf57a797bee7527
7
+ data.tar.gz: a9a1993322fb9f67db21274371a97aed463d0deab4d7e506d9c5e9e1d406b26c82882d71b0405bb1d5ca0f5d381d4fe051daf8736bba266e6e1b49991c9ca9fc
data/README.md CHANGED
@@ -31,6 +31,8 @@ Or install it yourself as:
31
31
  ## Usage
32
32
  Currently Confoog will not allow 'nested' configuration types, however each variable can be an array or hash so multiple settings can be recorded for each variable and accessed (for a hash) by `settings[variable][hash_key]` or array using `settings[array].each`. In other words, treat the return from `settings[var]` as the type it contains. See examples below.
33
33
 
34
+ By default, each time a configuration variable is created or changed the file on disk will be updated with this addition or change. If you intend to make a lot of consecutive changes or do not want the small performance hit of this, pass `autosave: false` as a parameter to #new, or set it false using the #autosave accessor.
35
+
34
36
  ```ruby
35
37
  require 'confoog'
36
38
 
@@ -57,6 +59,10 @@ settings[50]
57
59
  settings[50][:two]
58
60
  # => "for the show"
59
61
 
62
+ settings.quiet = true # squelch any error or status messages to console
63
+
64
+ settings.autosave = false # disable autosave if it has been enabled with #new or #autosave
65
+
60
66
  settings.save # save all current parameters to the YAML file
61
67
 
62
68
  settings.load # load the settings from YAML file.
@@ -81,9 +87,12 @@ prefix: 'My Application'
81
87
  quiet: true | false
82
88
 
83
89
  # Should we automatically load the configuration file when the class is created?
84
- auto_load: true | false
90
+ autoload: true | false
91
+
92
+ # Should we automatically save the configuration file when a variable is created or changed?
93
+ autosave: true | false
85
94
  ```
86
- If these are not specified, Confoog will use the following defaults :
95
+ If any of these are not specified, Confoog will use the following defaults :
87
96
 
88
97
  ```ruby
89
98
  location: '~/'
@@ -91,7 +100,8 @@ filename: '.confoog'
91
100
  create_file: false
92
101
  prefix: 'Configuration'
93
102
  quiet: false
94
- auto_load: false
103
+ autoload: false
104
+ autosave: true
95
105
  ```
96
106
 
97
107
  Confoog will set the following error constants which will be returned in the `.status['errors']` variable as needed :
@@ -117,7 +127,6 @@ Thoughts in no particular order.
117
127
 
118
128
  - Restrict configuration variables to a specified subset, or to only those that already exist in the YAML file.
119
129
  - A better way of dealing with multi-level variables - i.e. nested arrays, hashes etc.
120
- - option to save config file after any config variables are changed, not just explicitly with `Confoog::Settings.save`
121
130
 
122
131
  ## Development
123
132
 
data/Rakefile CHANGED
@@ -9,8 +9,7 @@ RuboCop::RakeTask.new do |task|
9
9
  task.options << 'lib'
10
10
  end
11
11
  Inch::Rake::Suggest.new do |suggest|
12
- suggest.args << "--pedantic"
12
+ suggest.args << '--pedantic'
13
13
  end
14
14
 
15
-
16
15
  task default: [:rubocop, :inch, :spec]
@@ -0,0 +1,10 @@
1
+ # A collection of utility functions for the Confoog class
2
+ module ConfoogUtils
3
+ private
4
+
5
+ # Display output to the console with the severity noted, unless we are quiet.
6
+ def console_output(message, severity)
7
+ return unless @options[:quiet] == false
8
+ $stderr.puts "#{@options[:prefix]} : #{severity} - #{message}"
9
+ end
10
+ end
@@ -2,5 +2,5 @@
2
2
  module Confoog
3
3
  # Version of this Gem, using Semantic Versioning 2.0.0
4
4
  # http://semver.org/
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
data/lib/confoog.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'confoog/version'
2
+ require 'confoog/utility'
2
3
  require 'yaml'
3
4
 
4
5
  # rubocop:disable LineLength
@@ -47,7 +48,8 @@ module Confoog
47
48
  prefix: 'Configuration',
48
49
  location: '~/',
49
50
  filename: DEFAULT_CONFIG,
50
- auto_load: false
51
+ autoload: false,
52
+ autosave: true
51
53
  }
52
54
 
53
55
  # Provide an encapsulated class to access a YAML configuration file.
@@ -82,6 +84,7 @@ module Confoog
82
84
  # settings[50][:two]
83
85
  # # => "for the show"
84
86
  class Settings
87
+ include ConfoogUtils
85
88
  attr_reader :filename, :location, :status
86
89
 
87
90
  # rubocop:enable LineLength
@@ -109,7 +112,27 @@ module Confoog
109
112
  check_exists(options)
110
113
 
111
114
  # if auto_load is true, automatically load from file
112
- load unless @options[:auto_load] == false
115
+ load unless @options[:autoload] == false
116
+ end
117
+
118
+ # Return the value of the 'auto_save' option.
119
+ # @example
120
+ # autosave_status = settings.autosave
121
+ # => true
122
+ # @param [None]
123
+ # @return [Boolen] true if we are autosaving on change or addition.
124
+ def autosave
125
+ @options[:autosave]
126
+ end
127
+
128
+ # Change the 'auto_save' option.
129
+ # @example
130
+ # settings.autosave = false
131
+ # => false
132
+ # @return [Boolean] The new value [true | false]
133
+ # @param autosave [Boolean] True to send messages to console for errors.
134
+ def autosave=(autosave)
135
+ @options[:autosave] = autosave
113
136
  end
114
137
 
115
138
  # Return the value of the 'quiet' option.
@@ -189,13 +212,16 @@ module Confoog
189
212
  @config[key]
190
213
  end
191
214
 
192
- # Set a configuration key
215
+ # Set a configuration key.
216
+ # If auto_save: true then will also update the config file (default is true)
193
217
  # @example
194
218
  # settings[:key] = "Value"
195
219
  # settings[:array] = ["first", "second", "third"]
196
220
  # @return [<various>] Returns the variable that was assigned.
197
221
  def []=(key, value)
198
222
  @config[key] = value
223
+ # automatically save to file if this has been requested.
224
+ save unless @options[:autosave] == false
199
225
  end
200
226
 
201
227
  # Returns the fully qualified path to the configuration file in use.
@@ -208,11 +234,6 @@ module Confoog
208
234
 
209
235
  private
210
236
 
211
- def console_output(message, severity)
212
- return unless @options[:quiet] == false
213
- $stderr.puts "#{@options[:prefix]} : #{severity} - #{message}"
214
- end
215
-
216
237
  def save_to_yaml
217
238
  file = File.open(config_path, 'w')
218
239
  file.write(@config.to_yaml)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confoog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seapagan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-07 00:00:00.000000000 Z
11
+ date: 2015-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -154,6 +154,7 @@ files:
154
154
  - bin/setup
155
155
  - confoog.gemspec
156
156
  - lib/confoog.rb
157
+ - lib/confoog/utility.rb
157
158
  - lib/confoog/version.rb
158
159
  homepage: https://github.com/seapagan/confoog
159
160
  licenses: