reflection_utils 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e79dd0612063c610415fb53e00eb28f7028d051
4
- data.tar.gz: e038ab0057ebf11a500b161d9dd723804a0e0941
3
+ metadata.gz: 571f076e3fdbd327ef51ff4a018483cdaae24dd0
4
+ data.tar.gz: 115edd01652ae363aa797e248a82f19d1c4b9d62
5
5
  SHA512:
6
- metadata.gz: dbbfc1be41596ec50c7f55dc574cd307af011b02c26f1b3a842eec285fe5d17290f677cda16de6f648499e22200563f84b2fee0184017c490eb53d6a37bf6187
7
- data.tar.gz: 41ebc3ff100c6ec141d62f451b9c22a1c117e51261f23bde1d4a6b6828d0f71675c4da0df1d53524d97633f2c159c7bd1a1cb9b12a20edfbf9102d9acd647057
6
+ metadata.gz: cf21898bdb44e9c05442df1f565c4151e36560a1d88d94b5b2e0a76ff6a517c63bd8e5bfd0e2a2c63bb034004bdbbe7da6fee7b7688126ccdb82a39693b1f0ab
7
+ data.tar.gz: e5616ad3e79722f06facd7a3163f4bba0ce02503a03b61d13869774ee639a655101ae0b83043c55df75b1cce0d0dbd0d89d941616361e19e41505eecf766f0ae
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2017
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2017
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,72 +1,73 @@
1
- # ReflectionUtils
2
-
3
- #### Commonly used Ruby utility functions related to reflection.
4
-
5
- | Branch | Status |
6
- | ------ | ------ |
7
- | Release | [![Build Status](https://travis-ci.org/thisismydesign/reflection_utils.svg?branch=release)](https://travis-ci.org/thisismydesign/reflection_utils) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/reflection_utils/badge.svg?branch=release)](https://coveralls.io/github/thisismydesign/reflection_utils?branch=release) [![Gem Version](https://badge.fury.io/rb/reflection_utils.svg)](https://badge.fury.io/rb/reflection_utils) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/reflection_utils?type=total)](https://rubygems.org/gems/reflection_utils) |
8
- | Development | [![Build Status](https://travis-ci.org/thisismydesign/reflection_utils.svg?branch=master)](https://travis-ci.org/thisismydesign/reflection_utils) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/reflection_utils/badge.svg?branch=master)](https://coveralls.io/github/thisismydesign/reflection_utils?branch=master) |
9
-
10
- ## Features
11
-
12
- Functions include:
13
- - get_bound_instance_method(instance:, method_name:)
14
- - get_class_constant(instance:)
15
- - call(callback, params = nil)
16
- - has_parameter?(proc, parameter_index, parameter)
17
- - has_parameters?(proc, parameters)
18
- - assert_parameters(proc, parameters)
19
- - non_default_methods(class_or_instance)
20
- - module CreateClassMethodsUponInclude (more: http://lifeinacubicleblog.com/2017/06/26/ruby-how-to-use-self-included-meaningfully)
21
-
22
- For usage and examples for each of them take a look at the [unit tests](https://github.com/thisismydesign/reflection_utils/blob/master/spec/reflection_utils_spec.rb).
23
-
24
- Another approach would be to include this functionality into classes where its needed. It may be more elegant however moving this functionality into a separate utility class decouples the logic and removes dependency from those classes.
25
-
26
- ## Installation
27
-
28
- Add this line to your application's Gemfile:
29
-
30
- ```ruby
31
- gem 'reflection_utils'
32
- ```
33
-
34
- And then execute:
35
-
36
- $ bundle
37
-
38
- Or install it yourself as:
39
-
40
- $ gem install reflection_utils
41
-
42
- ## Usage
43
-
44
- ```ruby
45
- require 'reflection_utils'
46
-
47
- # ...
48
-
49
- ReflectionUtils.get_bound_instance_method(instance: my_obj, method_name: :my_method)
50
-
51
- # etc.
52
- ```
53
-
54
- ## Feedback
55
-
56
- Any feedback is much appreciated.
57
-
58
- I can only tailor this project to fit use-cases I know about - which are usually my own ones. If you find that this might be the right direction to solve your problem too but you find that it's suboptimal or lacks features don't hesitate to contact me.
59
-
60
- Please let me know if you make use of this project so that I can prioritize further efforts.
61
-
62
- ## Development
63
-
64
- This gem is developed using Bundler conventions. A good overview can be found [here](http://bundler.io/v1.14/guides/creating_gem.html).
65
-
66
- ## Contributing
67
-
68
- Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/reflection_utils.
69
-
70
- ## License
71
-
72
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
1
+ # ReflectionUtils
2
+
3
+ #### Commonly used Ruby utility functions related to reflection.
4
+
5
+ | Branch | Status |
6
+ | ------ | ------ |
7
+ | Release | [![Build Status](https://travis-ci.org/thisismydesign/reflection_utils.svg?branch=release)](https://travis-ci.org/thisismydesign/reflection_utils) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/reflection_utils/badge.svg?branch=release)](https://coveralls.io/github/thisismydesign/reflection_utils?branch=release) [![Gem Version](https://badge.fury.io/rb/reflection_utils.svg)](https://badge.fury.io/rb/reflection_utils) [![Total Downloads](http://ruby-gem-downloads-badge.herokuapp.com/reflection_utils?type=total)](https://rubygems.org/gems/reflection_utils) |
8
+ | Development | [![Build Status](https://travis-ci.org/thisismydesign/reflection_utils.svg?branch=master)](https://travis-ci.org/thisismydesign/reflection_utils) [![Coverage Status](https://coveralls.io/repos/github/thisismydesign/reflection_utils/badge.svg?branch=master)](https://coveralls.io/github/thisismydesign/reflection_utils?branch=master) |
9
+
10
+ ## Features
11
+
12
+ Functions include:
13
+ - get_bound_instance_method(instance:, method_name:)
14
+ - get_class_constant(instance:)
15
+ - call(callback, params = nil)
16
+ - has_parameter?(proc, parameter_index, parameter)
17
+ - has_parameters?(proc, parameters)
18
+ - assert_parameters(proc, parameters)
19
+ - non_default_methods(class_or_instance)
20
+ - module CreateClassMethodsUponInclude (more: http://lifeinacubicleblog.com/2017/06/26/ruby-how-to-use-self-included-meaningfully)
21
+ - module CreateModuleFunctions (more: https://stackoverflow.com/questions/322470/can-i-invoke-an-instance-method-on-a-ruby-module-without-including-it)
22
+
23
+ For usage and examples for each of them take a look at the [unit tests](https://github.com/thisismydesign/reflection_utils/blob/master/spec/reflection_utils_spec.rb).
24
+
25
+ Another approach would be to include this functionality into classes where its needed. It may be more elegant however moving this functionality into a separate utility class decouples the logic and removes dependency from those classes.
26
+
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'reflection_utils'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ $ bundle
38
+
39
+ Or install it yourself as:
40
+
41
+ $ gem install reflection_utils
42
+
43
+ ## Usage
44
+
45
+ ```ruby
46
+ require 'reflection_utils'
47
+
48
+ # ...
49
+
50
+ ReflectionUtils.get_bound_instance_method(instance: my_obj, method_name: :my_method)
51
+
52
+ # etc.
53
+ ```
54
+
55
+ ## Feedback
56
+
57
+ Any feedback is much appreciated.
58
+
59
+ I can only tailor this project to fit use-cases I know about - which are usually my own ones. If you find that this might be the right direction to solve your problem too but you find that it's suboptimal or lacks features don't hesitate to contact me.
60
+
61
+ Please let me know if you make use of this project so that I can prioritize further efforts.
62
+
63
+ ## Development
64
+
65
+ This gem is developed using Bundler conventions. A good overview can be found [here](http://bundler.io/v1.14/guides/creating_gem.html).
66
+
67
+ ## Contributing
68
+
69
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thisismydesign/reflection_utils.
70
+
71
+ ## License
72
+
73
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -1,49 +1,50 @@
1
- require_relative 'reflection_utils/create_class_methods_upon_include'
2
-
3
- module ReflectionUtils
4
-
5
- def self.get_bound_instance_method(instance:, method_name:)
6
- get_class_constant(instance: instance).instance_method(method_name).bind(instance)
7
- end
8
-
9
- def self.get_class_constant(instance:)
10
- Object.const_get(instance.class.name)
11
- end
12
-
13
- def self.call(callback, params = nil)
14
- params.nil? ? callback.call : callback.call(params)
15
- end
16
-
17
- def self.has_parameters?(proc, parameters)
18
- parameters.each_with_index do |parameter, index|
19
- return false unless has_parameter?(proc, index, parameter)
20
- end
21
-
22
- true
23
- end
24
-
25
- def self.assert_parameters(proc, parameters)
26
- parameters.each_with_index do |parameter, index|
27
- raise ArgumentError, "Argument #{parameter} not found for #{proc} at #{index} index." unless has_parameter?(proc, index, parameter)
28
- end
29
-
30
- true
31
- end
32
-
33
- def self.has_parameter?(proc, parameter_index, parameter)
34
- proc.parameters[parameter_index] == parameter
35
- end
36
-
37
- def self.non_default_methods(class_or_instance)
38
- class_or_instance.is_a?(Module) ? non_default_class_methods(class_or_instance) : non_default_instance_methods(class_or_instance)
39
- end
40
-
41
- def self.non_default_class_methods(clazz)
42
- clazz.methods - Object.methods
43
- end
44
-
45
- def self.non_default_instance_methods(instance)
46
- instance.methods - Object.new.methods
47
- end
48
-
49
- end
1
+ require_relative 'reflection_utils/create_class_methods_upon_include'
2
+ require_relative 'reflection_utils/create_module_functions'
3
+
4
+ module ReflectionUtils
5
+
6
+ def self.get_bound_instance_method(instance:, method_name:)
7
+ get_class_constant(instance: instance).instance_method(method_name).bind(instance)
8
+ end
9
+
10
+ def self.get_class_constant(instance:)
11
+ Object.const_get(instance.class.name)
12
+ end
13
+
14
+ def self.call(callback, params = nil)
15
+ params.nil? ? callback.call : callback.call(params)
16
+ end
17
+
18
+ def self.has_parameters?(proc, parameters)
19
+ parameters.each_with_index do |parameter, index|
20
+ return false unless has_parameter?(proc, index, parameter)
21
+ end
22
+
23
+ true
24
+ end
25
+
26
+ def self.assert_parameters(proc, parameters)
27
+ parameters.each_with_index do |parameter, index|
28
+ raise ArgumentError, "Argument #{parameter} not found for #{proc} at #{index} index." unless has_parameter?(proc, index, parameter)
29
+ end
30
+
31
+ true
32
+ end
33
+
34
+ def self.has_parameter?(proc, parameter_index, parameter)
35
+ proc.parameters[parameter_index] == parameter
36
+ end
37
+
38
+ def self.non_default_methods(class_or_instance)
39
+ class_or_instance.is_a?(Module) ? non_default_class_methods(class_or_instance) : non_default_instance_methods(class_or_instance)
40
+ end
41
+
42
+ def self.non_default_class_methods(clazz)
43
+ clazz.methods - Object.methods
44
+ end
45
+
46
+ def self.non_default_instance_methods(instance)
47
+ instance.methods - Object.new.methods
48
+ end
49
+
50
+ end
@@ -1,9 +1,9 @@
1
- module ReflectionUtils
2
- module CreateClassMethodsUponInclude
3
- def self.included(base)
4
- base.define_singleton_method :included do |base|
5
- base.extend(self)
6
- end
7
- end
8
- end
9
- end
1
+ module ReflectionUtils
2
+ module CreateClassMethodsUponInclude
3
+ def self.included(base)
4
+ base.define_singleton_method :included do |base|
5
+ base.extend(self)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module ReflectionUtils
2
+ module CreateModuleFunctions
3
+ def self.included(base)
4
+ base.instance_methods.each do |method|
5
+ base.module_eval do
6
+ module_function(method)
7
+ public(method)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
- module ReflectionUtils
2
- VERSION = "0.2.1"
3
- end
1
+ module ReflectionUtils
2
+ VERSION = "0.3.0"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reflection_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thisismydesign
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-28 00:00:00.000000000 Z
11
+ date: 2017-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coveralls
@@ -84,6 +84,7 @@ files:
84
84
  - bin/setup
85
85
  - lib/reflection_utils.rb
86
86
  - lib/reflection_utils/create_class_methods_upon_include.rb
87
+ - lib/reflection_utils/create_module_functions.rb
87
88
  - lib/reflection_utils/version.rb
88
89
  - reflection_utils.gemspec
89
90
  homepage: https://github.com/thisismydesign/reflection_utils
@@ -105,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
106
  version: '0'
106
107
  requirements: []
107
108
  rubyforge_project:
108
- rubygems_version: 2.5.2
109
+ rubygems_version: 2.5.1
109
110
  signing_key:
110
111
  specification_version: 4
111
112
  summary: Commonly used utility functions related to reflection