skn_utils 3.0.2 → 3.1.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: 82fb6a798fdac8263ee4faa65a6dd734cf148365
4
- data.tar.gz: 2dc5b9cc3fa76df1d7c9dbef494b8e9d2dcee707
3
+ metadata.gz: b8101dc2b931c238b66774b58096c9220b04978e
4
+ data.tar.gz: 4250acac9028a89de948d8c82986191d6471db09
5
5
  SHA512:
6
- metadata.gz: f5d5410f5f06e63a85e054a36e27f20cd5a8c344c59453f992c36e3e28d9632ac256e10f96df6b03421649da3b64e5493808c48e42b5abbc1bce18206347b2c9
7
- data.tar.gz: 217fc83650fff470b1a5869734747875727bfbcc374a2762e3562b1d610a90bd020505dfbb2ef2340bf09ddcc98791f2688e3095af5f6a0569eb3c86782c5219
6
+ metadata.gz: 9a0c6456e74196bad005876f4ff2d9a24635a22ab3d3a40f98daa7444461b33cc1a9d7fc868f22dd77db3da99a22935062cf17639c40760fbf74139d1669c49c
7
+ data.tar.gz: 7ae18c76e710f02b873165afc916ae97da9b7571bae75eb171e6f86869de684774815878141c389de52d19735e046e4fbde818169cdeb3535c4ff87ef6c5439a
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem "deep_merge", :require => 'deep_merge/rails_compat'
4
+
3
5
  # Specify your gem's dependencies in skn_utils.gemspec
4
6
  gemspec
data/bin/benchmark.rb ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'skn_utils'
5
+ require 'ostruct'
6
+ require 'psych'
7
+ require 'benchmark/ips'
8
+
9
+ Benchmark.ips do |x|
10
+
11
+ class RegularClass
12
+ attr_accessor :foo
13
+ end
14
+
15
+ class OpenStructClass < OpenStruct
16
+ end
17
+
18
+ x.report('regular class') do
19
+ r = RegularClass.new
20
+ r.foo = :bar
21
+ r.foo
22
+ end
23
+
24
+ x.report('OpenStruct class') do
25
+ o = OpenStructClass.new(foo: nil)
26
+ o.foo = :bar
27
+ o.foo
28
+ end
29
+
30
+ x.report('NestedResult class') do
31
+ n = SknUtils::NestedResult.new(foo: nil)
32
+ n.foo = :bar
33
+ n.foo
34
+ end
35
+ end
36
+
37
+ # Warming up --------------------------------------
38
+ # regular class 182.079k i/100ms
39
+ # OpenStruct class 12.129k i/100ms
40
+ # NestedResult class 11.075k i/100ms
41
+ # Calculating -------------------------------------
42
+ # regular class 4.140M (± 2.2%) i/s - 20.757M in 5.015689s
43
+ # OpenStruct class 129.418k (± 2.3%) i/s - 654.966k in 5.063580s
44
+ # NestedResult class 115.819k (± 2.3%) i/s - 586.975k in 5.070852s
data/bin/console CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'skn_utils'
5
4
  require 'psych'
5
+ require 'erb'
6
+ require 'deep_merge/rails_compat'
7
+ require 'skn_utils'
6
8
 
7
9
  require 'pry'
8
10
  Pry.start
@@ -0,0 +1,11 @@
1
+ ##
2
+ # Initialize:
3
+ # SknSettings.load_config_basename!('some_name')
4
+ #
5
+ # Usage:
6
+ # SknSettings.<config.key>[.<config.key>]...
7
+ ##
8
+
9
+ # This creates a global constant (and singleton) with a defaulted configuration
10
+ class << (SknSettings = SknUtils::SknConfiguration.new())
11
+ end
@@ -94,8 +94,7 @@ module SknUtils
94
94
  class NestedResult
95
95
 
96
96
  def initialize(params={})
97
- @container = {}
98
- initialize_for_speed(params)
97
+ reset_from_empty!(params)
99
98
  end
100
99
 
101
100
  def [](attr)
@@ -170,12 +169,17 @@ module SknUtils
170
169
  def init_with(coder)
171
170
  case coder.tag
172
171
  when '!ruby/object:SknUtils::NestedResult', "!ruby/object:#{self.class.name}"
173
- initialize_for_speed( coder.map['container'] )
172
+ reset_from_empty!( coder.map['container'] )
174
173
  end
175
174
  end
176
175
 
177
176
  protected
178
177
 
178
+ def reset_from_empty!(params={})
179
+ @container = {}
180
+ initialize_for_speed(params)
181
+ end
182
+
179
183
  ##
180
184
  # Marshal.load()/.dump() support, chance to re-initialize value methods
181
185
  #
@@ -185,7 +189,7 @@ module SknUtils
185
189
 
186
190
  # Using the String from above create and return an instance of this class
187
191
  def marshal_load(hash)
188
- initialize_for_speed(hash)
192
+ reset_from_empty!(hash)
189
193
  end
190
194
 
191
195
  def respond_to_missing?(method, incl_private=false)
@@ -316,10 +320,10 @@ module SknUtils
316
320
 
317
321
 
318
322
  if method.to_s.end_with?("=") # add new key/value pair, transform value if Hash or Array
319
- initialize_from_hash({method_nsym => args.first})
323
+ initialize_from_hash({method_nsym => args.first}) # Add Reader/Writer one first need
320
324
 
321
325
  elsif container.key?(method_sym)
322
- container[enable_dot_notation(method_sym)] # Add Reader/Writer one first need
326
+ container[method_sym] # Add Reader/Writer one first need
323
327
 
324
328
  elsif method.to_s.end_with?('?') # order of tests is significant,
325
329
  attribute?(method_nsym)
@@ -0,0 +1,47 @@
1
+ #
2
+ # @see SknSettings
3
+
4
+ module SknUtils
5
+
6
+ class SknConfiguration < NestedResult
7
+
8
+ def initialize(params={})
9
+ default_mode = defined?(Rails) ? Rails.env : ENV.fetch('RAILS_ENV', 'development')
10
+ @config_filename = params.is_a?(String) ? params : params.fetch(:config_filename, default_mode)
11
+ @base_path = @config_filename.eql?('test') ? './spec/factories/' : './config/'
12
+ load_config_basename!(@config_filename)
13
+ end
14
+
15
+ def load_config_basename!(conf)
16
+ reset_from_empty!(load_config(conf))
17
+ self
18
+ end
19
+
20
+ private
21
+
22
+ def load_config(conf)
23
+ yname = "#{@base_path}settings.yml"
24
+ return {} unless File.exist?(yname)
25
+ f_base = load_yml_with_erb(yname)
26
+
27
+ yname = "#{@base_path}settings/#{conf}.yml"
28
+ f_env = load_yml_with_erb(yname) if File.exist?(yname)
29
+ f_base = f_base.deeper_merge!(f_env) unless (f_env.nil? || f_env.empty?)
30
+
31
+ yname = "#{@base_path}settings/#{conf}.local.yml"
32
+ f_local = load_yml_with_erb(yname) if File.exist?(yname)
33
+ f_base = f_base.deeper_merge!(f_local) unless (f_local.nil? || f_local.empty?)
34
+
35
+ f_base
36
+ end
37
+
38
+ def load_yml_with_erb(yml_file)
39
+ erb = ERB.new(File.read(yml_file)).result
40
+ erb.empty? ? {} : Psych.load(erb)
41
+ rescue => e
42
+ puts "#{self.class.name}##{__method__} Class: #{e.class}, Message: #{e.message}"
43
+ {}
44
+ end
45
+ end
46
+
47
+ end
@@ -2,8 +2,8 @@
2
2
  module SknUtils
3
3
  class Version
4
4
  MAJOR = 3
5
- MINOR = 0
6
- PATCH = 2
5
+ MINOR = 1
6
+ PATCH = 0
7
7
 
8
8
  def self.to_s
9
9
  [MAJOR, MINOR, PATCH].join('.')
data/lib/skn_utils.rb CHANGED
@@ -2,8 +2,10 @@ require "skn_utils/version"
2
2
  require 'skn_utils/nested_result'
3
3
  require 'skn_utils/null_object'
4
4
  require 'skn_utils/notifier_base'
5
+ require 'skn_utils/skn_configuration'
5
6
  require 'skn_utils/exploring/commander'
6
7
  require 'skn_utils/exploring/action_service'
8
+ require 'skn_settings'
7
9
 
8
10
  module SknUtils
9
11
 
data/skn_utils.gemspec CHANGED
@@ -31,10 +31,11 @@ EOF
31
31
  spec.executables = []
32
32
  spec.test_files = spec.files.grep(%r{^(spec)/})
33
33
  spec.require_paths = ['lib']
34
-
34
+
35
35
  spec.add_development_dependency "bundler", ">= 0"
36
36
  spec.add_development_dependency "rake", ">= 0"
37
37
  spec.add_development_dependency "rspec", '~> 3.0'
38
38
  spec.add_development_dependency "pry", ">= 0"
39
39
  spec.add_development_dependency "simplecov", ">= 0"
40
+ spec.add_development_dependency 'benchmark-ips'
40
41
  end
@@ -0,0 +1,3 @@
1
+ ---
2
+ Packaging:
3
+ configName: test.local
@@ -0,0 +1,5 @@
1
+ ---
2
+ Packaging:
3
+ isTest: true
4
+ isDevelopment: false
5
+ configName: test
@@ -0,0 +1,9 @@
1
+ ---
2
+ Packaging:
3
+ pomVersion: <%= SknUtils::VERSION %>
4
+ isTest: false
5
+ isDevelopment: true
6
+ isStaging: false
7
+ isProduction: false
8
+ configName: development
9
+ short_name: skn
@@ -0,0 +1,10 @@
1
+ #
2
+
3
+ describe SknSettings, "Application Configuration" do
4
+
5
+ it 'contains the test settings for the application' do
6
+ expect(SknSettings.Packaging.pomVersion).to eq SknUtils::VERSION
7
+ expect(SknSettings.Packaging.configName).to eq 'test.local'
8
+ expect(SknSettings.Packaging.isTest).to be true
9
+ end
10
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,18 @@
1
- ENV['RAILS_ENV'] ||= 'test'
1
+ ENV['RAILS_ENV'] = 'test'
2
+
3
+ require 'bundler/setup'
4
+
5
+ require 'simplecov'
6
+
7
+ SimpleCov.start do
8
+ # any custom configs like groups and filters can be here at a central place
9
+ add_filter '/spec/'
10
+ end
11
+
12
+ require 'psych'
13
+ require 'json'
14
+ require 'erb'
15
+ require 'deep_merge/rails_compat'
2
16
 
3
17
  require 'skn_utils'
4
18
  require 'skn_utils/exploring/commander'
@@ -6,8 +20,6 @@ require 'skn_utils/exploring/action_service'
6
20
  require 'skn_utils/exploring/configuration'
7
21
 
8
22
  require 'rspec'
9
- require 'psych'
10
- require 'json'
11
23
 
12
24
  # Shared Examples and Support Routines
13
25
  Dir["./spec/support/**/*.rb"].sort.each { |f| require f}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: skn_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Scott Jr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-07 00:00:00.000000000 Z
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: benchmark-ips
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: "The intent of the NestedResult class is to be a container of data results
84
98
  or key/value pairs, \nwith easy access to its contents, and on-demand transformation
85
99
  back to the hash (#to_hash).\n\nReview the RSpec tests, and or review the README
@@ -98,7 +112,9 @@ files:
98
112
  - README.md
99
113
  - README.rdoc
100
114
  - Rakefile
115
+ - bin/benchmark.rb
101
116
  - bin/console
117
+ - lib/skn_settings.rb
102
118
  - lib/skn_utils.rb
103
119
  - lib/skn_utils/exploring/action_service.rb
104
120
  - lib/skn_utils/exploring/commander.rb
@@ -106,8 +122,13 @@ files:
106
122
  - lib/skn_utils/nested_result.rb
107
123
  - lib/skn_utils/notifier_base.rb
108
124
  - lib/skn_utils/null_object.rb
125
+ - lib/skn_utils/skn_configuration.rb
109
126
  - lib/skn_utils/version.rb
110
127
  - skn_utils.gemspec
128
+ - spec/factories/settings.yml
129
+ - spec/factories/settings/test.local.yml
130
+ - spec/factories/settings/test.yml
131
+ - spec/lib/skn_settings_spec.rb
111
132
  - spec/lib/skn_utils/exploring/action_service_spec.rb
112
133
  - spec/lib/skn_utils/exploring/commander_spec.rb
113
134
  - spec/lib/skn_utils/exploring/configuration_spec.rb
@@ -144,6 +165,10 @@ specification_version: 4
144
165
  summary: SknUtils contains a small collection of Ruby utilities, the first being a
145
166
  NestedResult a key/value container.
146
167
  test_files:
168
+ - spec/factories/settings.yml
169
+ - spec/factories/settings/test.local.yml
170
+ - spec/factories/settings/test.yml
171
+ - spec/lib/skn_settings_spec.rb
147
172
  - spec/lib/skn_utils/exploring/action_service_spec.rb
148
173
  - spec/lib/skn_utils/exploring/commander_spec.rb
149
174
  - spec/lib/skn_utils/exploring/configuration_spec.rb