catchy 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjQyMzYzNzE1MzAzZmYwNDgyMDNlZGUzNzg4ZDc4NDcxZWIxZDhmOA==
4
+ ODUzYmI1MDgyNmQyNjA1MTFkM2QwODYwY2JhYzNjNTJiYzNjOTVhOA==
5
5
  data.tar.gz: !binary |-
6
- OWU3NDZiNmFkNTNhYjZmZDhjZmYzZDhiNTRlZWY0YWI5OTYyZDNlZA==
6
+ ZTM1OTc0ZjAxYmEyZmUzYjk4YzExZTMyMDY5ZTgzNGUzMTg2NjI3ZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NzI5ZTZhMjBlN2M3NzdkMWEwNWQ0MWYyZWEyZjJmMTE4MDdmNDdjYjhjOWMx
10
- ZTUzYjE4NDNkMzFjZWE5NDQ5MWYxZDc1OGI5MjdhNzM1MjAwZThkYjRkYTJh
11
- YWYyNDEwYzRkYzM4MGY0YmY5Mjg5OGRjZTg5YjJhMjA3NTViNGE=
9
+ YmFhOTFjMjc3NjllOTNiOTBmZTNmMmM2NTdkNmJiNjg0OTE3Y2MyZTI4YmJm
10
+ NmY5NTI5NGYyMGFiMTVkZDhhMzg3N2NiNDdhZjk4NTM0Nzg3MjJkZDhmYmQ1
11
+ YTg4M2VkMzExYmJiODBiOTM3MmIwM2I2YTY3ZTUyNDMxODQyYzQ=
12
12
  data.tar.gz: !binary |-
13
- ZjcyMDU0MjY4ZGNhZjRjMjFkOTJjZmQ5ZDFjMWE0MTJkZjVkNDhjY2EzYTFk
14
- YWI0MjBjYTRiZjUyNmU5ZWUwNjEyMDBkMzFlMmE2MzZkNGU3MTA1ZTFiYjM1
15
- YzA1ZTAwOTM1NDZkZGI4ODJiM2I0ZWE0MWYyZWQyYjAxMjc3YmM=
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
- [![Build Status](https://travis-ci.org/my-codeworks/catchy.png)](https://travis-ci.org/my-codeworks/catchy)
6
5
  [![Gem Version](https://badge.fury.io/rb/catchy.png)](http://badge.fury.io/rb/catchy)
6
+ [![Build Status](https://travis-ci.org/my-codeworks/catchy.png)](https://travis-ci.org/my-codeworks/catchy)
7
7
  [![Code Climate](https://codeclimate.com/github/my-codeworks/catchy.png)](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
- Then you can
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
- DEFAULT_OPTIONS = {
7
- to_s: :to_s,
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
@@ -0,0 +1,9 @@
1
+ class Catchy::Configuration
2
+
3
+ attr_accessor :to_s
4
+
5
+ def initialize
6
+ @to_s = :to_s
7
+ end
8
+
9
+ end
@@ -1,8 +1,8 @@
1
1
  class Catchy::MethodChain
2
2
 
3
3
  def initialize( options = {} )
4
- options = Catchy::DEFAULT_OPTIONS.merge( options )
5
- define_accessors( options )
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 define_accessors( options )
17
- define_to_string_as( options[:to_s] )
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 define_to_string_as( to_s_name )
21
- self.class.send( :define_method, to_s_name ) do
22
- @method_chain.join('.')
23
- end
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
@@ -1,3 +1,3 @@
1
1
  module Catchy
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,30 +1,30 @@
1
1
  require 'spec_helper'
2
- require 'catchy/method_chain'
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().whatever.class }
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().can.be.called.by.whatever.to_s }
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 "customizing behaviour" do
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
@@ -3,4 +3,16 @@ require 'catchy'
3
3
 
4
4
  describe Catchy do
5
5
 
6
+ describe "instanziation" do
7
+
8
+ it "works" do
9
+ Catchy.new.should_not be_nil
10
+ end
11
+
12
+ it "provides default configuration" do
13
+ Catchy.configuration.should_not be_nil
14
+ end
15
+
16
+ end
17
+
6
18
  end
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.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-03 00:00:00.000000000 Z
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