flap 0.1.1 → 0.2.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 +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/flap/version.rb +1 -1
- data/lib/flap.rb +54 -1
- data/spec/flap_spec.rb +51 -9
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 218548f3e588ea9a8844809b21ce70319d829df2
|
4
|
+
data.tar.gz: f0c0a639432afc042a933b772bb1e27ce92e0e08
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c089770e5798a98609e2d757083951102ce5993fbf9727873845f202d8add950d49865a4a991909441e3e25ca5646164c0d1345439164c199a587960c15fe9c4
|
7
|
+
data.tar.gz: 4eefb23fbb54a134300c839a617aac17996d7c6c34a735eee6b75315e0962d963bd77aed07417a07e229dee7f93188170dae6df715fb3bf3c7ec3b1a993749e6
|
data/CHANGELOG.md
CHANGED
data/lib/flap/version.rb
CHANGED
data/lib/flap.rb
CHANGED
@@ -1,10 +1,63 @@
|
|
1
1
|
require "flap/version"
|
2
2
|
|
3
3
|
module Flap
|
4
|
-
def
|
4
|
+
def self.included(base)
|
5
|
+
Module.__send__ :include, ModuleMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
# Public: tap + instance_eval
|
9
|
+
#
|
10
|
+
# block - call in receiver's context
|
11
|
+
#
|
12
|
+
# Examples
|
13
|
+
# hash = {a: 1, b: 2}
|
14
|
+
# hash.instance_tap_eval { delete :a } #=> {:b => 2}
|
15
|
+
#
|
16
|
+
# Returns self
|
17
|
+
def instance_tap_eval(&block)
|
5
18
|
self.instance_eval &block if block_given?
|
6
19
|
self
|
7
20
|
end
|
21
|
+
|
22
|
+
# Deprecated: same as instance_tap_eval
|
23
|
+
def flap(&block)
|
24
|
+
warn "[deprecated] this method will be removed."
|
25
|
+
instance_tap_eval &block
|
26
|
+
end
|
27
|
+
|
28
|
+
module ModuleMethods
|
29
|
+
# Public: tap + class_eval
|
30
|
+
#
|
31
|
+
# block - call in class context
|
32
|
+
#
|
33
|
+
# Examples
|
34
|
+
# Klass = Class.new.class_tap_eval { include Awesome }
|
35
|
+
# Klass.new.awesome_method
|
36
|
+
#
|
37
|
+
# Returns self
|
38
|
+
def class_tap_eval(&block)
|
39
|
+
class_eval &block if block_given?
|
40
|
+
self
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Public: define alias methods itap/ctap.
|
45
|
+
#
|
46
|
+
# Returns self
|
47
|
+
def self.enable_short_methods!
|
48
|
+
Object.__send__ :include, ShortMethods
|
49
|
+
end
|
50
|
+
|
51
|
+
module ShortMethods
|
52
|
+
def self.included(base)
|
53
|
+
base.class_eval do
|
54
|
+
alias_method :itap, :instance_tap_eval
|
55
|
+
Module.class_eval do
|
56
|
+
alias_method :ctap, :class_tap_eval
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
8
61
|
end
|
9
62
|
|
10
63
|
Object.__send__ :include, Flap
|
data/spec/flap_spec.rb
CHANGED
@@ -1,19 +1,61 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Flap do
|
4
|
-
|
5
|
-
|
4
|
+
shared_examples_for "xxx_tap_eval" do
|
5
|
+
it "has method" do
|
6
|
+
expect(subject).to respond_to(meth)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "returns self" do
|
10
|
+
expect(subject.public_send(meth)).to eql subject
|
11
|
+
end
|
12
|
+
|
13
|
+
it "block binded self context" do
|
14
|
+
ret = nil
|
15
|
+
subject.public_send(meth) { ret = self }
|
16
|
+
expect(ret).to eql subject
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "instance_tap_eval" do
|
21
|
+
subject { Object.new }
|
22
|
+
let(:meth) { :instance_tap_eval }
|
23
|
+
it_behaves_like "xxx_tap_eval"
|
6
24
|
end
|
7
25
|
|
8
|
-
|
26
|
+
describe "class_tap_eval" do
|
27
|
+
subject { Module }
|
28
|
+
let(:meth) { :class_tap_eval }
|
29
|
+
it_behaves_like "xxx_tap_eval"
|
30
|
+
end
|
31
|
+
|
32
|
+
describe ".enable_short_methods!" do
|
33
|
+
before do
|
34
|
+
Flap.enable_short_methods!
|
35
|
+
end
|
9
36
|
|
10
|
-
|
11
|
-
|
37
|
+
it "Object has :itap instance method" do
|
38
|
+
expect(Object.new).to respond_to(:itap)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "Module has :ctap class method" do
|
42
|
+
expect(Module).to respond_to(:ctap)
|
43
|
+
end
|
12
44
|
end
|
13
45
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
46
|
+
context "deprecated" do
|
47
|
+
let(:meth) { :flap }
|
48
|
+
it_behaves_like "xxx_tap_eval"
|
49
|
+
|
50
|
+
it "shows deprecated message" do
|
51
|
+
begin
|
52
|
+
original = $stderr
|
53
|
+
$stderr = result = StringIO.new
|
54
|
+
flap
|
55
|
+
expect(result.string).to match("deprecated")
|
56
|
+
ensure
|
57
|
+
$stderr = original
|
58
|
+
end
|
59
|
+
end
|
18
60
|
end
|
19
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomohiro Nishimura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|