confoog 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.pullreview.yml +4 -0
- data/README.md +6 -6
- data/Rakefile +9 -1
- data/confoog.gemspec +2 -0
- data/lib/confoog.rb +6 -27
- data/lib/confoog/status.rb +33 -24
- data/lib/confoog/version.rb +1 -2
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9422eaf268b310c4933473e850ae17b7cb2af2fe
|
4
|
+
data.tar.gz: f19cf7d265b7d48023c3246c3ff33e9c25c7e4d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95a01b11a275022152f9de1b8cd0b1711f3fcfd78db7b21a96e77af83a32e705bacb12c0f10cd0d3c79b2ddccebfb573b6da8fb9b4eb735955064089de40292a
|
7
|
+
data.tar.gz: 455181a8fc2b81bff5ab62a7dbad00c10e72141b3c28e13d67fe8520d6aefad5c1c19b62c45fd99b3d36c48ded2e0bae165f7d4e42ffc60a3b9e3ca63cb2fa7c
|
data/.pullreview.yml
ADDED
data/README.md
CHANGED
@@ -110,12 +110,11 @@ Confoog will set the following error constants which will be returned in the `.s
|
|
110
110
|
```ruby
|
111
111
|
ERR_NO_ERROR = 0 # no error condition, command was succesfull
|
112
112
|
ERR_FILE_NOT_EXIST = 1 # specified configuration file does not exist
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
ERR_CANT_LOAD = 64 # Cannot load configuration data from file.
|
113
|
+
ERR_CANT_CREATE_FILE = 2 # cannot create the requested configuration file
|
114
|
+
ERR_NOT_WRITING_EMPTY_FILE = 4 # not attempting to save an empty configuration
|
115
|
+
ERR_CANT_SAVE_CONFIGURATION = 8 # Failed to save the configuration file
|
116
|
+
ERR_NOT_LOADING_EMPTY_FILE = 16 # not atempting to load an empty config file
|
117
|
+
ERR_CANT_LOAD = 32 # Cannot load configuration data from file.
|
119
118
|
|
120
119
|
INFO_FILE_CREATED = 256 # Information - specified file was created
|
121
120
|
INFO_FILE_LOADED = 512 # Information - Config file was loaded successfully
|
@@ -129,6 +128,7 @@ Thoughts in no particular order.
|
|
129
128
|
|
130
129
|
- Restrict configuration variables to a specified subset, or to only those that already exist in the YAML file.
|
131
130
|
- A better way of dealing with multi-level variables - i.e. nested arrays, hashes etc.
|
131
|
+
- Write standalone tests for the 'Status' class - right now it is tested at 100% by the application tests though would probably be good to have dedicated tests too
|
132
132
|
|
133
133
|
## Development
|
134
134
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
2
|
require 'rspec/core/rake_task'
|
3
3
|
require 'rubocop/rake_task'
|
4
|
+
require 'reek/rake/task'
|
4
5
|
require 'inch/rake'
|
5
6
|
|
6
7
|
RSpec::Core::RakeTask.new(:spec)
|
@@ -8,8 +9,15 @@ RSpec::Core::RakeTask.new(:spec)
|
|
8
9
|
RuboCop::RakeTask.new do |task|
|
9
10
|
task.options << 'lib'
|
10
11
|
end
|
12
|
+
|
11
13
|
Inch::Rake::Suggest.new do |suggest|
|
12
14
|
suggest.args << '--pedantic'
|
13
15
|
end
|
14
16
|
|
15
|
-
|
17
|
+
Reek::Rake::Task.new do |t|
|
18
|
+
t.fail_on_error = false
|
19
|
+
t.verbose = true
|
20
|
+
t.reek_opts = '-U'
|
21
|
+
end
|
22
|
+
|
23
|
+
task default: [:rubocop, :inch, :reek, :spec]
|
data/confoog.gemspec
CHANGED
@@ -30,4 +30,6 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.add_development_dependency 'rubocop'
|
31
31
|
spec.add_development_dependency 'inch'
|
32
32
|
spec.add_development_dependency 'simplecov', '~> 0.10'
|
33
|
+
spec.add_development_dependency 'pullreview-coverage'
|
34
|
+
spec.add_development_dependency 'reek', '~> 3.3'
|
33
35
|
end
|
data/lib/confoog.rb
CHANGED
@@ -22,10 +22,6 @@ module Confoog
|
|
22
22
|
}
|
23
23
|
|
24
24
|
# Provide an encapsulated class to access a YAML configuration file.
|
25
|
-
# @!attribute [r] filename
|
26
|
-
# @return [String] The configuration filename in use.
|
27
|
-
# @!attribute [r] location
|
28
|
-
# @return [String] The directory storing the configuration file.
|
29
25
|
# @!attribute [r] status
|
30
26
|
# @return [Hash] A hash containing status variables.
|
31
27
|
# @example
|
@@ -53,7 +49,7 @@ module Confoog
|
|
53
49
|
# settings[50][:two]
|
54
50
|
# # => "for the show"
|
55
51
|
class Settings
|
56
|
-
attr_reader :
|
52
|
+
attr_reader :status
|
57
53
|
|
58
54
|
# rubocop:enable LineLength
|
59
55
|
|
@@ -69,13 +65,12 @@ module Confoog
|
|
69
65
|
|
70
66
|
# Hash containing any error or return from methods
|
71
67
|
@status = Status.new(@options[:quiet], @options[:prefix])
|
72
|
-
|
73
|
-
@
|
68
|
+
# clear the error condition as default.
|
69
|
+
@status.clear_error
|
74
70
|
|
71
|
+
# Initialize the Configuration to and empty hash.
|
75
72
|
@config = {}
|
76
73
|
|
77
|
-
# clear the error condition as default.
|
78
|
-
@status.clear_error
|
79
74
|
# make sure the file exists or can be created...
|
80
75
|
check_exists(options)
|
81
76
|
|
@@ -149,20 +144,6 @@ module Confoog
|
|
149
144
|
@status.set(errors: Status::ERR_CANT_LOAD)
|
150
145
|
end
|
151
146
|
|
152
|
-
# dummy method currently to stop changing location by caller once created,
|
153
|
-
# @return [hash] an error flag in the ':status' variable.
|
154
|
-
# @param [Optional] Parameter is ignored
|
155
|
-
def location=(*)
|
156
|
-
@status.set(errors: Status::ERR_CANT_CHANGE)
|
157
|
-
end
|
158
|
-
|
159
|
-
# dummy method currently to stop changing filename by caller once created,
|
160
|
-
# @return [hash] an error flag in the ':status' variable.
|
161
|
-
# @param optional Parameter is ignored
|
162
|
-
def filename=(*)
|
163
|
-
@status.set(errors: Status::ERR_CANT_CHANGE)
|
164
|
-
end
|
165
|
-
|
166
147
|
# Read the configuration key (key)
|
167
148
|
# @example
|
168
149
|
# key = settings[:key]
|
@@ -188,7 +169,7 @@ module Confoog
|
|
188
169
|
# path = config_path
|
189
170
|
# @return [String] Full path and filename of the configuration file.
|
190
171
|
def config_path
|
191
|
-
File.expand_path(File.join(@location, @filename))
|
172
|
+
File.expand_path(File.join(@options[:location], @options[:filename]))
|
192
173
|
end
|
193
174
|
|
194
175
|
private
|
@@ -198,9 +179,7 @@ module Confoog
|
|
198
179
|
@status.set(config_exists: false, errors: Status::ERR_FILE_NOT_EXIST)
|
199
180
|
return
|
200
181
|
end
|
201
|
-
|
202
|
-
file.write(@config.to_yaml)
|
203
|
-
file.close
|
182
|
+
File.open(config_path, 'w') { |file| file.write(@config.to_yaml) }
|
204
183
|
rescue
|
205
184
|
@status.set(errors: Status::ERR_CANT_SAVE_CONFIGURATION)
|
206
185
|
end
|
data/lib/confoog/status.rb
CHANGED
@@ -1,27 +1,19 @@
|
|
1
1
|
# Provide error messages and console output when required.
|
2
2
|
class Status
|
3
|
-
# @!attribute prefix
|
4
|
-
# @return [String] String to pre-pend on any error put to console
|
5
|
-
attr_accessor :prefix
|
6
|
-
# @!attribute quiet
|
7
|
-
# @return [Boolean] Do we output anything to console or not
|
8
|
-
attr_accessor :quiet
|
9
3
|
# No error condition exists
|
10
4
|
ERR_NO_ERROR = 0
|
11
5
|
# The specified file does not exist
|
12
6
|
ERR_FILE_NOT_EXIST = 1
|
13
|
-
# You cannot change location or filename after class is instantiated
|
14
|
-
ERR_CANT_CHANGE = 2
|
15
7
|
# Was unable to create the specified file
|
16
|
-
ERR_CANT_CREATE_FILE =
|
8
|
+
ERR_CANT_CREATE_FILE = 2
|
17
9
|
# There are no configuration variables set, so not writing empty file
|
18
|
-
ERR_NOT_WRITING_EMPTY_FILE =
|
10
|
+
ERR_NOT_WRITING_EMPTY_FILE = 4
|
19
11
|
# Cannot save to the specified file for some reason
|
20
|
-
ERR_CANT_SAVE_CONFIGURATION =
|
12
|
+
ERR_CANT_SAVE_CONFIGURATION = 8
|
21
13
|
# The specified file is empty so not trying to load settings from it
|
22
|
-
ERR_NOT_LOADING_EMPTY_FILE =
|
14
|
+
ERR_NOT_LOADING_EMPTY_FILE = 16
|
23
15
|
# Cannot load the specified file for some reason.
|
24
|
-
ERR_CANT_LOAD =
|
16
|
+
ERR_CANT_LOAD = 32
|
25
17
|
|
26
18
|
# Information - file was created successfully
|
27
19
|
INFO_FILE_CREATED = 256
|
@@ -39,7 +31,6 @@ class Status
|
|
39
31
|
# not have a message, there will be no output.
|
40
32
|
ERROR_STRINGS = {
|
41
33
|
ERR_FILE_NOT_EXIST => 'The specified Configuration file does not exist.',
|
42
|
-
ERR_CANT_CHANGE => 'Cannot change filename after creation',
|
43
34
|
ERR_CANT_CREATE_FILE => 'Cannot create the specified Configuration file!',
|
44
35
|
ERR_NOT_WRITING_EMPTY_FILE => 'Not saving empty configuration data!',
|
45
36
|
ERR_CANT_SAVE_CONFIGURATION => 'Cannot save configuration data!',
|
@@ -56,8 +47,24 @@ class Status
|
|
56
47
|
# Initialize the status container to an empty hash. Will return nil
|
57
48
|
# for missing keys by default.
|
58
49
|
@status = {}
|
59
|
-
|
60
|
-
@
|
50
|
+
# ititialize a hash to store our own internal options.
|
51
|
+
@options = {}
|
52
|
+
# and fill it.
|
53
|
+
@options[:quiet] = quiet
|
54
|
+
@options[:prefix] = prefix
|
55
|
+
end
|
56
|
+
|
57
|
+
# Set whether we output to the console or not
|
58
|
+
# @param quiet [Boolean] True to output Errors to the console.
|
59
|
+
# @return [Boolean] Value of #quiet
|
60
|
+
def quiet=(quiet)
|
61
|
+
@options[:quiet] = quiet
|
62
|
+
end
|
63
|
+
|
64
|
+
# return the current 'quiet' status
|
65
|
+
# @return [Boolean] Value of #quiet
|
66
|
+
def quiet
|
67
|
+
@options[:quiet]
|
61
68
|
end
|
62
69
|
|
63
70
|
# Clear the error status.
|
@@ -94,20 +101,22 @@ class Status
|
|
94
101
|
# @param status [Hash] one or more hash-pairs of status information.
|
95
102
|
# @return Unspecified
|
96
103
|
def set(status)
|
97
|
-
status.each
|
98
|
-
|
99
|
-
|
100
|
-
return if ERROR_STRINGS[@status[:errors]].nil?
|
101
|
-
severity = (@status[:errors] <= 64) ? 'Error' : 'Info'
|
102
|
-
console_output(ERROR_STRINGS[@status[:errors]], severity)
|
104
|
+
status.each { |key, value| @status[key] = value }
|
105
|
+
return unless error_string
|
106
|
+
console_output(error_string, (@status[:errors] < 256) ? 'Error' : 'Info')
|
103
107
|
end
|
104
108
|
|
105
109
|
private
|
106
110
|
|
111
|
+
# return the error string corresponding to the current error number
|
112
|
+
def error_string
|
113
|
+
ERROR_STRINGS[@status[:errors]]
|
114
|
+
end
|
115
|
+
|
107
116
|
# Display output to the console with the severity noted, unless we are quiet.
|
108
117
|
# @param [String] message
|
109
118
|
def console_output(message, severity)
|
110
|
-
return unless @quiet == false
|
111
|
-
$stderr.puts "#{@prefix} : #{severity} - #{message}"
|
119
|
+
return unless @options[:quiet] == false
|
120
|
+
$stderr.puts "#{@options[:prefix]} : #{severity} - #{message}"
|
112
121
|
end
|
113
122
|
end
|
data/lib/confoog/version.rb
CHANGED
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.4.
|
4
|
+
version: 0.4.3
|
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-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,6 +136,34 @@ dependencies:
|
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0.10'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: pullreview-coverage
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: reek
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.3'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.3'
|
139
167
|
description: A simple Gem to add YAML configuration files to your Ruby script or Gem
|
140
168
|
email:
|
141
169
|
- seapagan@gmail.com
|
@@ -144,6 +172,7 @@ extensions: []
|
|
144
172
|
extra_rdoc_files: []
|
145
173
|
files:
|
146
174
|
- ".gitignore"
|
175
|
+
- ".pullreview.yml"
|
147
176
|
- ".rspec"
|
148
177
|
- ".travis.yml"
|
149
178
|
- Gemfile
|