junk_drawer 1.0.0 → 1.1.0

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: a0da0ad66a1221cb8d106b8364336f8039c09a6b
4
- data.tar.gz: 20f73f5ec1a8501aaca7429d099baa271cf14fc6
3
+ metadata.gz: 033f2ab3b77953431ed14a2e0cfdf6f0b7f8d80b
4
+ data.tar.gz: 0b1b9ddb51d43c0760585b915f8448719d8b6ea8
5
5
  SHA512:
6
- metadata.gz: 6f7b51bfb7acd57c1f433080fc473bfc49e603b02071f3757fc824b9f9ba3f1a773b8ef2d4892d50f8e3a08dca07097aece39f296f5584197d85ef3aa66b56c6
7
- data.tar.gz: 5dac68fde062e4e81d9f82a79138e00d0c21395349501e322b6599f365c714284555099feb2475afd34a61dfcbefa657bacb0dcfc3e482640f9f3913b5d3e911
6
+ metadata.gz: 452971946ec2297e949ce82a14805732ae35e1c5862d71681af2f35dd9ad287f8596c933caede70c45409f7b4c095888af3041968ebdd01a047b438ec3e0928d
7
+ data.tar.gz: 5f5d67af5ba7ddeed0e9a5dc0003a1af62123a30393796da18a1ad76b9e99a0c1c80873c6d1e5abbf8946f9e3da01b7e771fec6fba55ce53e87454ff3f7641b7
data/.rubocop.yml CHANGED
@@ -13,6 +13,9 @@ Metrics/BlockLength:
13
13
  RSpec/ExampleLength:
14
14
  Enabled: false
15
15
 
16
+ RSpec/MultipleExpectations:
17
+ Enabled: false
18
+
16
19
  # default disabled rules
17
20
  Style/AutoResourceCleanup:
18
21
  Enabled: true
data/README.md CHANGED
@@ -1,11 +1,7 @@
1
1
  # JunkDrawer
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to
4
- be able to package up your Ruby library into a gem. Put your Ruby code in the
5
- file `lib/junk_drawer`. To experiment with that code, run `bin/console` for an
6
- interactive prompt.
7
-
8
- TODO: Delete this and the text above, and describe your gem
3
+ `JunkDrawer` is a gem providing exactly one (and someday more) random utility
4
+ that is commonly useful across projects.
9
5
 
10
6
  ## Installation
11
7
 
@@ -25,7 +21,71 @@ Or install it yourself as:
25
21
 
26
22
  ## Usage
27
23
 
28
- TODO: Write usage instructions here
24
+ ### Callable
25
+
26
+ `JunkDrawer::Callable` is a module that provides constraints and conveniences
27
+ for objects that implement a single method `#call`. It comes with the
28
+ philosophy that objects that *do* something, should do only one thing. When including the `JunkDrawer::Callable` in one of your classes, you will get the following:
29
+
30
+ 1) It raises an error if you try to implement a public method other than
31
+ `#call`.
32
+
33
+ ```ruby
34
+ class Foo
35
+ include JunkDrawer::Callable
36
+ def bar # Bad: can't define public method "#bar"
37
+ end
38
+ end
39
+ ```
40
+
41
+ produces:
42
+
43
+ ```
44
+ JunkDrawer::CallableError: invalid method name bar, only public method allowed is "call"
45
+ ```
46
+
47
+ Private methods are fine:
48
+
49
+ ```ruby
50
+ class Foo
51
+ include JunkDrawer::Callable
52
+ private
53
+ def bar # private methods are okay!
54
+ end
55
+ end
56
+ ```
57
+
58
+ 2) It delegates `call` on the class to a new instance:
59
+
60
+ ```ruby
61
+ class Foo
62
+ include JunkDrawer::Callable
63
+ def call(stuff)
64
+ puts "I am a Foo! I've got #{stuff}"
65
+ end
66
+ end
67
+ ```
68
+
69
+ ```
70
+ > Foo.call('a brochure')
71
+ I am a Foo! I've got a brochure
72
+ > Foo.new.call('a brochure')
73
+ I am a Foo! I've got a brochure
74
+ ```
75
+
76
+ 3) It implements `to_proc`, both on the class and instance, allowing operations
77
+ such as:
78
+
79
+ ```
80
+ > ['puppies', 'a cold', 'cheeseburgers'].each(&Foo)
81
+ I am a Foo! I've got puppies
82
+ I am a Foo! I've got a cold
83
+ I am a Foo! I've got cheeseburgers
84
+ ```
85
+
86
+ See here for a great explanation of `to_proc` and the `&` operator:
87
+
88
+ http://www.brianstorti.com/understanding-ruby-idiom-map-with-symbol/
29
89
 
30
90
  ## Development
31
91
 
@@ -41,11 +101,10 @@ git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygem
41
101
  ## Contributing
42
102
 
43
103
  Bug reports and pull requests are welcome on GitHub at
44
- https://github.com/[USERNAME]/junk_drawer. This project is intended to be a
104
+ https://github.com/mockdeep/junk_drawer. This project is intended to be a
45
105
  safe, welcoming space for collaboration, and contributors are expected to
46
106
  adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
47
107
 
48
-
49
108
  ## License
50
109
 
51
110
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -10,6 +10,10 @@ module JunkDrawer
10
10
  raise NotImplementedError
11
11
  end
12
12
 
13
+ def to_proc
14
+ proc { |args| self.(*args) }
15
+ end
16
+
13
17
  # `ClassMethods` defines a class level method `call` that delegates to
14
18
  # an instance. It also causes an error to be raised if a public instance
15
19
  # method is defined with a name other than `call`
@@ -18,6 +22,10 @@ module JunkDrawer
18
22
  new.(*args)
19
23
  end
20
24
 
25
+ def to_proc
26
+ new.to_proc
27
+ end
28
+
21
29
  def method_added(method_name)
22
30
  return if method_name == :call || !public_method_defined?(method_name)
23
31
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module JunkDrawer
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: junk_drawer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fletcher
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-20 00:00:00.000000000 Z
11
+ date: 2016-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler