darthjee-core_ext 1.5.2 → 1.5.3

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: f4e412855a254f3c8334a1485327c880be5bbf9c
4
- data.tar.gz: 676209baf8fe045c8824eebad20d570881087a35
3
+ metadata.gz: b584506156a0622988d8fe4b00681f318ebc9660
4
+ data.tar.gz: 3f554744e539f3440408f9d971bdd45b5dbf24f5
5
5
  SHA512:
6
- metadata.gz: 7688e35d2cc25b0001e617cd484a6e6f1251bc3e5c6c5958b1662d571ad940ab2467780211fbb9609e9ace834cc37e03a6e68c029fffa571847bddb48cf8e40e
7
- data.tar.gz: c6dbd9bc92839a16f158571599d3d1aced950f1973fb04dd0902254f82066b9b9c1fb2a4dfb869196d78cecafb7ef6e542eabe73c7464f59ddef9456e77d0fca
6
+ metadata.gz: 428fc4e08889758330f638d25299cb5b26aee30cf284b3e7fcf548872e972e59dc27f61a69d753ec845e32ae4be0a17c0134ffcc3b7629632d0ceb91caf67d1a
7
+ data.tar.gz: b2fd1bac68f74aeabe0a4e0095c0d1db5a5364e0ea36cb3929c79f9633f110cfb465965fb01f661f85ec0879da0a02fd3d6805acc293bfff836922ff69538ca7
data/OBJECT_README.md ADDED
@@ -0,0 +1,50 @@
1
+ ## Object
2
+
3
+ ### .default_value
4
+ Adds a method with default value
5
+
6
+ ```ruby
7
+ class TheClass
8
+ default_value :the_method, 10
9
+ end.new.the_method
10
+ ```
11
+
12
+ will return
13
+
14
+ ```ruby
15
+ 10
16
+ ```
17
+
18
+ ### .default_values
19
+ Add several methods with single return value
20
+
21
+ ```ruby
22
+ class TheIntermediateChild < TheParent
23
+ default_values :is_child?, :is_final?, true
24
+ end.new.is_child?
25
+ ```
26
+
27
+ will return
28
+
29
+ ```ruby
30
+ true
31
+ ```
32
+
33
+ ### #is_any?
34
+ returns if the object is an instance of any of the given classes
35
+
36
+ ```ruby
37
+ 1.is_any?(String, Symbol)
38
+ ```
39
+ returns
40
+ ```ruby
41
+ false
42
+ ```
43
+
44
+ ```ruby
45
+ 1.is_any?(String, Symbol, Numeric)
46
+ ```
47
+ returns
48
+ ```ruby
49
+ false
50
+ ```
data/README.md CHANGED
@@ -36,3 +36,5 @@ bundle install darthjee-core_ext
36
36
  [ENUMERABLE_README.md](ENUMERABLE_README.md)
37
37
  ## Date
38
38
  [DATE_README.md](DATE_README.md)
39
+ ## Object
40
+ [OBJECT_README.md](OBJECT_README.md)
@@ -0,0 +1,16 @@
1
+ class Object
2
+ class << self
3
+ private
4
+
5
+ def default_value(name, value)
6
+ define_method(name) { |*_| value }
7
+ end
8
+
9
+ def default_values(*names, value)
10
+ names.each do |name|
11
+ default_value(name, value)
12
+ end
13
+ end
14
+ end
15
+ end
16
+
@@ -1,3 +1,5 @@
1
+ require 'darthjee/core_ext/object/default_value'
2
+
1
3
  class Object
2
4
  def is_any?(*classes)
3
5
  classes.any? do |clazz|
@@ -1,5 +1,5 @@
1
1
  module Darthjee
2
2
  module CoreExt
3
- VERSION = '1.5.2'
3
+ VERSION = '1.5.3'
4
4
  end
5
5
  end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+ describe '.default_value' do
5
+ subject { DefaultValue.new }
6
+
7
+ it 'accepts default value' do
8
+ expect(subject.x).to eq(10)
9
+ end
10
+
11
+ it do
12
+ expect(Object).not_to respond_to(:default_value)
13
+ end
14
+ end
15
+
16
+ describe '.default_values' do
17
+ subject { DefaultValue.new }
18
+
19
+ it 'accepts default values' do
20
+ expect(subject.y).to eq(20)
21
+ end
22
+
23
+ it 'accepts default values' do
24
+ expect(subject.z).to eq(20)
25
+ end
26
+
27
+ it do
28
+ expect(Object).not_to respond_to(:default_values)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ class DefaultValue
2
+ default_value :x, 10
3
+ default_values :y, :z, 20
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: darthjee-core_ext
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.2
4
+ version: 1.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Darthjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-07 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: activesupport
@@ -137,6 +137,7 @@ files:
137
137
  - Gemfile
138
138
  - HASH_README.md
139
139
  - LICENSE
140
+ - OBJECT_README.md
140
141
  - README.md
141
142
  - Rakefile
142
143
  - SYMBOL_README.md
@@ -155,6 +156,7 @@ files:
155
156
  - lib/darthjee/core_ext/hash/value_changer.rb
156
157
  - lib/darthjee/core_ext/numeric.rb
157
158
  - lib/darthjee/core_ext/object.rb
159
+ - lib/darthjee/core_ext/object/default_value.rb
158
160
  - lib/darthjee/core_ext/symbol.rb
159
161
  - lib/darthjee/core_ext/time.rb
160
162
  - lib/darthjee/core_ext/version.rb
@@ -165,10 +167,12 @@ files:
165
167
  - spec/lib/hash/key_changer_spec.rb
166
168
  - spec/lib/hash_spec.rb
167
169
  - spec/lib/numeric_spec.rb
170
+ - spec/lib/object/default_value_spe.rb
168
171
  - spec/lib/object_spec.rb
169
172
  - spec/lib/symbol_spec.rb
170
173
  - spec/lib/time_spec.rb
171
174
  - spec/spec_helper.rb
175
+ - spec/support/models/default_value.rb
172
176
  - spec/support/models/hash/value_changer/dummy.rb
173
177
  - spec/support/models/hash/value_changer/dummy_iteractor.rb
174
178
  - spec/support/shared_examples/array_random.rb
@@ -216,10 +220,12 @@ test_files:
216
220
  - spec/lib/hash/key_changer_spec.rb
217
221
  - spec/lib/hash_spec.rb
218
222
  - spec/lib/numeric_spec.rb
223
+ - spec/lib/object/default_value_spe.rb
219
224
  - spec/lib/object_spec.rb
220
225
  - spec/lib/symbol_spec.rb
221
226
  - spec/lib/time_spec.rb
222
227
  - spec/spec_helper.rb
228
+ - spec/support/models/default_value.rb
223
229
  - spec/support/models/hash/value_changer/dummy.rb
224
230
  - spec/support/models/hash/value_changer/dummy_iteractor.rb
225
231
  - spec/support/shared_examples/array_random.rb