catchy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YWYxMWU2ZWU0YWRhNWVkOGQ2MjBhYjBhNjI1NDcyNDcyZDJkOTg4YQ==
5
+ data.tar.gz: !binary |-
6
+ YWQwMTIxNzAzMTQwZTQ3NDI2MjEwZjJmZTZiYzdjYjdjYjAxYjQ4MA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZjRjMzk1MzlkYmQ3ZThjYzUzNWJiODIzN2QwNzc5YTM1ZWM0ZTkwN2I3Nzll
10
+ ZmY5ZjM4ZWVkYzQwNDM4Mjc4MGYyNGUxNzk5YTgxYjUwMTA0MmY0MTkwMzU3
11
+ ZTgyNzg3OWU3NzNjNDU2NWI0MjAwMGQ4MGRlZTE5MGY5ZDRhNjg=
12
+ data.tar.gz: !binary |-
13
+ NDYxMzVmYzQ3ZjRmZTk1YTA2ZTE3ZmM4MmQ5OGMwYTQ3MjEzZWY4ZmFhYzcy
14
+ ODgzMjQzOWRkZjEyYmEwMDliN2MzY2RiOGM2MTNiNGRkNWE5NWMzOGMzN2Nm
15
+ NWRmYWMyMGE1ODcyYTdkYzJjMzgwYjdjZTRjN2IwN2ExOTAyNTc=
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in method_chain_proxy.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,7 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
4
+ watch(%r{^lib/catchy/(.+)\.rb$}) { |m| "spec/lib/catchy/#{m[1]}_spec.rb" }
5
+ watch('spec/spec_helper.rb') { "spec" }
6
+ end
7
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jonas Schubert Erlandsson
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Catchy
2
+
3
+ This is a simple gem to capture chains of method calls.
4
+
5
+ [![Build Status](https://travis-ci.org/my-codeworks/catchy.png)](https://travis-ci.org/my-codeworks/catchy)
6
+ [![Gem Version](https://badge.fury.io/rb/catchy.png)](http://badge.fury.io/rb/catchy)
7
+ [![Code Climate](https://codeclimate.com/github/my-codeworks/catchy.png)](https://codeclimate.com/github/my-codeworks/catchy)
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'method_chain_proxy'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install method_chain_proxy
22
+
23
+ ## Usage
24
+
25
+ ### Basic
26
+
27
+ At it's simplest you just instantiate a new `Catchy` and give it to whatever you want to capture the calls of:
28
+
29
+ proxy = Catchy.new
30
+ object.black_box( proxy )
31
+
32
+ Then you can get the chain of called methods as a string:
33
+
34
+ proxy.to_s # => "some.chain.of.method.calls"
35
+
36
+ ### Configuration
37
+
38
+ "But what if I need to capture call chains that include calls to to_s?" I hear you saying. Ah, we thought of that. Simply tell `Catchy` that you want another name for `to_s` when you create it, like this:
39
+
40
+ proxy = Catchy.new(to_s: :__to_string__)
41
+
42
+ Then you can
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create new Pull Request
51
+
52
+ ## Special thanks
53
+
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!
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task default: :spec
data/catchy.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'catchy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "catchy"
8
+ spec.version = Catchy::VERSION
9
+ spec.authors = ["Jonas Schubert Erlandsson"]
10
+ spec.email = ["jonas.schubert.erlandsson@my-codeworks.com"]
11
+ spec.description = "Allows you to create an object that captures any chain of methods called on it and then displays them when turned into a string."
12
+ spec.summary = "Ruby gem to capture chains of method calls."
13
+ spec.homepage = "https://github.com/my-codeworks/catchy"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "guard-rspec"
25
+ end
@@ -0,0 +1,26 @@
1
+ class Catchy::MethodChain
2
+
3
+ def initialize( options = {} )
4
+ options = Catchy::DEFAULT_OPTIONS.merge( options )
5
+ define_accessors( options )
6
+ @method_chain = []
7
+ end
8
+
9
+ def method_missing(name)
10
+ @method_chain << name
11
+ return self
12
+ end
13
+
14
+ private
15
+
16
+ def define_accessors( options )
17
+ define_to_string_as( options[:to_s] )
18
+ end
19
+
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
24
+ end
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ module Catchy
2
+ VERSION = "0.1.0"
3
+ end
data/lib/catchy.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'catchy/version'
2
+ require 'catchy/method_chain'
3
+
4
+ module Catchy
5
+
6
+ DEFAULT_OPTIONS = {
7
+ to_s: :to_s,
8
+ }
9
+
10
+ def self.new( *args )
11
+ MethodChain.new( *args )
12
+ end
13
+
14
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'catchy/method_chain'
3
+
4
+ describe Catchy::MethodChain do
5
+
6
+ context "basic use" do
7
+ describe "initialization" do
8
+ subject { Catchy.new() }
9
+ it { should_not be_nil }
10
+ end
11
+
12
+ describe "returns a method chain proxy when called" do
13
+ subject { Catchy.new().whatever.class }
14
+ it { should == Catchy::MethodChain }
15
+ end
16
+
17
+ describe "to_s yields chained calls" do
18
+ subject { Catchy.new().can.be.called.by.whatever.to_s }
19
+ it { should == 'can.be.called.by.whatever' }
20
+ end
21
+ end
22
+
23
+ context "customizing behaviour" do
24
+ describe "overriding default to_s method name" do
25
+ subject { Catchy.new(to_s: :__to_s).can.be.called.by.whatever.__to_s }
26
+ it { should == 'can.be.called.by.whatever' }
27
+ end
28
+ end
29
+
30
+ end
@@ -0,0 +1,6 @@
1
+ require 'spec_helper'
2
+ require 'catchy'
3
+
4
+ describe Catchy do
5
+
6
+ end
@@ -0,0 +1,7 @@
1
+ RSpec.configure do |config|
2
+ config.treat_symbols_as_metadata_keys_with_true_values = true
3
+ config.run_all_when_everything_filtered = true
4
+ config.filter_run :focus
5
+
6
+ config.order = 'random'
7
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: catchy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonas Schubert Erlandsson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
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
+ - - ! '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Allows you to create an object that captures any chain of methods called
70
+ on it and then displays them when turned into a string.
71
+ email:
72
+ - jonas.schubert.erlandsson@my-codeworks.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - Gemfile
80
+ - Guardfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - catchy.gemspec
85
+ - lib/catchy.rb
86
+ - lib/catchy/method_chain.rb
87
+ - lib/catchy/version.rb
88
+ - spec/lib/catchy/method_chain_spec.rb
89
+ - spec/lib/catchy_spec.rb
90
+ - spec/spec_helper.rb
91
+ homepage: https://github.com/my-codeworks/catchy
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Ruby gem to capture chains of method calls.
115
+ test_files:
116
+ - spec/lib/catchy/method_chain_spec.rb
117
+ - spec/lib/catchy_spec.rb
118
+ - spec/spec_helper.rb
119
+ has_rdoc: