catchy 0.1.1 → 0.1.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 +8 -8
- data/README.md +17 -3
- data/lib/catchy.rb +14 -5
- data/lib/catchy/configuration.rb +9 -0
- data/lib/catchy/method_chain.rb +15 -8
- data/lib/catchy/version.rb +1 -1
- data/spec/lib/catchy/method_chain_spec.rb +10 -10
- data/spec/lib/catchy_spec.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODUzYmI1MDgyNmQyNjA1MTFkM2QwODYwY2JhYzNjNTJiYzNjOTVhOA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZTM1OTc0ZjAxYmEyZmUzYjk4YzExZTMyMDY5ZTgzNGUzMTg2NjI3ZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YmFhOTFjMjc3NjllOTNiOTBmZTNmMmM2NTdkNmJiNjg0OTE3Y2MyZTI4YmJm
|
10
|
+
NmY5NTI5NGYyMGFiMTVkZDhhMzg3N2NiNDdhZjk4NTM0Nzg3MjJkZDhmYmQ1
|
11
|
+
YTg4M2VkMzExYmJiODBiOTM3MmIwM2I2YTY3ZTUyNDMxODQyYzQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OTZhMTAzNjllYjM4Yzk2ZTNjMjkzZjEwMzFiOWFkMDJmMjAzNjUzZTFjNzcz
|
14
|
+
ZDZmZjQ4MDMyMGNhOThjNzZmZDNlZTMyOGExMzgxNDVkYjA0M2FjMWYyMzYw
|
15
|
+
MjljMTg4MWM1MzkxODM4NTY5N2JlNTdlN2IzZDVmMDExZTg0Yzk=
|
data/README.md
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
catchy: Instantly appealing and memorable, a gem to capture chains of method calls.
|
4
4
|
|
5
|
-
[](https://travis-ci.org/my-codeworks/catchy)
|
6
5
|
[](http://badge.fury.io/rb/catchy)
|
6
|
+
[](https://travis-ci.org/my-codeworks/catchy)
|
7
7
|
[](https://codeclimate.com/github/my-codeworks/catchy)
|
8
8
|
|
9
9
|
## Installation
|
@@ -39,7 +39,21 @@ Then you can get the chain of called methods as a string:
|
|
39
39
|
|
40
40
|
proxy = Catchy.new(to_s: :__to_string__)
|
41
41
|
|
42
|
-
|
42
|
+
or with a config block, handy for a Rails initializer or similar, like this:
|
43
|
+
|
44
|
+
# config/initializers/catchy.rb
|
45
|
+
Catchy.configure do |config|
|
46
|
+
config.to_s = :__to_string__
|
47
|
+
end
|
48
|
+
|
49
|
+
# app/whatever/class.rb
|
50
|
+
proxy = Catchy.new
|
51
|
+
|
52
|
+
Then you can use it like this:
|
53
|
+
|
54
|
+
proxy.call.whatever.you.want.to_s
|
55
|
+
...
|
56
|
+
proxy.__to_string__
|
43
57
|
|
44
58
|
## Contributing
|
45
59
|
|
@@ -51,4 +65,4 @@ Then you can
|
|
51
65
|
|
52
66
|
## Special thanks
|
53
67
|
|
54
|
-
To Hüseyin Öztürk for suggesting the name. Originally the gem was called MethodChainProxy, but mr Öztürk found it less than sexy and suggested: "something funny and relevant, catchy ..." so there we where, Catchy. Exellent work!
|
68
|
+
To [Hüseyin Öztürk](https://github.com/hsyn) for suggesting the name. Originally the gem was called MethodChainProxy, but mr Öztürk found it less than sexy and suggested: "something funny and relevant, catchy ..." so there we where, Catchy. Exellent work!
|
data/lib/catchy.rb
CHANGED
@@ -1,14 +1,23 @@
|
|
1
1
|
require 'catchy/version'
|
2
|
+
require 'catchy/configuration'
|
2
3
|
require 'catchy/method_chain'
|
3
4
|
|
4
5
|
module Catchy
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def new( *args )
|
10
|
+
MethodChain.new( *args )
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
|
17
|
+
def configuration
|
18
|
+
@configuration ||= Configuration.new
|
19
|
+
end
|
9
20
|
|
10
|
-
def self.new( *args )
|
11
|
-
MethodChain.new( *args )
|
12
21
|
end
|
13
22
|
|
14
23
|
end
|
data/lib/catchy/method_chain.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
class Catchy::MethodChain
|
2
2
|
|
3
3
|
def initialize( options = {} )
|
4
|
-
|
5
|
-
|
4
|
+
configure( options )
|
5
|
+
define_methods
|
6
6
|
@method_chain = []
|
7
7
|
end
|
8
8
|
|
@@ -13,14 +13,21 @@ class Catchy::MethodChain
|
|
13
13
|
|
14
14
|
private
|
15
15
|
|
16
|
-
def
|
17
|
-
|
16
|
+
def configure( options )
|
17
|
+
return if options.empty?
|
18
|
+
Catchy.configure do |config|
|
19
|
+
options.each do |name, value|
|
20
|
+
config.send("#{name}=", value)
|
21
|
+
end
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
|
-
def
|
21
|
-
self.class.send( :define_method,
|
22
|
-
|
23
|
-
|
25
|
+
def define_method( name, &block)
|
26
|
+
self.class.send( :define_method, name, &block )
|
27
|
+
end
|
28
|
+
|
29
|
+
def define_methods
|
30
|
+
define_method( Catchy.configuration.to_s ){ @method_chain.join('.') }
|
24
31
|
end
|
25
32
|
|
26
33
|
end
|
data/lib/catchy/version.rb
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'catchy
|
2
|
+
require 'catchy'
|
3
3
|
|
4
4
|
describe Catchy::MethodChain do
|
5
5
|
|
6
6
|
context "basic use" do
|
7
|
-
describe "initialization" do
|
8
|
-
subject { Catchy.new() }
|
9
|
-
it { should_not be_nil }
|
10
|
-
end
|
11
|
-
|
12
7
|
describe "returns a method chain proxy when called" do
|
13
|
-
subject { Catchy.new
|
8
|
+
subject { Catchy.new.whatever.class }
|
14
9
|
it { should == Catchy::MethodChain }
|
15
10
|
end
|
16
11
|
|
17
12
|
describe "to_s yields chained calls" do
|
18
|
-
subject { Catchy.new
|
13
|
+
subject { Catchy.new.can.be.called.by.whatever.to_s }
|
19
14
|
it { should == 'can.be.called.by.whatever' }
|
20
15
|
end
|
21
16
|
end
|
22
17
|
|
23
|
-
context "
|
24
|
-
describe "overriding default to_s method name" do
|
18
|
+
context "customized behaviour" do
|
19
|
+
describe "overriding default to_s method name with initializer" do
|
25
20
|
subject { Catchy.new(to_s: :__to_s).can.be.called.by.whatever.__to_s }
|
26
21
|
it { should == 'can.be.called.by.whatever' }
|
27
22
|
end
|
23
|
+
|
24
|
+
describe "overriding default to_s method name with configure block" do
|
25
|
+
subject { Catchy.configure{|config| config.to_s = :__to_s}; Catchy.new.can.be.called.by.whatever.__to_s }
|
26
|
+
it { should == 'can.be.called.by.whatever' }
|
27
|
+
end
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
data/spec/lib/catchy_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: catchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonas Schubert Erlandsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- Rakefile
|
84
84
|
- catchy.gemspec
|
85
85
|
- lib/catchy.rb
|
86
|
+
- lib/catchy/configuration.rb
|
86
87
|
- lib/catchy/method_chain.rb
|
87
88
|
- lib/catchy/version.rb
|
88
89
|
- spec/lib/catchy/method_chain_spec.rb
|