confoog 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e8c834375260522e7bab9907771a55351d43bd29
4
- data.tar.gz: cac8eac230a60636d17a09faf7a3660287b4c084
3
+ metadata.gz: 67eda83fbbfd733612d64817a500c788eed105ad
4
+ data.tar.gz: 5e7f0886f7c014be9522d42dbd451b00ee605420
5
5
  SHA512:
6
- metadata.gz: 47213e291d3f7d01c5cbbac6aeecea1713ff1d1cdac181e11b02cb2f6fdfb30114d4dbaa1ef0017397be6c14ea229ea114cc32d7befeffeddd65b5f412538832
7
- data.tar.gz: 1dadeddcba9c34932aa45636e3e62025d1cff59225fa84e17336adbd7125f08a3cb6b6e79c768c5f7bf32b7742bfa3cb0c7806056891f212b9e0ebdaa1072b08
6
+ metadata.gz: 905bae34ff999f4ebe7d81bb41e0bc758ea1266eddc8162dba47e424fe4d233a640ebe8d26cf7ca8c3f2fcdb47c02d33b627db236478a7624d6486db6869588a
7
+ data.tar.gz: f9067c187fb8b99f234c3d7fbbcee109e62185c62e638564b833a80750fc756fe1ef493e11397ef75dd282410db366077f7cf3eaf8823371048a2ee23ec276d8
data/Rakefile CHANGED
@@ -1,10 +1,16 @@
1
1
  require 'bundler/gem_tasks'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'rubocop/rake_task'
4
+ require 'inch/rake'
4
5
 
5
6
  RSpec::Core::RakeTask.new(:spec)
7
+
6
8
  RuboCop::RakeTask.new do |task|
7
9
  task.options << 'lib'
8
10
  end
11
+ Inch::Rake::Suggest.new do |suggest|
12
+ suggest.args << "--pedantic"
13
+ end
14
+
9
15
 
10
- task default: [:rubocop, :spec]
16
+ task default: [:rubocop, :inch, :spec]
data/confoog.gemspec CHANGED
@@ -28,4 +28,5 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'fakefs'
29
29
  spec.add_development_dependency 'coveralls'
30
30
  spec.add_development_dependency 'rubocop'
31
+ spec.add_development_dependency 'inch'
31
32
  end
@@ -1,4 +1,6 @@
1
1
  # Define the Gem version string
2
2
  module Confoog
3
- VERSION = '0.1.4'
3
+ # Version of this Gem, using Semantic Versioning 2.0.0
4
+ # http://semver.org/
5
+ VERSION = '0.2.0'
4
6
  end
data/lib/confoog.rb CHANGED
@@ -1,30 +1,46 @@
1
1
  require 'confoog/version'
2
2
  require 'yaml'
3
3
 
4
+ # rubocop:disable LineLength
5
+
4
6
  # Overall module.
5
7
  # Contains Class Confoog::Settings
6
8
  module Confoog
9
+ # The default filename used if none specified when created.
7
10
  DEFAULT_CONFIG = '.confoog'
8
11
 
9
12
  # Error messages to be returned
13
+
14
+ # No error condition exists
10
15
  ERR_NO_ERROR = 0
16
+ # The specified file does not exist
11
17
  ERR_FILE_NOT_EXIST = 1
18
+ # You cannot change location or filename after class is instantiated
12
19
  ERR_CANT_CHANGE = 2
20
+ # Was unable to create the specified file
13
21
  ERR_CANT_CREATE_FILE = 4
22
+ # There are no configuration variables set, so not writing empty file
14
23
  ERR_NOT_WRITING_EMPTY_FILE = 8
24
+ # Cannot save to the specified file for some reason
15
25
  ERR_CANT_SAVE_CONFIGURATION = 16
26
+ # The specified file is empty so not trying to load settings from it
16
27
  ERR_NOT_LOADING_EMPTY_FILE = 32
17
28
 
18
29
  # Info messages to be returned
30
+
31
+ # Information - file was created successfully
19
32
  INFO_FILE_CREATED = 256
33
+ # Information - configuration was successfully loaded
20
34
  INFO_FILE_LOADED = 512
21
35
 
36
+ # Hash containing text versions of the assorted error severity.
22
37
  OUTPUT_SEVERITY = {
23
38
  ERR: 'Error',
24
39
  WARN: 'Warning',
25
40
  INFO: 'Information'
26
41
  }
27
42
 
43
+ # Hash containing default values of initialization variables
28
44
  DEFAULT_OPTIONS = {
29
45
  create_file: false,
30
46
  quiet: false,
@@ -33,21 +49,53 @@ module Confoog
33
49
  filename: DEFAULT_CONFIG
34
50
  }
35
51
 
36
- # Class : Settings.
37
52
  # Provide an encapsulated class to access a YAML configuration file.
38
- # Readers :
39
- # .filename = read the config filename for this instance
40
- # .location = read the config directory for this instance
41
- # .status = Hash containing assorted status variables, read only.
53
+ # @!attribute [r] filename
54
+ # @return [String] The configuration filename in use.
55
+ # @!attribute [r] location
56
+ # @return [String] The directory storing the configuration file.
57
+ # @!attribute [r] status
58
+ # @return [Hash] A hash containing status variables.
59
+ # @example
60
+ # require 'confoog'
61
+ # settings = Confoog::Settings.new
62
+ # settings[:var] = value
63
+ # settings[:array] = [1, 2, 3, 4]
64
+ # settings[42] = "Meaning of life"
65
+ # settings[:urls] = ["https://www.mywebsite.com", "https://www.anothersite.com/a/page.html"]
66
+ #
67
+ # settings[:urls].each do |url|
68
+ # puts url
69
+ # end
70
+ # # https://www.mywebsite.com
71
+ # # https://www.anothersite.com/a/page.html
72
+ # # => ["https://www.mywebsite.com", "https://www.anothersite.com/a/page.html"]
73
+ #
74
+ # settings[:dont_exist]
75
+ # # => nil
76
+ #
77
+ # a_variable = 50
78
+ # settings[a_variable] = {:one => "for the money", :two => "for the show", :three => "to get ready"}
79
+ # settings[50]
80
+ # # => {:one => "for the money", :two => "for the show", :three => "to get ready"}
81
+ # settings[50][:two]
82
+ # # => "for the show"
42
83
  class Settings
43
84
  attr_reader :filename, :location, :status
44
85
 
86
+ # rubocop:enable LineLength
87
+
88
+ # Setup the class with specified parameters or default values if any or all
89
+ # are absent.
90
+ # All parameters are optional.
91
+ # @param options [Hash] Hash value containing any passed parameters.
45
92
  def initialize(options = {})
46
93
  # merge default options to avoid ambiguity
47
94
  @options = DEFAULT_OPTIONS.merge(options)
48
95
  # set all other unset options to return false instead of Nul.
49
96
  @options.default = false
50
97
 
98
+ # Hash containing any error or return from methods
51
99
  @status = {}
52
100
  @location = @options[:location]
53
101
  @filename = @options[:filename]
@@ -60,14 +108,29 @@ module Confoog
60
108
  check_exists(options)
61
109
  end
62
110
 
111
+ # Return the value of the 'quiet' option.
112
+ # @example
113
+ # is_quiet = settings.quiet
114
+ # @param [None]
115
+ # @return [Boolean] True if we are not writing to the console on error
63
116
  def quiet
64
117
  @options[:quiet]
65
118
  end
66
119
 
120
+ # Change the 'quiet' option.
121
+ # @example
122
+ # settings.quiet = true
123
+ # @return [Boolean] The new value [true | false]
124
+ # @param quiet [Boolean] True to send messages to console for errors.
67
125
  def quiet=(quiet)
68
126
  @options[:quiet] = quiet
69
127
  end
70
128
 
129
+ # Save the entire configuration (@config) to the YAML file.
130
+ # @example
131
+ # settings.save
132
+ # @param [None]
133
+ # @return Unspecified
71
134
  def save
72
135
  if @config.count > 0
73
136
  save_to_yaml
@@ -78,6 +141,11 @@ module Confoog
78
141
  end
79
142
  end
80
143
 
144
+ # Populate the configuration (@config) from the YAML file.
145
+ # @param [None]
146
+ # @example
147
+ # settings.load
148
+ # @return Unspecified
81
149
  def load
82
150
  @config = YAML.load_file(config_path)
83
151
  status_set(errors: INFO_FILE_LOADED)
@@ -91,32 +159,45 @@ module Confoog
91
159
  OUTPUT_SEVERITY[:ERR])
92
160
  end
93
161
 
162
+ # dummy method currently to stop changing location by caller once created,
163
+ # @return [hash] an error flag in the ':status' variable.
164
+ # @param [Optional] Parameter is ignored
94
165
  def location=(*)
95
- # dummy method currently to stop changing location by caller once created,
96
- # but not raise error.
97
- # - Return an error flag in the ':status' variable.
98
166
  status_set(errors: ERR_CANT_CHANGE)
99
167
  console_output('Cannot change file location after creation',
100
168
  OUTPUT_SEVERITY[:WARN])
101
169
  end
102
170
 
171
+ # dummy method currently to stop changing filename by caller once created,
172
+ # @return [hash] an error flag in the ':status' variable.
173
+ # @param optional Parameter is ignored
103
174
  def filename=(*)
104
- # dummy method currently to stop changing filename by caller once created,
105
- # but not raise error.
106
- # - Return an error flag in the ':status' variable.
107
175
  status_set(errors: ERR_CANT_CHANGE)
108
176
  console_output('Cannot change filename after creation',
109
177
  OUTPUT_SEVERITY[:WARN])
110
178
  end
111
179
 
180
+ # Read the configuration key (key)
181
+ # @example
182
+ # key = settings[:key]
183
+ # @return [<various>] Return value depends on the type of variable stored
112
184
  def [](key)
113
185
  @config[key]
114
186
  end
115
187
 
188
+ # Set a configuration key
189
+ # @example
190
+ # settings[:key] = "Value"
191
+ # settings[:array] = ["first", "second", "third"]
192
+ # @return [<various>] Returns the variable that was assigned.
116
193
  def []=(key, value)
117
194
  @config[key] = value
118
195
  end
119
196
 
197
+ # Returns the fully qualified path to the configuration file in use.
198
+ # @example
199
+ # path = config_path
200
+ # @return [String] Full path and filename of the configuration file.
120
201
  def config_path
121
202
  File.expand_path(File.join(@location, @filename))
122
203
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confoog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seapagan
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: inch
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description: A simple Gem to add YAML configuration files to your Ruby script or Gem
112
126
  email:
113
127
  - seapagan@gmail.com