charlatan 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 929b8622fb574a9a9d020ff4ff647275dca2a2b8
4
+ data.tar.gz: 9ac59a5d71b381fcbebc6a611c2ed09cbab23e4e
5
+ SHA512:
6
+ metadata.gz: 6929d2756772933b28a5dad3bea59c4ec6a50c458dfa38c7ceb7de6851b94dfe308ef4caac961034586795fd444a3126a67fb36ccb62354f0a8ff1f7ade159ff
7
+ data.tar.gz: 9c79031f5e8fafafbfdce47d00f14c472a708fe298b4c0b28bf758a5919b6c95bb68571240501902fe8ef68865f97f04b063758ca867baad2c1491ad42ad2765
@@ -0,0 +1,18 @@
1
+ language: ruby
2
+ before_install: gem install bundler
3
+ bundler_args: --without yard guard benchmarks
4
+ script: "bundle exec rake metrics:coverage"
5
+ rvm:
6
+ - 1.9.3
7
+ - 2.0.0
8
+ - 2.1.0
9
+ - jruby-19mode
10
+ - rbx
11
+ - ruby-head
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
15
+ - rvm: rbx
16
+ notifications:
17
+ email:
18
+ - piotr.solnica@gmail.com
@@ -4,21 +4,24 @@ group :development do
4
4
  gem 'rake', '~> 10.1.0'
5
5
  gem 'rspec', '~> 2.14.1'
6
6
  gem 'yard', '~> 0.8.7'
7
+
8
+ platform :rbx do
9
+ gem 'rubysl-singleton', '~> 2.0.0'
10
+ end
7
11
  end
8
12
 
9
13
  group :yard do
10
- gem 'kramdown', '~> 1.2.0'
14
+ gem 'kramdown', '~> 1.3.0'
11
15
  end
12
16
 
13
17
  group :guard do
14
- gem 'guard', '~> 1.8.1'
15
- gem 'guard-bundler', '~> 1.0.0'
16
- gem 'guard-rspec', '~> 3.0.2'
17
- gem 'guard-rubocop', '~> 0.2.0'
18
- gem 'guard-mutant', '~> 0.0.1'
18
+ gem 'guard', '~> 2.2.4'
19
+ gem 'guard-bundler', '~> 2.0.0'
20
+ gem 'guard-rspec', '~> 4.2.0'
21
+ gem 'guard-rubocop', '~> 1.0.0'
19
22
 
20
23
  # file system change event handling
21
- gem 'listen', '~> 1.3.0'
24
+ gem 'listen', '~> 2.4.0'
22
25
  gem 'rb-fchange', '~> 0.0.6', require: false
23
26
  gem 'rb-fsevent', '~> 0.9.3', require: false
24
27
  gem 'rb-inotify', '~> 0.9.0', require: false
@@ -30,18 +33,27 @@ group :guard do
30
33
  end
31
34
 
32
35
  group :metrics do
33
- gem 'coveralls', '~> 0.6.7'
36
+ gem 'coveralls', '~> 0.7.0'
34
37
  gem 'flay', '~> 2.4.0'
35
- gem 'flog', '~> 4.1.1'
38
+ gem 'flog', '~> 4.2.0'
36
39
  gem 'reek', '~> 1.3.2'
37
- gem 'rubocop', '~> 0.12.0'
38
- gem 'simplecov', '~> 0.7.1'
40
+ gem 'rubocop', '~> 0.16.0'
41
+ gem 'simplecov', '~> 0.8.2'
39
42
  gem 'yardstick', '~> 0.9.7', git: 'https://github.com/dkubb/yardstick.git'
40
43
 
41
44
  platforms :ruby_19, :ruby_20 do
42
- gem 'mutant', git: 'https://github.com/mbj/mutant.git'
45
+ gem 'mutant', '~> 0.3.0', git: 'https://github.com/mbj/mutant.git'
46
+ gem 'unparser', '~> 0.1.5', git: 'https://github.com/mbj/unparser.git'
43
47
  gem 'yard-spellcheck', '~> 0.1.5'
44
48
  end
49
+
50
+ platform :rbx do
51
+ gem 'json', '~> 1.8.1'
52
+ gem 'racc', '~> 1.4.10'
53
+ gem 'rubysl-logger', '~> 2.0.0'
54
+ gem 'rubysl-open-uri', '~> 2.0.0'
55
+ gem 'rubysl-prettyprint', '~> 2.0.2'
56
+ end
45
57
  end
46
58
 
47
59
  group :benchmarks do
data/README.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Charlatan
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/charlatan.png)][gem]
4
+ [![Build Status](https://secure.travis-ci.org/solnic/charlatan.png?branch=master)][travis]
5
+ [![Dependency Status](https://gemnasium.com/solnic/charlatan.png)][gemnasium]
6
+ [![Code Climate](https://codeclimate.com/github/solnic/charlatan.png)][codeclimate]
7
+ [![Coverage Status](https://coveralls.io/repos/solnic/charlatan/badge.png?branch=master)][coveralls]
8
+
9
+ [gem]: https://rubygems.org/gems/charlatan
10
+ [travis]: https://travis-ci.org/solnic/charlatan
11
+ [gemnasium]: https://gemnasium.com/solnic/charlatan
12
+ [codeclimate]: https://codeclimate.com/github/solnic/charlatan
13
+ [coveralls]: https://coveralls.io/r/solnic/charlatan
14
+
3
15
  Turn any object into a proxy delegating to another object. Like that:
4
16
 
5
17
  ``` ruby
@@ -22,11 +34,22 @@ other = array_proxy + ['Oh Hai']
22
34
  other.class # => ArrayProxy
23
35
  ```
24
36
 
37
+ Planned features:
38
+
39
+ * optional support for equality methods
40
+ * optional support for kind_of? and ===
41
+ * transparent vs restricted delegation (as in, allow all calls or explicitly specify what should be delegated)
42
+
25
43
  ## Why?
26
44
 
27
- I dunno, you tell me. I just like it. Which I cannot say about SimpleDelegator.
45
+ The idea is that a delegator object wrapping another object delegates method calls but it preserves the original type for return values which match the wrapped object's kind. This means if you decorate an array object and you call concat on the decorator you will get an instance of the decorator back rather than an array.
46
+
47
+ Other cool aspects of this library:
28
48
 
29
- ### TODO: explain why
49
+ * You get a constructor for free which plays well with your own, just remember to call super if you override it
50
+ * You get attr reader for the wrapped object
51
+ * Your object correctly handles method missing and respond_to? - something that is really easy to break accidentely in an ad-hoc custom implementation
52
+ * You don't need to inherit from any superclass, just mix it in and call it a day
30
53
 
31
54
  ## Installation
32
55
 
@@ -42,6 +65,18 @@ Or install it yourself as:
42
65
 
43
66
  $ gem install charlatan
44
67
 
68
+ ## Credits
69
+
70
+ * [Dan Kubb](https://github.com/dkubb) for the original idea behind a proxy
71
+ wrapping another object.
72
+ * [Don Morrison](https://github.com/elskwid) for the awesome name that happened
73
+ to be available on github and rubygems *at the same time*
74
+
75
+ ## Similar libraries
76
+
77
+ * [casting](https://github.com/saturnflyer/casting)
78
+ * simple_delegator in ruby stdlib
79
+
45
80
  ## Contributing
46
81
 
47
82
  1. Fork it
@@ -22,19 +22,19 @@ class Charlatan < Module
22
22
  attr_reader name
23
23
  ivar = "@#{name}"
24
24
 
25
- define_method(:initialize) do |*args, &block|
26
- instance_variable_set(ivar, args.first)
27
- @__proxy_args = args[1..args.size] || []
25
+ attr_reader :__proxy_kind__, :__proxy_args__
26
+
27
+ define_method(:initialize) do |proxy_target, *args, &block|
28
+ instance_variable_set(ivar, proxy_target)
29
+
30
+ @__proxy_kind__ = options.fetch(:kind) { proxy_target.class }
31
+ @__proxy_args__ = args
28
32
  end
29
33
 
30
34
  define_method(:__proxy_target__) do
31
35
  instance_variable_get(ivar)
32
36
  end
33
37
 
34
- define_method(:__proxy_kind__) do
35
- options[:kind] || __proxy_target__.class
36
- end
37
-
38
38
  include Methods
39
39
  end
40
40
 
@@ -50,12 +50,12 @@ class Charlatan < Module
50
50
  if response.equal?(__proxy_target__)
51
51
  self
52
52
  elsif response.kind_of?(__proxy_kind__)
53
- self.class.new(*[response]+@__proxy_args)
53
+ self.class.new(*[response]+__proxy_args__)
54
54
  else
55
55
  response
56
56
  end
57
57
  else
58
- super(method_name, *args, &block)
58
+ super
59
59
  end
60
60
  end
61
61
  end
@@ -1,3 +1,3 @@
1
1
  class Charlatan < Module
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,6 +8,10 @@ describe Charlatan do
8
8
  Class.new {
9
9
  include Charlatan.new(:other)
10
10
 
11
+ def inspect
12
+ '#<TestClass>'
13
+ end
14
+
11
15
  def initialize(other, extra, &block)
12
16
  super(other, extra, &block)
13
17
  end
@@ -53,7 +57,10 @@ describe Charlatan do
53
57
  end
54
58
 
55
59
  it 'raises no method error when method is not defined' do
56
- expect { charlatan.not_here}.to raise_error(NoMethodError)
60
+ expect { charlatan.not_here}.to raise_error(
61
+ NoMethodError,
62
+ /undefined method `not_here' for #<TestClass>/
63
+ )
57
64
  end
58
65
 
59
66
  it 'forwards multiple levels down to the last target' do
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: charlatan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Piotr Solnica
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-12-12 00:00:00.000000000 Z
11
+ date: 2014-01-08 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -30,17 +27,15 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  description: Neat delegation for ruby objects
@@ -52,6 +47,7 @@ extra_rdoc_files: []
52
47
  files:
53
48
  - .gitignore
54
49
  - .rspec
50
+ - .travis.yml
55
51
  - Gemfile
56
52
  - Gemfile.devtools
57
53
  - Guardfile
@@ -73,27 +69,26 @@ files:
73
69
  homepage: https://github.com/solnic/charlatan
74
70
  licenses:
75
71
  - MIT
72
+ metadata: {}
76
73
  post_install_message:
77
74
  rdoc_options: []
78
75
  require_paths:
79
76
  - lib
80
77
  required_ruby_version: !ruby/object:Gem::Requirement
81
- none: false
82
78
  requirements:
83
- - - ! '>='
79
+ - - '>='
84
80
  - !ruby/object:Gem::Version
85
81
  version: '0'
86
82
  required_rubygems_version: !ruby/object:Gem::Requirement
87
- none: false
88
83
  requirements:
89
- - - ! '>='
84
+ - - '>='
90
85
  - !ruby/object:Gem::Version
91
86
  version: '0'
92
87
  requirements: []
93
88
  rubyforge_project:
94
- rubygems_version: 1.8.23
89
+ rubygems_version: 2.0.3
95
90
  signing_key:
96
- specification_version: 3
91
+ specification_version: 4
97
92
  summary: ''
98
93
  test_files:
99
94
  - spec/spec_helper.rb