modifiers 1.1.0 → 2.0.2

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,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 1c529f23f0c4fe7d0417b298daabad35a18c98ba
4
- data.tar.gz: 4e26087e2b3d2a386417c3ae74bef0dfac9ef131
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ Yzc0Y2YyNjU3YjUyOTRjYWE1ZjcwMmQxZjFhN2FiNTgxNThiMjMwNg==
5
+ data.tar.gz: !binary |-
6
+ NGMyZTkyMzViNjM4NjUwYTE0ZWJmNmIxODg5ZjBhNmYzNzQyZmJiMw==
5
7
  SHA512:
6
- metadata.gz: 7cae095e6a838c2e06094242f883ad3bd18db3841bd931abee97dcd8b507990ad5a1e851d241b85ddfa1de3d90ab5a465aac3b5bed809a4830317405a2cab543
7
- data.tar.gz: b1649f83e589491f7da170b057be4121be762efc592f06cb7c228c92a2d2d3e74a871859b5cc2b6b80b777976f575b16d7c688e7c901699dbf8ddfef314ef183
8
+ metadata.gz: !binary |-
9
+ ZDIxNDVmYTFmNzY0ODQ3YWRkMjljOWZkNjk4Mjg0YTZmOTE4ZDZlY2RiZjUw
10
+ NDBkZjFiNmRiYzk3ODM4MTA3MTQzNmU1M2VlMmY3NTVjNTYyZGUwNzU1MTU0
11
+ NDEzOTM2MmQ1MDQyMDE0ZjczNTg4MWNiNGNiNmZmNWQ4Y2JkN2U=
12
+ data.tar.gz: !binary |-
13
+ NzcwMjZmNTA5MzJhYTdhMWM2MDM2NGM2OTQ5YzliZWNlZmVmM2Y1MGFmY2Ux
14
+ MDNkMDYyNjAyM2UxZGZlNGZlY2NkMmQ1YWY0ZDVlZjg1OTYxMzIxMTg1ZWRk
15
+ MTM3NzYxMjM3YzUzY2I4NTRiZTc5NDQ1NDZkYzhjNTZlNmVhMjc=
@@ -0,0 +1,6 @@
1
+ inherit_from: .rubocop_todo.yml
2
+ Metrics/LineLength:
3
+ Max: 120
4
+ Style/Documentation:
5
+ Exclude:
6
+ - spec/**/*.rb
@@ -0,0 +1,10 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2014-09-20 01:40:17 +0000 using RuboCop version 0.26.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 11
9
+ Style/Documentation:
10
+ Enabled: false
@@ -1,12 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
4
- - 2.1.0
5
- - 2.1.1
6
- - 2.1.2
3
+ - 2.0.0
4
+ - 2.1.5
7
5
  deploy:
8
6
  provider: rubygems
9
7
  api_key:
10
- secure: fewAgjCXLYSkbRq57EQYRTjwPn/LfQgpvSh1HBdVG1Vjds2OCL+yl3d6x30o4q28GU7dMLKjEl2BZrrQ9TwPgit3LRPUwlsoZRvGQj+oztdNfshpWansne6coBYa5vx/tQFBSDWkTMdE2RMH1w7qP20Iqn44c4yQU1tQiqWoZMQ=
8
+ secure: ZPeXm1QrIHsDx+ltW0aQ5mKK2vdeRHiHltBHO+KnnWMygHmeoe4ophwQetUhee/oH1LL9W1KdpLc+tSvt64PN0WooMdJtsbOA7M3DLOZGSrqNtTHM3b0xcLrQFIg8wLKDlp/0jx4xUFHybCIapsXT2N+Q8EdgtiS1lwRKEcN44I=
9
+ gem: modifiers
11
10
  on:
12
11
  tags: true
12
+ repo: nicknovitski/modifiers
13
+ all_branches: true
data/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Modifiers
2
- [![Build Status](https://travis-ci.org/nicknovitski/modifiers.svg?branch=master)](https://travis-ci.org/nicknovitski/modifiers)
2
+ [![Build Status](https://travis-ci.org/nicknovitski/modifiers.svg?branch=master)](https://travis-ci.org/nicknovitski/modifiers) [![Code Climate](https://codeclimate.com/github/nicknovitski/modifiers/badges/gpa.svg)](https://codeclimate.com/github/nicknovitski/modifiers)
3
3
 
4
4
  ## What is/are Modifiers?
5
5
 
6
- `Modifiers` is a collection of method modifiers, and a way to make more.
6
+ `modifiers` is a collection of **method modifiers**, and a way to make more.
7
7
 
8
- _Method Modifiers_, obviously, modify methods. Specifically, in Ruby
8
+ Method modifiers, obviously, modify methods. Specifically, in Ruby
9
9
  terms, they are class methods which:
10
10
 
11
11
  1. Take a symbol argument which names an instance method of the same class, _and_
@@ -27,10 +27,10 @@ end
27
27
  ```
28
28
 
29
29
  This method is quite small, but it still complects the concerns of counting
30
- ducks and of saving and reusing the result of a calculation, and that latter
31
- concern might be repeated any number of times in your codebase.
30
+ ducks with that of saving and reusing the result of a calculation, and that latter
31
+ concern might be duplicated any number of times across your codebase.
32
32
 
33
- With modifiers, we can encapsulate the implementation of the memoization, and
33
+ With `modifiers`, you can encapsulate the implementation of the memoization, and
34
34
  keep the intent:
35
35
  ```ruby
36
36
  def count_ducks
@@ -67,7 +67,7 @@ And then execute:
67
67
 
68
68
  ## Usage
69
69
 
70
- ### built-in modifiers
70
+ ### built-in method modifiers
71
71
 
72
72
  #### memoized
73
73
 
@@ -135,12 +135,12 @@ no side-effects.
135
135
  It may or may not be a good idea, but at least now it's easy to unambiguously
136
136
  indicate and enforce!
137
137
 
138
- First, a method modified by `command` will always return nil. It's as trivial as it
139
- sounds.
138
+ First, a method modified by `command` will always return `self`. It's as
139
+ trivial as it sounds.
140
140
 
141
- Conversely (?), a method modified by `query` will never change the state of
142
- anything non-global and in-process. This is also trivial, but it might seem
143
- more impressive.
141
+ Conversely (TODO: find out if this is actually what converse means), a method
142
+ modified by `query` will never change the state of anything non-global and
143
+ in-process. This is also trivial, but it might seem more impressive.
144
144
 
145
145
  ```ruby
146
146
  require 'modifiers/command_query'
@@ -169,14 +169,14 @@ john = DuckFarmer.new(Array.new(3) { DuckHutch.new(rand(20)) })
169
169
 
170
170
  john.fullest_hutch # => #<struct DuckHutch num_eggs=11>
171
171
 
172
- john.hutches.any? { |h| h.ducks_disturbed? } # => false
172
+ john.hutches.any?(&:ducks_disturbed?) # => false
173
173
  ```
174
174
 
175
175
  If this was an infomercial, now is when I would say something like "It's just
176
176
  that easy, Michael!", and you (your name is Michael in this scenario) would say
177
177
  "Now _that's_ incredible!" and the audience would applaud.
178
178
 
179
- ### defining new modifiers
179
+ ### defining new method modifiers
180
180
 
181
181
  New modifiers can be defined in your own modules using the `define_modifier` method.
182
182
 
@@ -203,18 +203,20 @@ end
203
203
  ```
204
204
 
205
205
  Much as with `define_method`, the first argument to `define_modifier` gives us
206
- the name of the new modifier, and the block gives us the implementation of a
207
- given *modification*: a method which intercepts calls to the original method
208
- (in this case, `DuckFarm#farm`), does whatever it likes, then invokes the
209
- original method using `super`.
206
+ the name of the new method modifier, and the block gives us the implementation
207
+ of a given **modification**: a method which intercepts calls to the original
208
+ method (in this case, `DuckFarm#farm`), does whatever it likes, then invokes
209
+ that original method using `super`.
210
210
 
211
- (Sadly, just as with `define_method`, you have to use explicit arguments when
212
- calling `super`. Sorry, doing otherwise involved too much oddity.)
211
+ Sadly, just as with `define_method`, you have to use explicit arguments when
212
+ calling `super`. I genuinely and sincerely apologize for this leaky abstraction,
213
+ and wish I knew a way to optimize for the common case of just calling through with
214
+ unchanged arguments without adding significant implementation complexity.
213
215
 
214
- But maybe you don't want to call the original method at all!
216
+ But hey, maybe I'm lucky and you don't want to call the original method at all!
215
217
  ```ruby
216
218
  module DuckFarmModifiers
217
- define_modifier(:x) { }
219
+ define_modifier(:disabled) { }
218
220
  end
219
221
  ```
220
222
 
@@ -225,8 +227,10 @@ module DuckFarmModifiers
225
227
  super(*args.map(&:to_i), &block)
226
228
  end
227
229
  end
230
+ ```
228
231
 
229
- You can do things before, after, or even "around" the invocation.
232
+ You can do things before, after, or even "around" the invocation; It's
233
+ Just Ruby®!
230
234
  ```ruby
231
235
  module DuckFarmModifiers
232
236
  define_modifier(:perf_logged) do |*args, &block|
@@ -237,7 +241,7 @@ module DuckFarmModifiers
237
241
  end
238
242
  ```
239
243
 
240
- ### Extending modifiers
244
+ ### Extending method modifiers
241
245
 
242
246
  The body of a modifier will be evaluated in the context of the receiver
243
247
  instance of the modified method, so you can refer to any other instance
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require 'bundler/gem_tasks'
2
1
  require 'rspec/core/rake_task'
2
+ require 'rubocop/rake_task'
3
+
4
+ RuboCop::RakeTask.new
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task default: :spec
8
+ task default: %i(rubocop spec)
@@ -3,6 +3,6 @@ require 'modifiers/define_modifier'
3
3
  module Modifiers
4
4
  define_modifier(:command) do |*args, &block|
5
5
  super(*args, &block)
6
- nil
6
+ self
7
7
  end
8
8
  end
@@ -9,10 +9,10 @@ module Modifiers
9
9
  end
10
10
 
11
11
  def duplicate_ivars!
12
- ivars_hash.each { |k,v| instance_variable_set(k, Marshal.load(Marshal.dump(v))) }
12
+ ivars_hash.each { |k, v| instance_variable_set(k, Marshal.load(Marshal.dump(v))) }
13
13
  end
14
14
 
15
- def set_ivars(hash)
15
+ def reset_ivars(hash)
16
16
  hash.each { |k, v| instance_variable_set(k, v) }
17
17
 
18
18
  in_state_but_not_hash = instance_variables.select { |i| hash[i].nil? }
@@ -24,7 +24,7 @@ module Modifiers
24
24
  orig_ivars = ivars_hash
25
25
  duplicate_ivars!
26
26
  return_value = super(*args, &block)
27
- set_ivars(orig_ivars)
27
+ reset_ivars(orig_ivars)
28
28
  return_value
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Modifiers
2
- VERSION = '1.1.0'
2
+ VERSION = '2.0.2'
3
3
  end
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.required_ruby_version = '>= 2.0.0'
21
21
 
22
- spec.add_development_dependency 'bundler', '~> 1.6'
22
+ spec.add_development_dependency 'bundler', '~> 1.7'
23
23
  spec.add_development_dependency 'rake'
24
- spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency 'rspec'
25
+ spec.add_development_dependency 'rubocop'
25
26
  end
@@ -16,8 +16,8 @@ RSpec.describe Modifiers do
16
16
  describe '#command' do
17
17
  it_behaves_like 'a modifier', :command, changes_return_value: true
18
18
 
19
- it 'causes the method to always return nil' do
20
- expect(doer.take_action).to be_nil
19
+ it 'causes the method to always return the receiver' do
20
+ expect(doer.take_action).to be doer
21
21
  end
22
22
  end
23
23
  end
@@ -29,7 +29,7 @@ class Foo
29
29
  bro :hello
30
30
 
31
31
  def poot
32
- "I accidentally typed the name of this method but I think it's great"
32
+ "I accidentally typed the name of this method but I think it's great"
33
33
  end
34
34
  timed :poot
35
35
  end
@@ -3,7 +3,7 @@ require 'modifiers/deprecated'
3
3
 
4
4
  RSpec.describe Modifiers do
5
5
  describe '#deprecated' do
6
- context "with silenced warnings" do
6
+ context 'with silenced warnings' do
7
7
  around(:example) do |example|
8
8
  old_verbose, $VERBOSE = $VERBOSE, nil
9
9
  example.call
@@ -32,6 +32,7 @@ RSpec.describe Modifiers do
32
32
  def initialize
33
33
  @state_changes = []
34
34
  end
35
+
35
36
  def status
36
37
  @state_changes << :awake
37
38
  end
@@ -1,6 +1,6 @@
1
1
  RSpec.shared_examples 'a modifier' do |modifier, changes_return_value: false|
2
2
  let(:test_class) do
3
- klass = Class.new do
3
+ Class.new do
4
4
  extend Modifiers
5
5
 
6
6
  def public_method(arg = :foo)
@@ -19,9 +19,7 @@ RSpec.shared_examples 'a modifier' do |modifier, changes_return_value: false|
19
19
  #
20
20
  end
21
21
  end
22
- Object.const_set(random_class_name, klass)
23
22
  end
24
- let(:random_class_name) { (0...10).map { ('A'..'Z').to_a[rand(26)] }.join }
25
23
  subject(:instance) { test_class.new }
26
24
 
27
25
  it 'returns the symbol it is passed' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modifiers
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Novitski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2014-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,40 +16,54 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ! '>='
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
55
69
  description: A simple and composable way to add functionality to methods.
@@ -61,6 +75,8 @@ extra_rdoc_files: []
61
75
  files:
62
76
  - .gitignore
63
77
  - .rspec
78
+ - .rubocop.yml
79
+ - .rubocop_todo.yml
64
80
  - .travis.yml
65
81
  - Gemfile
66
82
  - LICENSE.txt
@@ -93,17 +109,17 @@ require_paths:
93
109
  - lib
94
110
  required_ruby_version: !ruby/object:Gem::Requirement
95
111
  requirements:
96
- - - '>='
112
+ - - ! '>='
97
113
  - !ruby/object:Gem::Version
98
114
  version: 2.0.0
99
115
  required_rubygems_version: !ruby/object:Gem::Requirement
100
116
  requirements:
101
- - - '>='
117
+ - - ! '>='
102
118
  - !ruby/object:Gem::Version
103
119
  version: '0'
104
120
  requirements: []
105
121
  rubyforge_project:
106
- rubygems_version: 2.0.14
122
+ rubygems_version: 2.4.2
107
123
  signing_key:
108
124
  specification_version: 4
109
125
  summary: Cute and Easy method modifiers (also called decorators)