active_object 4.0.14 → 5.0.1

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: 5f31cda51ca069ea0b9c95761a8e47a2bee4f790
4
- data.tar.gz: 271e61ac209c8214f07dbd886e8e5c3817955055
3
+ metadata.gz: 4cd0977ed5987833e7ad9c78da99af7a4f272eb7
4
+ data.tar.gz: 5d417a201cb1e86daf9ba248dddadc99691b537b
5
5
  SHA512:
6
- metadata.gz: 2a81cf6dce0eaa75ffcd73834b03e438df483bb645c6b5e2538e29f4702b7f9f7fdb78c11869153c2f733178e86fff7a527918c0576d753c65929020c400396a
7
- data.tar.gz: e26ccb4cdb9cf6bb64a959c9864d08961b322b2c0f2021379493acb47e4c5b39692214fbd4a3140c1d1f1eb3e392e0809bb2d890705c31459b7560bee284efb1
6
+ metadata.gz: b6a2979ceba4d3322cb54b8d678b7ea161eaedd13023f1150a4e4990b3db122670bdb0bda6e6a47fcd1060e42e03fbde51f3c4d6b96cd94ebc1c3bf68b74468e
7
+ data.tar.gz: 4319eb63c0f28920d755f7750bce797dbbb05dc2d1debf180eb882e2cc9af4cdc69b13ff058a01c3a65930451987431f363e6ecbdc40f6fc0419b09dafe431bb
data/.reek CHANGED
@@ -6,11 +6,7 @@ BooleanParameter:
6
6
  ControlParameter:
7
7
  enabled: false
8
8
  DuplicateMethodCall:
9
- exclude:
10
- - 'ActiveObject::Array#to_sentence'
11
- - 'ActiveObject::Array#split'
12
- - 'ActiveObject::Array#probability'
13
- - 'ActiveObject::Numeric'
9
+ enabled: false
14
10
  FeatureEnvy:
15
11
  enabled: false
16
12
  IrresponsibleModule:
data/.rubocop.yml CHANGED
@@ -4,39 +4,23 @@ AllCops:
4
4
  TargetRubyVersion: 2.4
5
5
  Exclude:
6
6
  - 'spec/**/**/*'
7
- Layout/ClosingParenthesisIndentation:
8
- Enabled: false
9
- Layout/EmptyLinesAroundBlockBody:
10
- Enabled: false
11
7
  Layout/EmptyLinesAroundClassBody:
12
8
  Enabled: false
13
9
  Layout/EmptyLinesAroundModuleBody:
14
10
  Enabled: false
15
- Layout/FirstParameterIndentation:
16
- Enabled: false
17
- Layout/MultilineMethodCallIndentation:
18
- EnforcedStyle: aligned
19
11
  LineLength:
20
12
  Max: 100
21
- Lint/ScriptPermission:
13
+ Lint/RescueWithoutErrorClass:
22
14
  Enabled: false
23
- Metrics/ClassLength:
15
+ Lint/ScriptPermission:
24
16
  Enabled: false
25
17
  Metrics/ModuleLength:
26
18
  Enabled: false
27
19
  Style/Alias:
28
20
  EnforcedStyle: prefer_alias_method
29
- Style/BracesAroundHashParameters:
30
- Enabled: false
31
21
  Style/ClassAndModuleChildren:
32
22
  EnforcedStyle: compact
33
23
  Style/Documentation:
34
24
  Enabled: false
35
- Style/HashSyntax:
36
- Enabled: false
37
- Style/FrozenStringLiteralComment:
38
- Enabled: false
39
- Style/NumericLiterals:
40
- Enabled: false
41
25
  Style/RescueModifier:
42
26
  Enabled: false
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in active_object.gemspec
data/README.md CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/active_object.svg)](http://badge.fury.io/rb/active_object)
4
4
  [![Build Status](https://travis-ci.org/drexed/active_object.svg?branch=master)](https://travis-ci.org/drexed/active_object)
5
- [![Coverage Status](https://coveralls.io/repos/github/drexed/active_object/badge.svg?branch=master)](https://coveralls.io/github/drexed/active_object?branch=master)
6
5
 
7
6
  ActiveObject is a collection of commonly used object helpers in a ruby based project.
8
7
 
@@ -46,7 +45,7 @@ Or install it yourself as:
46
45
  `../config/initalizers/active_object.rb`
47
46
 
48
47
  ```ruby
49
- ActiveObject::Settings.configure do |config|
48
+ ActiveObject.configure do |config|
50
49
  config.autoload_array = true
51
50
  config.autoload_date = true
52
51
  config.autoload_enumerable = true
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
 
3
5
  task default: :spec
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # coding: utf-8
2
4
 
3
5
  lib = File.expand_path('../lib', __FILE__)
@@ -20,10 +22,7 @@ Gem::Specification.new do |spec|
20
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
23
  spec.require_paths = ['lib']
22
24
 
23
- spec.add_runtime_dependency 'dry-configurable'
24
-
25
25
  spec.add_development_dependency 'bundler'
26
- spec.add_development_dependency 'coveralls'
27
26
  spec.add_development_dependency 'rake'
28
27
  spec.add_development_dependency 'rspec'
29
28
  spec.add_development_dependency 'generator_spec'
data/bin/console CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'bundler/setup'
4
5
  require 'active_object'
data/bin/rake CHANGED
@@ -1,10 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
- #
2
+ # frozen_string_literal: true
3
+
3
4
  # This file was generated by Bundler.
4
5
  #
5
6
  # The application 'rake' is installed as part of a gem, and
6
7
  # this file is here to facilitate running it.
7
- #
8
8
 
9
9
  require 'pathname'
10
10
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', Pathname.new(__FILE__).realpath)
@@ -1,206 +1,210 @@
1
- module ActiveObject::Array
1
+ # frozen_string_literal: true
2
2
 
3
- def after(value)
4
- return unless include?(value)
3
+ module ActiveObject
4
+ module Array
5
5
 
6
- self[(index(value).to_i + 1) % length]
7
- end
8
-
9
- def before(value)
10
- return unless include?(value)
11
-
12
- self[(index(value).to_i - 1) % length]
13
- end
6
+ def after(value)
7
+ return unless include?(value)
14
8
 
15
- def delete_first
16
- self[1..-1]
17
- end
18
-
19
- def delete_first!
20
- replace(delete_first)
21
- end
9
+ self[(index(value).to_i + 1) % length]
10
+ end
22
11
 
23
- def delete_last
24
- self[0...-1]
25
- end
12
+ def before(value)
13
+ return unless include?(value)
26
14
 
27
- def delete_last!
28
- replace(delete_last)
29
- end
15
+ self[(index(value).to_i - 1) % length]
16
+ end
30
17
 
31
- def delete_values(*args)
32
- result = []
33
- args.each { |val| result << delete(val) }
34
- result
35
- end
18
+ def delete_first
19
+ self[1..-1]
20
+ end
36
21
 
37
- def denillify(value = 0)
38
- map { |val| val.nil? ? value : val }
39
- end
22
+ def delete_first!
23
+ replace(delete_first)
24
+ end
40
25
 
41
- def denillify!(value = 0)
42
- replace(denillify(value))
43
- end
26
+ def delete_last
27
+ self[0...-1]
28
+ end
44
29
 
45
- def dig(key, *rest)
46
- value = (self[key] rescue nil)
30
+ def delete_last!
31
+ replace(delete_last)
32
+ end
47
33
 
48
- return if value.nil?
49
- return value if rest.empty?
50
- return value.dig(*rest) if value.respond_to?(:dig)
51
- end
34
+ def delete_values(*args)
35
+ result = []
36
+ args.each { |val| result << delete(val) }
37
+ result
38
+ end
52
39
 
53
- def duplicates(minimum = 2)
54
- hash = Hash.new(0)
55
- each { |val| hash[val] += 1 }
56
- hash.delete_if { |_, val| val < minimum }.keys
57
- end
40
+ def denillify(value = 0)
41
+ map { |val| val.nil? ? value : val }
42
+ end
58
43
 
59
- def from(position)
60
- self[position, length] || []
61
- end
44
+ def denillify!(value = 0)
45
+ replace(denillify(value))
46
+ end
62
47
 
63
- def groups(number)
64
- return [] if number <= 0
48
+ def dig(key, *rest)
49
+ value = (self[key] rescue nil)
65
50
 
66
- num, rem = length.divmod(number)
67
- collection = (0..(num - 1)).collect { |val| self[(val * number), number] }
68
- rem.positive? ? collection << self[-rem, rem] : collection
69
- end
51
+ return if value.nil?
52
+ return value if rest.empty?
53
+ return value.dig(*rest) if value.respond_to?(:dig)
54
+ end
70
55
 
71
- # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
72
- def in_groups(number, fill_with = nil)
73
- collection_length = length
74
- division = collection_length.div(number)
75
- modulo = collection_length % number
56
+ def duplicates(minimum = 2)
57
+ hash = ::Hash.new(0)
58
+ each { |val| hash[val] += 1 }
59
+ hash.delete_if { |_, val| val < minimum }.keys
60
+ end
76
61
 
77
- collection = []
78
- start = 0
79
- number.times do |int|
80
- mod_gt_zero = modulo.positive?
81
- grouping = division + (mod_gt_zero && modulo > int ? 1 : 0)
82
- collection << last_group = slice(start, grouping)
83
- last_group << fill_with if fill_with != false && mod_gt_zero && grouping == division
84
- start += grouping
62
+ def from(position)
63
+ self[position, length] || []
85
64
  end
86
65
 
87
- block_given? ? collection.each { |val| yield(val) } : collection
88
- end
89
- # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
66
+ def groups(number)
67
+ return [] if number <= 0
90
68
 
91
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
92
- def in_groups_of(number, fill_with = nil)
93
- if number.to_i <= 0
94
- raise ArgumentError,
95
- "Group length must be a positive integer, was #{number.inspect}"
69
+ num, rem = length.divmod(number)
70
+ collection = (0..(num - 1)).collect { |val| self[(val * number), number] }
71
+ rem.positive? ? collection << self[-rem, rem] : collection
96
72
  end
97
73
 
98
- if fill_with == false
99
- collection = self
100
- else
101
- padding = (number - length % number) % number
102
- collection = dup.concat(Array.new(padding, fill_with))
74
+ # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
75
+ def in_groups(number, fill_with = nil)
76
+ collection_length = length
77
+ division = collection_length.div(number)
78
+ modulo = collection_length % number
79
+
80
+ collection = []
81
+ start = 0
82
+ number.times do |int|
83
+ mod_gt_zero = modulo.positive?
84
+ grouping = division + (mod_gt_zero && modulo > int ? 1 : 0)
85
+ collection << last_group = slice(start, grouping)
86
+ last_group << fill_with if fill_with != false && mod_gt_zero && grouping == division
87
+ start += grouping
88
+ end
89
+
90
+ block_given? ? collection.each { |val| yield(val) } : collection
103
91
  end
92
+ # rubocop:enable Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/AbcSize
104
93
 
105
- sliced_collection = collection.each_slice(number)
94
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
95
+ def in_groups_of(number, fill_with = nil)
96
+ if number.to_i <= 0
97
+ raise ArgumentError,
98
+ "Group length must be a positive integer, was #{number.inspect}"
99
+ end
106
100
 
107
- block_given? ? sliced_collection { |val| yield(val) } : sliced_collection.to_a
108
- end
109
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
101
+ if fill_with == false
102
+ collection = self
103
+ else
104
+ padding = (number - length % number) % number
105
+ collection = dup.concat(::Array.new(padding, fill_with))
106
+ end
110
107
 
111
- def merge(*values)
112
- values.each { |val| concat(val) }
113
- self
114
- end
108
+ sliced_collection = collection.each_slice(number)
115
109
 
116
- def nillify
117
- map { |val| !val.nil? && (val.try(:blank?) || val.try(:to_s).blank?) ? nil : val }
118
- end
110
+ block_given? ? sliced_collection { |val| yield(val) } : sliced_collection.to_a
111
+ end
112
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
119
113
 
120
- def nillify!
121
- replace(nillify)
122
- end
114
+ def merge(*values)
115
+ values.each { |val| concat(val) }
116
+ self
117
+ end
123
118
 
124
- def probability
125
- hash = Hash.new(0.0)
126
- differ = 0.0
119
+ def nillify
120
+ map { |val| !val.nil? && (val.try(:blank?) || val.try(:to_s).blank?) ? nil : val }
121
+ end
127
122
 
128
- each do |val|
129
- hash[val] += 1.0
130
- differ += 1.0
123
+ def nillify!
124
+ replace(nillify)
131
125
  end
132
126
 
133
- hash.each_key { |val| hash[val] /= differ }
134
- hash
135
- end
127
+ def probability
128
+ hash = ::Hash.new(0.0)
129
+ differ = 0.0
136
130
 
137
- def reject_values(*args)
138
- reject { |val| args.include?(val) }
139
- end
131
+ each do |val|
132
+ hash[val] += 1.0
133
+ differ += 1.0
134
+ end
140
135
 
141
- def sample!
142
- delete_at(Random.rand(length - 1))
143
- end
136
+ hash.each_key { |val| hash[val] /= differ }
137
+ hash
138
+ end
144
139
 
145
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
146
- def split(number = nil)
147
- if block_given?
148
- each_with_object([[]]) do |element, results|
149
- yield(element) ? (results << []) : (results.last << element)
150
- end
151
- else
152
- results = [[]]
153
- arr = dup
154
-
155
- until arr.empty?
156
- if (idx = arr.index(number))
157
- results.last.concat(arr.shift(idx))
158
- arr.shift
159
- results << []
160
- else
161
- results.last.concat(arr.shift(arr.length))
140
+ def reject_values(*args)
141
+ reject { |val| args.include?(val) }
142
+ end
143
+
144
+ def sample!
145
+ delete_at(::Random.rand(length - 1))
146
+ end
147
+
148
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
149
+ def split(number = nil)
150
+ if block_given?
151
+ each_with_object([[]]) do |element, results|
152
+ yield(element) ? (results << []) : (results.last << element)
153
+ end
154
+ else
155
+ results = [[]]
156
+ arr = dup
157
+
158
+ until arr.empty?
159
+ if (idx = arr.index(number))
160
+ results.last.concat(arr.shift(idx))
161
+ arr.shift
162
+ results << []
163
+ else
164
+ results.last.concat(arr.shift(arr.length))
165
+ end
162
166
  end
163
- end
164
167
 
165
- results
168
+ results
169
+ end
166
170
  end
167
- end
168
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
171
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
169
172
 
170
- def strip
171
- reject(&:blank?)
172
- end
173
+ def strip
174
+ reject(&:blank?)
175
+ end
173
176
 
174
- def strip!
175
- replace(strip)
176
- end
177
+ def strip!
178
+ replace(strip)
179
+ end
177
180
 
178
- def to(position)
179
- position >= 0 ? first(position + 1) : self[0..position]
180
- end
181
+ def to(position)
182
+ position >= 0 ? first(position + 1) : self[0..position]
183
+ end
181
184
 
182
- # rubocop:disable Metrics/MethodLength
183
- def to_sentence(options = {})
184
- default_connectors = {
185
- words_connector: ', ',
186
- two_words_connector: ' and ',
187
- last_word_connector: ', and '
188
- }
189
- options = default_connectors.merge!(options)
190
-
191
- case length
192
- when 0
193
- ''
194
- when 1
195
- self[0].to_s.dup
196
- when 2
197
- "#{self[0]}#{options[:two_words_connector]}#{self[1]}"
198
- else
199
- "#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
185
+ # rubocop:disable Metrics/MethodLength
186
+ def to_sentence(options = {})
187
+ default_connectors = {
188
+ words_connector: ', ',
189
+ two_words_connector: ' and ',
190
+ last_word_connector: ', and '
191
+ }
192
+ options = default_connectors.merge!(options)
193
+
194
+ case length
195
+ when 0
196
+ ''
197
+ when 1
198
+ self[0].to_s.dup
199
+ when 2
200
+ "#{self[0]}#{options[:two_words_connector]}#{self[1]}"
201
+ else
202
+ "#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
203
+ end
200
204
  end
201
- end
202
- # rubocop:enable Metrics/MethodLength
205
+ # rubocop:enable Metrics/MethodLength
203
206
 
207
+ end
204
208
  end
205
209
 
206
- Array.include(ActiveObject::Array) if ActiveObject::Settings.config.autoload_array
210
+ Array.include(ActiveObject::Array) if ActiveObject.configuration.autoload_array
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveObject
4
+ class Configuration
5
+
6
+ attr_accessor :autoload_array, :autoload_date, :autoload_enumerable, :autoload_hash,
7
+ :autoload_integer, :autoload_numeric, :autoload_object, :autoload_range,
8
+ :autoload_string, :autoload_time
9
+
10
+ def initialize
11
+ @autoload_array = true
12
+ @autoload_date = true
13
+ @autoload_enumerable = true
14
+ @autoload_hash = true
15
+ @autoload_integer = true
16
+ @autoload_numeric = true
17
+ @autoload_object = true
18
+ @autoload_range = true
19
+ @autoload_string = true
20
+ @autoload_time = true
21
+ end
22
+
23
+ end
24
+
25
+ def self.configuration
26
+ @configuration ||= Configuration.new
27
+ end
28
+
29
+ def self.configuration=(config)
30
+ @configuration = config
31
+ end
32
+
33
+ def self.configure
34
+ yield(configuration)
35
+ end
36
+
37
+ end