skn_utils 3.3.11 → 3.3.12

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: 2320444637a8553023d0ec9e5f911b98088fd4d3
4
- data.tar.gz: 826ebe50285744c864944b884a242be41ae71f73
3
+ metadata.gz: e6048e54b3ef049c2f0cc12d2e5d8c1068464bf9
4
+ data.tar.gz: 13d07f94bf6785297b7da9f407447abe7ea0242c
5
5
  SHA512:
6
- metadata.gz: 6cd9147939ac1b4faa2b06cf588013628dfa56ec5f9b2b5bc8e003f5a90c4425ce45e74d1b4d291e4650d84bd386ddd7ea0b07b7d265191d1c8bd25951b5a095
7
- data.tar.gz: e9e72e2a88758598cf6ba9fee28b94f7fb3c9f47bb176baf5b648d68038ae98bdbad2591fd030577805d06e7d11b529b8c056ef3089c2cd60a1721873a5ed51b
6
+ metadata.gz: 491f607e8959573f8d9a8806d1447802507fb50a8ae51487fa428421a87c3b20569fe62212f0cc6a1b6226182dba2f25a6813515fe78fa60bced473fcb8be1fe
7
+ data.tar.gz: 8237f57472729b24e8b25b7346bdda8413f0d0616f1942dbda9d6cda1f05a558c91441ba68d0f40fcbc48a65bb8b8b7678a23790ebef05cfd1a861dbb055da5e
data/README.md CHANGED
@@ -54,7 +54,8 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
54
54
 
55
55
  ## Public Components
56
56
  SknUtils::NestedResult # >= V 3.0.0 Primary Key/Value Container with Dot/Hash notiation support.
57
- SknSettings # Application Configuration class, Key/Value Container with Dot/Hash notiation support.
57
+ SknSettings # Multi-level application Configuration class, Key/Value Container with Dot/Hash notiation support.
58
+ SknUtils::Configurable # Basic one-level configuration settings module for Applications and or Gems
58
59
 
59
60
  SknHash # Wrapper for name only, WITHOUT SknUtils namespace, inherits from SknUtils::NestedResult
60
61
  SknUtils::ResultBean # Wrapper for name only, inherits from SknUtils::NestedResult
@@ -65,6 +66,7 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
65
66
  SknUtils::List::CircularLinkedList # List with forward (#next) and backward (#prev) navigation, and head/tail wrapping
66
67
 
67
68
 
69
+
68
70
  ## Configuration Options
69
71
  None required other than initialization hash
70
72
 
data/bin/console CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'skn_utils'
5
+ require 'skn_utils/business_services/year_month'
6
+ require 'skn_utils/exploring/commander'
7
+ require 'skn_utils/exploring/action_service'
8
+ require 'skn_utils/exploring/configuration'
5
9
 
6
10
  require 'pry'
7
11
  Pry.start
@@ -0,0 +1,58 @@
1
+ ##
2
+ # File: <gem-root>/lib/skn_utils/business_services/year_month.rb
3
+ # Ref: http://blog.arkency.com/2014/08/using-ruby-range-with-custom-classes/
4
+ #
5
+ ## Calculates YearMonth
6
+ #
7
+ # YearMonth.new(2014, 3) > YearMonth.new(2014, 1)
8
+ # => true
9
+
10
+ # YearMonth.new(2014, 1) >= YearMonth.new(2014, 1)
11
+ # => true
12
+
13
+ # YearMonth.new(2015, 1) < YearMonth.new(2014, 3)
14
+ # => false
15
+ #
16
+ module SknUtils
17
+ module BusinessServices
18
+
19
+ class YearMonth < Struct.new(:year, :month)
20
+ include Comparable
21
+
22
+ def initialize(iyear, imonth)
23
+ cleaned_year = iyear.to_i
24
+ cleaned_month = imonth.to_i
25
+
26
+ raise ArgumentError unless cleaned_year > 0
27
+ raise ArgumentError unless cleaned_month >= 1 && cleaned_month <= 12
28
+
29
+ super(cleaned_year, cleaned_month)
30
+ end
31
+
32
+ def next
33
+ if month == 12
34
+ self.class.new(year+1, 1)
35
+ else
36
+ self.class.new(year, month+1)
37
+ end
38
+ end
39
+ alias_method :succ, :next
40
+
41
+ def <=>(other)
42
+ (year <=> other.year).nonzero? || month <=> other.month
43
+ end
44
+
45
+ # need to do some time calcs
46
+
47
+ def beginning_of
48
+ Time.parse("12:00",Date.new(year, month, 1).to_time) # strftime('%Y-%m-%d')
49
+ end
50
+
51
+ def end_of
52
+ Time.parse("12:00",Date.new(year, month, -1).to_time) # strftime('%Y-%m-%d')
53
+ end
54
+
55
+ private :year=, :month=
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,79 @@
1
+ ##
2
+ # File: <gem-root>/lib/skn_utils/configurable.rb
3
+ # Ref: https://www.toptal.com/ruby/ruby-dsl-metaprogramming-guide
4
+ #
5
+
6
+ module SknUtils
7
+
8
+ # In the end, we have got ourselves a pretty neat module for making an arbitrary
9
+ # class configurable and then specifying those configuration values using a clean
10
+ # and simple DSL that also lets us reference one configuration attribute
11
+ # from another:
12
+ #
13
+ #################
14
+ # Inside Target component
15
+ #################
16
+ # class MyApp
17
+ # include SknUtils::Configurable.with(:app_id, :title, :cookie_name)
18
+ # # ...
19
+ # end
20
+ #
21
+ #################
22
+ # Inside Initializer
23
+ #################
24
+ # MyApp.configure do
25
+ # app_id "my_app"
26
+ # title "My App"
27
+ # cookie_name { "#{app_id}_session" }
28
+ # end
29
+ #
30
+ #################
31
+ # Usage:
32
+ #################
33
+ # MyApp.config.app_id # ==> "my_app"
34
+ #
35
+ # Here is the final version of the module that implements our DSL—a total of 36 lines of code:
36
+
37
+ module Configurable
38
+
39
+ def self.with(*attrs)
40
+ not_provided = Object.new
41
+
42
+ # Define the class/module methods
43
+ config_class = Class.new do
44
+ attrs.each do |attr|
45
+ define_method attr do |value = not_provided, &block|
46
+ if value === not_provided && block.nil?
47
+ result = instance_variable_get("@#{attr}")
48
+ result.is_a?(Proc) ? instance_eval(&result) : result
49
+ else
50
+ instance_variable_set("@#{attr}", block || value)
51
+ end
52
+ end
53
+ end
54
+
55
+ attr_writer *attrs
56
+ end
57
+
58
+ # Define the runtime access methods
59
+ class_methods = Module.new do
60
+ define_method :config do
61
+ @config ||= config_class.new
62
+ end
63
+
64
+ def configure(&block)
65
+ config.instance_eval(&block)
66
+ end
67
+ end
68
+
69
+ # Apply the custom configuration
70
+ Module.new do
71
+ singleton_class.send :define_method, :included do |host_class|
72
+ host_class.extend class_methods
73
+ end
74
+ end
75
+
76
+ end # method
77
+
78
+ end # end module
79
+ end # End module
@@ -3,7 +3,14 @@
3
3
  # Ruby Notify like class
4
4
  #
5
5
  # Ref: https://ozone.wordpress.com/category/programming/metaprogramming/
6
-
6
+ ##
7
+ # Listeners implement:
8
+ #
9
+ # def attribute_changed(attr, old, new)
10
+ # ...
11
+ # end
12
+ #
13
+ #
7
14
  module SknUtils
8
15
  class NotifierBase
9
16
 
@@ -3,7 +3,7 @@ module SknUtils
3
3
  class Version
4
4
  MAJOR = 3
5
5
  MINOR = 3
6
- PATCH = 11
6
+ PATCH = 12
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 'psych'
3
3
  require 'json'
4
4
  require 'erb'
5
+ require 'date'
6
+ require 'time'
5
7
  unless defined?(Rails)
6
- require 'deep_merge'
8
+ require 'deep_merge'
7
9
  end
8
10
  require 'skn_utils/nested_result'
9
11
  require 'skn_utils/result_bean'
@@ -11,13 +13,15 @@ require 'skn_utils/page_controls'
11
13
  require 'skn_utils/null_object'
12
14
  require 'skn_utils/notifier_base'
13
15
  require 'skn_utils/skn_configuration'
16
+ require 'skn_utils/configurable'
14
17
  require 'skn_utils/lists/linked_commons'
15
18
  require 'skn_utils/lists/link_node'
16
19
  require 'skn_utils/lists/linked_list'
17
20
  require 'skn_utils/lists/doubly_linked_list'
18
21
  require 'skn_utils/lists/circular_linked_list'
19
- require 'skn_utils/exploring/commander'
20
- require 'skn_utils/exploring/action_service'
22
+ # require 'skn_utils/business_services/year_month'
23
+ # require 'skn_utils/exploring/commander'
24
+ # require 'skn_utils/exploring/action_service'
21
25
  # require 'skn_utils/exploring/configuration'
22
26
  require 'skn_hash'
23
27
  require 'skn_settings'
@@ -0,0 +1,49 @@
1
+ ##
2
+ # spec/lib/skn_utils/node_based_linked_list_spec.rb
3
+ #
4
+
5
+ RSpec.describe SknUtils::BusinessServices::YearMonth, "Year Month Calculator " do
6
+
7
+ let(:basic) { described_class.new(2017, 1) }
8
+
9
+ context "Normal Operations " do
10
+
11
+ it "No params" do
12
+ expect{described_class.new}.to raise_error(ArgumentError)
13
+ end
14
+ it "With Params" do
15
+ expect(basic).to be_a described_class
16
+ end
17
+ it "#beginning_of month to be correct. " do
18
+ expect(basic.beginning_of).to be_a Time
19
+ end
20
+ it "#end_of month to be correct. " do
21
+ expect(basic.end_of).to be_a Time
22
+ end
23
+ it "#month to equal 3." do
24
+ expect(basic.month).to eq(1)
25
+ end
26
+ it "#year to equal 2017." do
27
+ expect(basic.year).to eq(2017)
28
+ end
29
+ it "#next.month to equal 2." do
30
+ expect(basic.next.month).to eq(2)
31
+ end
32
+ it "Comparisons are correct." do
33
+ expect(described_class.new(2017,1)).to eq(described_class.new(2017,1))
34
+ expect(described_class.new(2017,2)).to be > (described_class.new(2017,1))
35
+ expect(described_class.new(2017,1)).to be < (described_class.new(2017,2))
36
+ end
37
+ end
38
+
39
+ context "Range Operations " do
40
+
41
+ it "Can be represented in a Range object. " do
42
+ range = described_class.new(2017, 1)..described_class.new(2017, 9)
43
+
44
+ expect(range).to include(described_class.new(2017, 2))
45
+ expect(range).to include(described_class.new(2017, 7))
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,57 @@
1
+ ##
2
+ # spec/lib/skn_utils/exploring/configuration_spec.rb
3
+ #
4
+
5
+ class MyApp
6
+ include SknUtils::Configurable.with(:app_id, :title, :cookie_name)
7
+
8
+ def null_value
9
+ @app_id.dup
10
+ end
11
+ end
12
+
13
+ module MyMod
14
+ include SknUtils::Configurable.with(:app_id, :title, :cookie_name)
15
+
16
+ def self.null_value
17
+ @@app_id.dup
18
+ end
19
+ end
20
+
21
+ MyApp.configure do
22
+ app_id 'some app'
23
+ title 'My Title'
24
+ cookie_name 'Chocolate'
25
+ end
26
+
27
+ MyMod.configure do
28
+ app_id 'some module'
29
+ title 'Some Title'
30
+ cookie_name 'Caramel'
31
+ end
32
+
33
+
34
+ describe SknUtils::Configurable, "Gem Configuration module." do
35
+
36
+ let(:my_app) { MyApp.new }
37
+
38
+
39
+ context "Operational Features. " do
40
+
41
+ it "my_app#config.title returns expected value. " do
42
+ expect( MyApp.config.title ).to eq( "My Title" )
43
+ end
44
+ it "my_app#config.app_id returns expected value. " do
45
+ expect( MyApp.config.app_id ).to eq( "some app" )
46
+ end
47
+
48
+ it "MyMod#config.app_id returns expected value. " do
49
+ expect( MyMod.config.app_id ).to eq( "some module" )
50
+ end
51
+ it "MyMod#config.cookie_name returns expected value. " do
52
+ expect( MyMod.config.cookie_name ).to eq( 'Caramel' )
53
+ end
54
+
55
+ end
56
+
57
+ end
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,7 @@ require 'skn_utils'
15
15
  require 'skn_utils/exploring/commander'
16
16
  require 'skn_utils/exploring/action_service'
17
17
  require 'skn_utils/exploring/configuration'
18
+ require 'skn_utils/business_services/year_month'
18
19
 
19
20
  require 'rspec'
20
21
 
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.3.11
4
+ version: 3.3.12
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-08-18 00:00:00.000000000 Z
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -134,6 +134,8 @@ files:
134
134
  - lib/skn_hash.rb
135
135
  - lib/skn_settings.rb
136
136
  - lib/skn_utils.rb
137
+ - lib/skn_utils/business_services/year_month.rb
138
+ - lib/skn_utils/configurable.rb
137
139
  - lib/skn_utils/exploring/action_service.rb
138
140
  - lib/skn_utils/exploring/commander.rb
139
141
  - lib/skn_utils/exploring/configuration.rb
@@ -154,6 +156,8 @@ files:
154
156
  - spec/factories/settings/test.local.yml
155
157
  - spec/factories/settings/test.yml
156
158
  - spec/lib/skn_settings_spec.rb
159
+ - spec/lib/skn_utils/business_services/year_month_spec.rb
160
+ - spec/lib/skn_utils/configurable_spec.rb
157
161
  - spec/lib/skn_utils/exploring/action_service_spec.rb
158
162
  - spec/lib/skn_utils/exploring/commander_spec.rb
159
163
  - spec/lib/skn_utils/exploring/configuration_spec.rb
@@ -200,6 +204,8 @@ test_files:
200
204
  - spec/factories/settings/test.local.yml
201
205
  - spec/factories/settings/test.yml
202
206
  - spec/lib/skn_settings_spec.rb
207
+ - spec/lib/skn_utils/business_services/year_month_spec.rb
208
+ - spec/lib/skn_utils/configurable_spec.rb
203
209
  - spec/lib/skn_utils/exploring/action_service_spec.rb
204
210
  - spec/lib/skn_utils/exploring/commander_spec.rb
205
211
  - spec/lib/skn_utils/exploring/configuration_spec.rb