easy_class_to_instance_method 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +59 -0
- data/Rakefile +1 -0
- data/easy_class_to_instance_method.gemspec +26 -0
- data/lib/easy_class_to_instance_method/core_ext/extends_class.rb +17 -0
- data/lib/easy_class_to_instance_method/version.rb +3 -0
- data/lib/easy_class_to_instance_method.rb +25 -0
- data/spec/easy_class_to_instance_method_spec.rb +24 -0
- data/spec/spec_helper.rb +6 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c7de64c206ccb1d6c9276258a5667dcba96622cf
|
4
|
+
data.tar.gz: 85becbc39808633622879133f27f2b2127450424
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cf39d0a9786ab515167bba4ba1750d27e3e9dff37fb4582b4f712a601a293e6e176a6e38708bca061f2d184ed59fe3ce9bf90aa437ddf73bffc1125ed04734a8
|
7
|
+
data.tar.gz: ef69972ffd4abd8b4b23205e8a81596ffd0049d6c10c1fe03b206cc823fc2bd253b6925f4602728b81bd7e20c09257ef34c6e16861ee12fccdfcf91d44a45379
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Ramon Tayag
|
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,59 @@
|
|
1
|
+
# EasyClassToInstanceMethod
|
2
|
+
|
3
|
+
As long as there is an instance method on your class, then this will create a class method for it for easy calling. Makes this:
|
4
|
+
|
5
|
+
Something.new(1, 2).execute
|
6
|
+
|
7
|
+
Into:
|
8
|
+
|
9
|
+
Something.execute(1, 2)
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'easy_class_to_instance_method'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install easy_class_to_instance_method
|
24
|
+
|
25
|
+
In a class:
|
26
|
+
|
27
|
+
class MyClass
|
28
|
+
easy_class_to_instance
|
29
|
+
|
30
|
+
def initialize(a, b)
|
31
|
+
@a = a
|
32
|
+
@b = b
|
33
|
+
end
|
34
|
+
|
35
|
+
def my_action
|
36
|
+
puts "#{@a}, #{@b}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
Call it:
|
41
|
+
|
42
|
+
MyClass.my_action('Hello', 'there')
|
43
|
+
|
44
|
+
## Usage
|
45
|
+
|
46
|
+
TODO: Write usage instructions here
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create new Pull Request
|
55
|
+
|
56
|
+
## Contributors
|
57
|
+
|
58
|
+
- [Nestor Pestelos](https://github.com/ngpestelos)
|
59
|
+
- [Marc Ignacio](https://github.com/padi)
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'easy_class_to_instance_method/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "easy_class_to_instance_method"
|
8
|
+
spec.version = EasyClassToInstanceMethod::VERSION
|
9
|
+
spec.authors = ["Ramon Tayag"]
|
10
|
+
spec.email = ["ramon.tayag@gmail.com"]
|
11
|
+
spec.description = %q{Adds convenience method to class to insantiate itself and execute a method.}
|
12
|
+
spec.summary = %q{Adds convenience method to class to insantiate itself and execute a method. Makes it easier to work with non-singletons.}
|
13
|
+
spec.homepage = ""
|
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_dependency "activesupport", ">= 3.0.0"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", '~> 2.13.0'
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module EasyClassToInstanceMethod
|
2
|
+
module CoreExt
|
3
|
+
module ExtendsClass
|
4
|
+
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
def easy_class_to_instance
|
9
|
+
include EasyClassToInstanceMethod
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Class.send :include, EasyClassToInstanceMethod::CoreExt::ExtendsClass
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'easy_class_to_instance_method/version'
|
3
|
+
require 'easy_class_to_instance_method/core_ext/extends_class'
|
4
|
+
|
5
|
+
module EasyClassToInstanceMethod
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def method_missing(method_name, *args, &block)
|
10
|
+
if method_exists?(method_name)
|
11
|
+
self.new(*args).send(method_name, &block)
|
12
|
+
else
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def method_exists?(method_name)
|
20
|
+
intersection = self.instance_methods & [method_name.to_s, method_name.to_sym]
|
21
|
+
intersection.any?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class SomeClass
|
4
|
+
easy_class_to_instance
|
5
|
+
|
6
|
+
def initialize(a, b)
|
7
|
+
@a = a
|
8
|
+
@b = b
|
9
|
+
end
|
10
|
+
|
11
|
+
def foo
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe EasyClassToInstanceMethod do
|
16
|
+
|
17
|
+
it 'should delegate missing class methods to instance methods, passing any arguments' do
|
18
|
+
class_instance = double
|
19
|
+
SomeClass.stub(:new).with('hi', 'there').and_return(class_instance)
|
20
|
+
class_instance.should_receive(:foo) { 'result' }
|
21
|
+
SomeClass.foo('hi', 'there').should == 'result'
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: easy_class_to_instance_method
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ramon Tayag
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.13.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.13.0
|
69
|
+
description: Adds convenience method to class to insantiate itself and execute a method.
|
70
|
+
email:
|
71
|
+
- ramon.tayag@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- easy_class_to_instance_method.gemspec
|
82
|
+
- lib/easy_class_to_instance_method.rb
|
83
|
+
- lib/easy_class_to_instance_method/core_ext/extends_class.rb
|
84
|
+
- lib/easy_class_to_instance_method/version.rb
|
85
|
+
- spec/easy_class_to_instance_method_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.0.3
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Adds convenience method to class to insantiate itself and execute a method.
|
111
|
+
Makes it easier to work with non-singletons.
|
112
|
+
test_files:
|
113
|
+
- spec/easy_class_to_instance_method_spec.rb
|
114
|
+
- spec/spec_helper.rb
|