skn_utils 3.6.0 → 4.0.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: f318459d97979405431fd4e09eb85d8688707636
4
- data.tar.gz: 350ee31b2176feae8d567d02e649eb220b2c8a0d
3
+ metadata.gz: 95950dfdf413d133698bc9614a5513cd5d91bf82
4
+ data.tar.gz: 9fc06b3576d657326af58ad7d4caa7ce20613f40
5
5
  SHA512:
6
- metadata.gz: c10cff645d8c75d49abe41ef1b438ba0e3e057f509bd9454133cb9e0bdf32840c82b7a5c861f7ec3787d8565b5f10617cb0dc2cfca9439cd27a28cbdcf31f07e
7
- data.tar.gz: 904d521b3bc3849a8bc6e71e7f0376668ed378e7fdd887e83279486a016b8710c068ebd3c8dbe59250224de26d78a11267c19263b71816f503406975d0b00ec5
6
+ metadata.gz: dcb65cc5acde288729d5b11f0812ffd3a3c199ae1609492398fc06b96ce75246430ba21b945238494d28af65fe4e333193ec36baaa6797e84e55f8f5c984be4e
7
+ data.tar.gz: 60788d945065c38d3c0ed1ff2e5a889533c89223ced661275b6ab94a49242aa9c09810316b666bf983b19a0de525041db30a0b7d7ce8f894dfca79254b17bcb2
data/README.md CHANGED
@@ -9,13 +9,29 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
9
9
  an Object with Dot or Hash notational accessors to each key's value. Additional key/value pairs can be added post-create
10
10
  by 'obj.my_new_var = "some value"', or simply assigning it.
11
11
 
12
- * Transforms the initializating hash into accessible object instance values, with their keys as method names.
12
+ * Transforms the initialing hash into accessible object instance values, with their keys as method names.
13
13
  * If the key's value is also a hash, it too will become an Object.
14
- * if the key's value is a Array of Hashes, or Array of Arrays of Hashes, each element of the Arrays will become an Object.
14
+ * if the key's value is a Array of Hashes, or Array of Arrays of Hashes, each hash element of the Arrays will become an Object.
15
15
  * The current key/value (including nested) pairs are returned via #to_hash or #to_json when and if needed.
16
16
 
17
+ #### Primary Classes
18
+ * SknSettings
19
+ * SknContainer
20
+ * SknHash
21
+ * SknUtils::NestedResult
22
+ * SknUtils::ResultBean
23
+ * SknUtils::PageControls
24
+ * SknUtils::Configurable
25
+ * SknUtils::NullObject
26
+ * SknUtils::EnvStringHandler
27
+ * SknUtils::CoreObjectExtensions
17
28
 
18
29
  ## New Features
30
+ 02/04/2018 V4.0.0
31
+ Added SknUtils::CoreObjectExtensions, this module contains those popular Rails ActiveSupport extensions like `:present?`.
32
+ - However, it is contructed with the Ruby `:refine` and `using SknUtils::CoreObjectExtensions` constraints, so as not to intefer with existing monkey-patches.
33
+ - Simply add `using SknUtils::CoreObjectExtensions` to any class or module you wish to use the `:present?`, `:blank?`, etc methods.
34
+
19
35
  01/2018 V3.6.0
20
36
  Moved Linked List to my Minimum_Heaps gem. This repo has a tag of 'lists' documententing the removal
21
37
  Removed classes and utils not directly related to NestedResult
@@ -210,10 +226,11 @@ Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated
210
226
 
211
227
  ## Installation
212
228
 
213
- runtime prereqs:
214
- V3+ None
215
- V2+ None
216
- V1+ gem 'active_model', '~> 3.0'
229
+ runtime prereqs:
230
+ * V4+ None
231
+ * V3+ None
232
+ * V2+ None
233
+ * V1+ gem 'active_model', '~> 3.0'
217
234
 
218
235
 
219
236
  Add this line to your application's Gemfile:
@@ -0,0 +1,141 @@
1
+ # ##
2
+ # File: ./lib/skn_utils/core_extensions.rb --
3
+ # -- from: Rails 4.1 ActiveSupport:lib/active_support/core_ext/object/blank.rb
4
+ # -- Ref: https://6ftdan.com/allyourdev/2015/01/20/refinements-over-monkey-patching/
5
+
6
+ module SknUtils
7
+ module CoreObjectExtensions
8
+
9
+ unless Object.respond_to?(:present?)
10
+
11
+ refine Object do
12
+ # An object is blank if it's false, empty, or a whitespace string.
13
+ # For example, '', ' ', +nil+, [], and {} are all blank.
14
+ #
15
+ # This simplifies
16
+ #
17
+ # address.nil? || address.empty?
18
+ #
19
+ # to
20
+ #
21
+ # address.blank?
22
+ #
23
+ # @return [true, false]
24
+ def blank?
25
+ respond_to?(:empty?) ? !!empty? : !self
26
+ end
27
+
28
+ # An object is present if it's not blank.
29
+ #
30
+ # @return [true, false]
31
+ def present?
32
+ !blank?
33
+ end
34
+
35
+ # Returns the receiver if it's present otherwise returns +nil+.
36
+ # <tt>object.presence</tt> is equivalent to
37
+ #
38
+ # object.present? ? object : nil
39
+ #
40
+ # For example, something like
41
+ #
42
+ # state = params[:state] if params[:state].present?
43
+ # country = params[:country] if params[:country].present?
44
+ # region = state || country || 'US'
45
+ #
46
+ # becomes
47
+ #
48
+ # region = params[:state].presence || params[:country].presence || 'US'
49
+ #
50
+ # @return [Object]
51
+ def presence
52
+ self if present?
53
+ end
54
+ end
55
+
56
+ refine NilClass do
57
+ # +nil+ is blank:
58
+ #
59
+ # nil.blank? # => true
60
+ #
61
+ # @return [true]
62
+ def blank?
63
+ true
64
+ end
65
+ end
66
+
67
+ refine FalseClass do
68
+ # +false+ is blank:
69
+ #
70
+ # false.blank? # => true
71
+ #
72
+ # @return [true]
73
+ def blank?
74
+ true
75
+ end
76
+ end
77
+
78
+ refine TrueClass do
79
+ # +true+ is not blank:
80
+ #
81
+ # true.blank? # => false
82
+ #
83
+ # @return [false]
84
+ def blank?
85
+ false
86
+ end
87
+ end
88
+
89
+ refine Array do
90
+ # An array is blank if it's empty:
91
+ #
92
+ # [].blank? # => true
93
+ # [1,2,3].blank? # => false
94
+ #
95
+ # @return [true, false]
96
+ alias_method :blank?, :empty?
97
+ end
98
+
99
+ refine Hash do
100
+ # A hash is blank if it's empty:
101
+ #
102
+ # {}.blank? # => true
103
+ # { key: 'value' }.blank? # => false
104
+ #
105
+ # @return [true, false]
106
+ alias_method :blank?, :empty?
107
+ end
108
+
109
+ refine String do
110
+ # A string is blank if it's empty or contains whitespaces only:
111
+ #
112
+ # ''.blank? # => true
113
+ # ' '.blank? # => true
114
+ # "\t\n\r".blank? # => true
115
+ # ' blah '.blank? # => false
116
+ #
117
+ # Unicode whitespace is supported:
118
+ #
119
+ # "\u00a0".blank? # => true
120
+ #
121
+ # @return [true, false]
122
+ def blank?
123
+ /\A[[:space:]]*\z/ === self
124
+ end
125
+ end
126
+
127
+ refine Numeric do #:nodoc:
128
+ # No number is blank:
129
+ #
130
+ # 1.blank? # => false
131
+ # 0.blank? # => false
132
+ #
133
+ # @return [false]
134
+ def blank?
135
+ false
136
+ end
137
+ end
138
+ end # end unless respond_to
139
+
140
+ end # end CoreObjectExtensions
141
+ end # end SknUtils
@@ -93,8 +93,17 @@
93
93
  module SknUtils
94
94
  class NestedResult
95
95
 
96
- def initialize(params={}, mod=true)
97
- reset_from_empty!(params, mod)
96
+ # ##
97
+ # Onlye good for the first level
98
+ def self.with_methods(args)
99
+ new(args, false)
100
+ end
101
+ def self.with_instance_vars(args)
102
+ new(args, true)
103
+ end
104
+
105
+ def initialize(params={}, speed=true)
106
+ reset_from_empty!(params, speed)
98
107
  end
99
108
 
100
109
  def [](attr)
@@ -6,7 +6,7 @@ module SknUtils
6
6
  class SknConfiguration < NestedResult
7
7
 
8
8
  def initialize(params={})
9
- default_mode = defined?(Rails) ? Rails.env : ENV.fetch('RAILS_ENV', 'development')
9
+ default_mode = defined?(Rails) ? Rails.env : ENV.fetch('RACK_ENV', 'development')
10
10
  @config_filename = params.is_a?(String) ? params : params.fetch(:config_filename, default_mode)
11
11
  @base_path = ENV.fetch('TEST_GEM', 'rails').eql?('gem') ? './spec/factories/' : './config/'
12
12
  load_config_basename!(@config_filename)
@@ -1,8 +1,8 @@
1
1
  # A better way to say it
2
2
  module SknUtils
3
3
  class Version
4
- MAJOR = 3
5
- MINOR = 6
4
+ MAJOR = 4
5
+ MINOR = 0
6
6
  PATCH = 0
7
7
 
8
8
  def self.to_s
data/lib/skn_utils.rb CHANGED
@@ -13,6 +13,7 @@ unless defined?(Rails)
13
13
  puts e.message
14
14
  end
15
15
  end
16
+ require 'skn_utils/core_extensions'
16
17
  require 'skn_utils/env_string_handler'
17
18
  require 'skn_utils/nested_result'
18
19
  require 'skn_utils/result_bean'
@@ -7,3 +7,9 @@ Packaging:
7
7
  isProduction: false
8
8
  configName: development
9
9
  short_name: skn
10
+
11
+ # Create a EnvStringHandler to support: SknSettings.env.development?
12
+ # Yes, its YAML trick
13
+ env: !ruby/string:SknUtils::EnvStringHandler <%= ENV['RACK_ENV'] %>
14
+ root: <%= Dir.pwd %>
15
+
@@ -7,4 +7,16 @@ describe SknSettings, "Application Configuration" do
7
7
  expect(SknSettings.Packaging.configName).to eq 'test.local'
8
8
  expect(SknSettings.Packaging.isTest).to be true
9
9
  end
10
+
11
+ it 'contains the current RACK or RAILS environment values' do
12
+ expect(SknSettings.env).to eq 'test'
13
+ expect(SknSettings.env.test?).to be true
14
+ expect(SknSettings.env.development?).to be false
15
+ end
16
+
17
+ it 'contains the application root path as a string' do
18
+ expect(SknSettings.root).to eq Dir.pwd
19
+ expect(SknSettings.root).to be_a(String)
20
+ end
21
+
10
22
  end
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
+ ENV['RACK_ENV'] = 'test'
2
3
 
3
4
  ENV['TEST_GEM'] = 'gem' # enable SknSettings Gem Mode Testing
4
5
 
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.6.0
4
+ version: 4.0.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: 2018-01-21 00:00:00.000000000 Z
11
+ date: 2018-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deep_merge
@@ -150,6 +150,7 @@ files:
150
150
  - lib/skn_settings.rb
151
151
  - lib/skn_utils.rb
152
152
  - lib/skn_utils/configurable.rb
153
+ - lib/skn_utils/core_extensions.rb
153
154
  - lib/skn_utils/env_string_handler.rb
154
155
  - lib/skn_utils/nested_result.rb
155
156
  - lib/skn_utils/notifier_base.rb