reflection_utils 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: c261c1b2f2134c6a7df86853710ea69c54130244
4
+ data.tar.gz: 74857503c77afc6d67ee3a34a29c226c41a15c68
5
+ SHA512:
6
+ metadata.gz: d4b3884f9b9f0ac2b85c35e33ddfa255d249ba5c0aaa01cbd6abe3f420b4fb080e7319316a9a203815a72cb733acc9a85cbc0c554b00e3f386a283e6c273aba0
7
+ data.tar.gz: 8d38855ac7793b6a09744506244e0345f53eba44df0ece32a24f930fe76ef18686783f5d9c89e1ee27241d71a217830bf43bf2564def47af8754922a79304a06
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in reflection_utils.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +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.
@@ -0,0 +1,70 @@
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
+
20
+ 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).
21
+
22
+ 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.
23
+
24
+ ## Installation
25
+
26
+ Add this line to your application's Gemfile:
27
+
28
+ ```ruby
29
+ gem 'reflection_utils'
30
+ ```
31
+
32
+ And then execute:
33
+
34
+ $ bundle
35
+
36
+ Or install it yourself as:
37
+
38
+ $ gem install reflection_utils
39
+
40
+ ## Usage
41
+
42
+ ```ruby
43
+ require 'reflection_utils'
44
+
45
+ # ...
46
+
47
+ ReflectionUtils.get_bound_instance_method(instance: my_obj, method_name: :my_method)
48
+
49
+ # etc.
50
+ ```
51
+
52
+ ## Feedback
53
+
54
+ Any feedback is much appreciated.
55
+
56
+ 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.
57
+
58
+ Please let me know if you make use of this project so that I can prioritize further efforts.
59
+
60
+ ## Development
61
+
62
+ This gem is developed using Bundler conventions. A good overview can be found [here](http://bundler.io/v1.14/guides/creating_gem.html).
63
+
64
+ ## Contributing
65
+
66
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/reflection_utils.
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ desc "Check if source can be required locally"
7
+ task :require do
8
+ sh "ruby -e \"require '#{File.dirname __FILE__}/lib/reflection_utils'\""
9
+ end
10
+
11
+ task :default => [:require, :spec]
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "reflection_utils"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,35 @@
1
+ module ReflectionUtils
2
+
3
+ def self.get_bound_instance_method(instance:, method_name:)
4
+ get_class_constant(instance: instance).instance_method(method_name).bind(instance)
5
+ end
6
+
7
+ def self.get_class_constant(instance:)
8
+ Object.const_get(instance.class.name)
9
+ end
10
+
11
+ def self.call(callback, params = nil)
12
+ params.nil? ? callback.call : callback.call(params)
13
+ end
14
+
15
+ def self.has_parameters?(proc, parameters)
16
+ parameters.each_with_index do |parameter, index|
17
+ return false unless has_parameter?(proc, index, parameter)
18
+ end
19
+
20
+ true
21
+ end
22
+
23
+ def self.assert_parameters(proc, parameters)
24
+ parameters.each_with_index do |parameter, index|
25
+ raise ArgumentError, "Argument #{parameter} not found for #{proc} at #{index} index." unless has_parameter?(proc, index, parameter)
26
+ end
27
+
28
+ true
29
+ end
30
+
31
+ def self.has_parameter?(proc, parameter_index, parameter)
32
+ proc.parameters[parameter_index] == parameter
33
+ end
34
+
35
+ end
@@ -0,0 +1,3 @@
1
+ module ReflectionUtils
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'reflection_utils/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "reflection_utils"
8
+ spec.version = ReflectionUtils::VERSION
9
+ spec.authors = ["thisismydesign"]
10
+ spec.email = ["thisismydesign@users.noreply.github.com"]
11
+
12
+ spec.summary = "Commonly used utility functions related to reflection"
13
+ spec.homepage = "https://github.com/thisismydesign/reflection_utils"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "coveralls"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: reflection_utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - thisismydesign
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coveralls
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '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.14'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.14'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.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: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - thisismydesign@users.noreply.github.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - Gemfile
80
+ - LICENSE
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/reflection_utils.rb
86
+ - lib/reflection_utils/version.rb
87
+ - reflection_utils.gemspec
88
+ homepage: https://github.com/thisismydesign/reflection_utils
89
+ licenses: []
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.5.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Commonly used utility functions related to reflection
111
+ test_files: []