extensions_loader 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a5ac2fe65917c76331010fcc4292ce191858ef0d
4
+ data.tar.gz: c6fbc70a0bb9c3939b35289c702843cd8b53c7aa
5
+ SHA512:
6
+ metadata.gz: 73239969e2fea642b84e08fb47568f014eb12fc44fedcef3993e4e24b8159d7eeca93c8480aa890637cb355ce1122262efdcecb279fce2361fceab22f3191663
7
+ data.tar.gz: eb174a48a4269b37ad1fc847fcd82802b12055d3cacd6475f89708cd0a2b4f8e78c994c7cae7108077037d732a35a92f2c909155045f7ca5e0ebc17abb72e50d
data/.gitignore ADDED
@@ -0,0 +1,31 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # Ruby
30
+ Gemfile.lock
31
+ .rvmrc
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.4
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in extensions-loader.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Andrew Page
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 ADDED
@@ -0,0 +1,59 @@
1
+ # ExtensionsLoader
2
+
3
+ ExtensionsLoader is a lightweight gem that simplifies the extension of Ruby classes and modules. Rather than monkeypatching or managing your extension modules yourself, you can use ExtensionsLoader to easily include extension modules into pre-defined Ruby modules and classes.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'extensions_loader'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```sh
16
+ $ bundle install
17
+ ```
18
+
19
+ Or install it yourself with:
20
+
21
+ ```bash
22
+ $ gem install extensions_loader
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ First, you need to load the ExtensionsLoader gem in your code.
28
+
29
+ ```ruby
30
+ require 'extensions_loader'
31
+ ```
32
+
33
+ Then, you can define base classes and their extensions with the following mapping syntax:
34
+
35
+ ```ruby
36
+ ExtensionsLoader.load!(
37
+ ActiveRecord::Base => Extensions::Database::MyQueryCounter,
38
+ String => [
39
+ Extensions::MyColoredStrings,
40
+ Extensions::MyURLGenerator
41
+ ]
42
+ )
43
+ ```
44
+
45
+ The key of the mapping hash is the **target**, and the value is the **extension(s)**. You can pass in a single extension as the value, or an Array of extensions. Both are valid.
46
+
47
+ This will include `Extensions::Database::MyQueryCounter` into `ActiveRecord::Base`, and `Extensions::MyColoredStrings` and `Extensions::MyURLGenerator` into `String`.
48
+
49
+ Using ExtensionsLoader to manage your Ruby extensions is much easier than the alternative, monkeypatching these classes individually.
50
+
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/andrewpage/extensions_loader.
55
+
56
+
57
+ ## License
58
+
59
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'irb'
5
+
6
+ require 'extensions_loader'
7
+
8
+ IRB.start
data/bin/setup ADDED
@@ -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,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'extensions_loader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'extensions_loader'
8
+ spec.version = ExtensionsLoader::VERSION
9
+ spec.authors = ['Andrew Page']
10
+ spec.email = ['andrew@andrewpage.me']
11
+
12
+ spec.summary = 'Avoid monkeypatching by dynamically loading Ruby extensions.'
13
+ spec.description = 'ExtensionsLoader is a lightweight gem that simplifies the extension of Ruby classes and modules. Rather than monkeypatching or managing your extension modules yourself, you can use ExtensionsLoader to easily include extension modules into pre-defined Ruby modules and classes.'
14
+ spec.homepage = 'https://github.com/andrewpage/extensions_loader'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = %w(lib)
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ end
@@ -0,0 +1,9 @@
1
+ require 'extensions_loader/version'
2
+ require 'extensions_loader/loader'
3
+
4
+ module ExtensionsLoader
5
+ def self.load!(mapping)
6
+ loader = Loader.new(mapping)
7
+ loader.load!
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ module ExtensionsLoader
2
+ class Loader
3
+ attr_reader :mapping
4
+
5
+ def initialize(mapping)
6
+ @mapping = mapping
7
+ verify!
8
+ end
9
+
10
+ # Perform extension loading on all mappings
11
+ def load!
12
+ mapping.each do |klass, loadable|
13
+ if loadable.is_a? Array
14
+ loadable.each { |extension| load_extension(klass, extension) }
15
+ else
16
+ load_extension(klass, loadable)
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ # Ensure that all defined extensions are either a Module or Array.
24
+ def verify!
25
+ mapping.each { |k, v| raise "#{k}'s extension must provide a Module or Array." unless v.is_a?(Module) || v.is_a?(Array) }
26
+ end
27
+
28
+ # Include `extension` into class `klass`
29
+ def load_extension(klass, extension)
30
+ klass.include(extension)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module ExtensionsLoader
2
+ VERSION = '1.0.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: extensions_loader
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Page
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-24 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: ExtensionsLoader is a lightweight gem that simplifies the extension of
56
+ Ruby classes and modules. Rather than monkeypatching or managing your extension
57
+ modules yourself, you can use ExtensionsLoader to easily include extension modules
58
+ into pre-defined Ruby modules and classes.
59
+ email:
60
+ - andrew@andrewpage.me
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".rspec"
67
+ - ".travis.yml"
68
+ - Gemfile
69
+ - LICENSE
70
+ - README.md
71
+ - Rakefile
72
+ - bin/console
73
+ - bin/setup
74
+ - extensions_loader.gemspec
75
+ - lib/extensions_loader.rb
76
+ - lib/extensions_loader/loader.rb
77
+ - lib/extensions_loader/version.rb
78
+ homepage: https://github.com/andrewpage/extensions_loader
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.4.8
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: Avoid monkeypatching by dynamically loading Ruby extensions.
102
+ test_files: []