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 +4 -4
- data/.reek +1 -5
- data/.rubocop.yml +2 -18
- data/Gemfile +2 -0
- data/README.md +1 -2
- data/Rakefile +2 -0
- data/active_object.gemspec +2 -3
- data/bin/console +1 -0
- data/bin/rake +2 -2
- data/lib/active_object/array.rb +165 -161
- data/lib/active_object/configuration.rb +37 -0
- data/lib/active_object/date.rb +84 -78
- data/lib/active_object/enumerable.rb +6 -5
- data/lib/active_object/hash.rb +197 -193
- data/lib/active_object/integer.rb +25 -21
- data/lib/active_object/numeric.rb +440 -436
- data/lib/active_object/object.rb +80 -76
- data/lib/active_object/range.rb +28 -24
- data/lib/active_object/string.rb +281 -277
- data/lib/active_object/time.rb +121 -117
- data/lib/active_object/version.rb +3 -1
- data/lib/active_object.rb +3 -1
- data/lib/generators/active_object/install_generator.rb +2 -0
- data/lib/generators/active_object/templates/install.rb +3 -1
- metadata +4 -33
- data/.coveralls.yml +0 -1
- data/lib/active_object/settings.rb +0 -17
data/lib/active_object/object.rb
CHANGED
@@ -1,101 +1,105 @@
|
|
1
|
-
|
2
|
-
FALSE_VALUES ||= [false, 0, '0', 'false', 'FALSE', 'f', 'F'].freeze
|
3
|
-
TRUE_VALUES ||= [true, 1, '1', 'true', 'TRUE', 't', 'T'].freeze
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
module ActiveObject
|
4
|
+
module Object
|
5
|
+
FALSE_VALUES ||= [false, 0, '0', 'false', 'FALSE', 'f', 'F'].freeze
|
6
|
+
TRUE_VALUES ||= [true, 1, '1', 'true', 'TRUE', 't', 'T'].freeze
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
respond_to?(:empty?) ? object.empty? : !object
|
13
|
-
end
|
8
|
+
def array?
|
9
|
+
is_a?(Array)
|
10
|
+
end
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
def blank?
|
13
|
+
object = self
|
14
|
+
object = object.strip if respond_to?(:strip)
|
15
|
+
respond_to?(:empty?) ? object.empty? : !object
|
16
|
+
end
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
# rubocop:enable Style/YodaCondition
|
18
|
+
def boolean?
|
19
|
+
TRUE_VALUES.include?(self) || FALSE_VALUES.include?(self)
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
# rubocop:disable Style/YodaCondition
|
23
|
+
def false?
|
24
|
+
false == self
|
25
|
+
end
|
26
|
+
# rubocop:enable Style/YodaCondition
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
28
|
+
def falsey?
|
29
|
+
nil? || FALSE_VALUES.include?(self)
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
32
|
+
def float?
|
33
|
+
is_a?(Float)
|
34
|
+
end
|
36
35
|
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def hash?
|
37
|
+
is_a?(Hash)
|
38
|
+
end
|
40
39
|
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
def integer?
|
41
|
+
is_a?(Integer)
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
def numeral?
|
45
|
+
!to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/).nil?
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
def numeric?
|
49
|
+
is_a?(Numeric)
|
50
|
+
end
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
def palindrome?
|
53
|
+
to_s == to_s.reverse
|
54
|
+
end
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
def present?
|
57
|
+
!blank?
|
58
|
+
end
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
def range?
|
61
|
+
is_a?(Range)
|
62
|
+
end
|
64
63
|
|
65
|
-
|
66
|
-
|
67
|
-
|
64
|
+
def salvage(placeholder = '---')
|
65
|
+
blank? ? placeholder : self
|
66
|
+
end
|
68
67
|
|
69
|
-
|
70
|
-
|
71
|
-
|
68
|
+
def send_chain(*keys)
|
69
|
+
Array(keys).inject(self) { |obj, key| obj.send(*key) }
|
70
|
+
end
|
72
71
|
|
73
|
-
|
74
|
-
|
75
|
-
|
72
|
+
def string?
|
73
|
+
is_a?(String)
|
74
|
+
end
|
76
75
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
end
|
81
|
-
# rubocop:enable Style/YodaCondition
|
76
|
+
def time?
|
77
|
+
is_a?(Time)
|
78
|
+
end
|
82
79
|
|
83
|
-
|
84
|
-
|
85
|
-
|
80
|
+
# rubocop:disable Style/YodaCondition
|
81
|
+
def true?
|
82
|
+
true == self
|
83
|
+
end
|
84
|
+
# rubocop:enable Style/YodaCondition
|
86
85
|
|
87
|
-
|
88
|
-
|
89
|
-
|
86
|
+
def truthy?
|
87
|
+
TRUE_VALUES.include?(self)
|
88
|
+
end
|
90
89
|
|
91
|
-
|
92
|
-
|
93
|
-
block.arity.zero? ? instance_eval(&block) : yield(self)
|
94
|
-
else
|
95
|
-
public_send(*obj, &block)
|
90
|
+
def try(*obj, &block)
|
91
|
+
try!(*obj, &block) if obj.empty? || respond_to?(obj.first)
|
96
92
|
end
|
97
|
-
end
|
98
93
|
|
94
|
+
def try!(*obj, &block)
|
95
|
+
if obj.empty? && block_given?
|
96
|
+
block.arity.zero? ? instance_eval(&block) : yield(self)
|
97
|
+
else
|
98
|
+
public_send(*obj, &block)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
99
103
|
end
|
100
104
|
|
101
|
-
Object.include(ActiveObject::Object) if ActiveObject
|
105
|
+
Object.include(ActiveObject::Object) if ActiveObject.configuration.autoload_object
|
data/lib/active_object/range.rb
CHANGED
@@ -1,34 +1,38 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
end
|
3
|
+
module ActiveObject
|
4
|
+
module Range
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
operator = exclude_end? && !other.exclude_end? ? :< : :<=
|
10
|
-
include?(other.first) && other.last.send(operator, last)
|
11
|
-
else
|
12
|
-
include?(other)
|
6
|
+
def combine(other)
|
7
|
+
to_a.concat(other.to_a)
|
13
8
|
end
|
14
|
-
end
|
15
9
|
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
def include_with_range?(other)
|
11
|
+
if other.is_a?(Range)
|
12
|
+
operator = exclude_end? && !other.exclude_end? ? :< : :<=
|
13
|
+
include?(other.first) && other.last.send(operator, last)
|
14
|
+
else
|
15
|
+
include?(other)
|
16
|
+
end
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def overlaps?(other)
|
20
|
+
cover?(other.first) || other.cover?(first)
|
21
|
+
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
def sample
|
24
|
+
to_a.sample
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
def shuffle
|
28
|
+
to_a.shuffle
|
29
|
+
end
|
31
30
|
|
31
|
+
def within?(other)
|
32
|
+
cover?(other.first) && cover?(other.last)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
|
-
Range.include(ActiveObject::Range) if ActiveObject
|
38
|
+
Range.include(ActiveObject::Range) if ActiveObject.configuration.autoload_range
|