ruby-augmentations 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +109 -0
- data/augmentations.gemspec +20 -0
- data/lib/augmentations.rb +3 -0
- data/lib/augmentations/module.rb +10 -0
- data/lib/augmentations/object.rb +10 -0
- data/lib/augmentations/version.rb +3 -0
- metadata +66 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 672f337c5e16c31f99be94b1870e3ea4c1118abe
|
4
|
+
data.tar.gz: 8bed552c8bc95e822bc35741c9abc2f8a76e5cdd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 35b213e53a42a18eeb6c1d738732aa776c85c1d08946b11cbee663b3a0a436fef5bbbd3300cdf9ed9c9cfd6ee7a090adf6959f9c5f7ca1c8a8fdab36b6062920
|
7
|
+
data.tar.gz: 7b173f717b1649f706fc9afa2d39a3439243da45c617b0d868e9b2eb015126e749909df834f572f1c1bb1a72c6854e152aba2d4b452b4f573b1857c418a1fd66
|
data/.gitignore
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Michael Cizl
|
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
|
13
|
+
all 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
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Augmentations
|
2
|
+
|
3
|
+
*Augmentations* is a tiny gem to easily extend a class with instance methods and class methods, as well as running class methods like Rails `belongs_to` at extend time.
|
4
|
+
|
5
|
+
# Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ruby-augmentations', require: 'augmentations'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ruby-augmentations
|
20
|
+
|
21
|
+
And put a require statement into your code:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'augmentations'
|
25
|
+
```
|
26
|
+
|
27
|
+
# Usage
|
28
|
+
|
29
|
+
It's basically like `include`ing a module, but you can define class methods and call class methods as you would in the class itself, without (ab)using the `self.included` hook and thus with less boilerplate.
|
30
|
+
|
31
|
+
Use it for Rails like
|
32
|
+
|
33
|
+
class User < ActiveRecord::Base
|
34
|
+
augment Shared::Pingable, User::PasswordResetExtension
|
35
|
+
end
|
36
|
+
|
37
|
+
with modules like
|
38
|
+
|
39
|
+
module User::PasswordResetExtension
|
40
|
+
augmentation do
|
41
|
+
|
42
|
+
has_many :password_resets
|
43
|
+
|
44
|
+
def self.a_class_method
|
45
|
+
# …
|
46
|
+
end
|
47
|
+
|
48
|
+
def an_instance_method
|
49
|
+
# …
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
This particular module would be found in `app/models/user/password_reset_extension.rb`.
|
56
|
+
|
57
|
+
You may pass options to the augmentation as in the following example (taken from [henrik/augmentations.rb](https://gist.github.com/henrik/1281a6f3f6a9632886fa)):
|
58
|
+
|
59
|
+
module MyMod
|
60
|
+
augmentation do |excited: false|
|
61
|
+
attr_accessor :this_works
|
62
|
+
|
63
|
+
def self.class_method; "this works"; end
|
64
|
+
def instance_method; "this works"; end
|
65
|
+
|
66
|
+
# Parameters!
|
67
|
+
if excited
|
68
|
+
def self.hi
|
69
|
+
puts "Hi!!!"
|
70
|
+
end
|
71
|
+
else
|
72
|
+
def self.hi
|
73
|
+
puts "Hi."
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
class MyClass
|
80
|
+
augment MyMod
|
81
|
+
end
|
82
|
+
|
83
|
+
class MyExcitedClass
|
84
|
+
augment MyMod, excited: true
|
85
|
+
end
|
86
|
+
|
87
|
+
## Credits
|
88
|
+
|
89
|
+
By [Henrik Nyh](http://henrik.nyh.se/) for [DanceJam](http://dancejam.com) under the MIT license:
|
90
|
+
|
91
|
+
Copyright (c) 2008 Henrik Nyh
|
92
|
+
|
93
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
94
|
+
of this software and associated documentation files (the "Software"), to deal
|
95
|
+
in the Software without restriction, including without limitation the rights
|
96
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
97
|
+
copies of the Software, and to permit persons to whom the Software is
|
98
|
+
furnished to do so, subject to the following conditions:
|
99
|
+
|
100
|
+
The above copyright notice and this permission notice shall be included in
|
101
|
+
all copies or substantial portions of the Software.
|
102
|
+
|
103
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
104
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
105
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
106
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
107
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
108
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
109
|
+
THE SOFTWARE.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'augmentations/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruby-augmentations"
|
8
|
+
spec.version = Augmentations::VERSION
|
9
|
+
spec.authors = ["Michael Cizl"]
|
10
|
+
spec.email = ["michael@mic-city.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{Gemified version of Henrik Nyh's augmentations}
|
13
|
+
spec.homepage = "https://github.com/mcizl/augmentations"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
20
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# "Augmentations" plugin for Rails.
|
2
|
+
# By Henrik Nyh <http://henrik.nyh.se> under the MIT license for DanceJam <http://dancejam.com> 2008-09-10.
|
3
|
+
# See README for usage.
|
4
|
+
# By Henrik Nyh 2015-04-02 under the MIT license.
|
5
|
+
|
6
|
+
class ::Module
|
7
|
+
def augmentation(**opts, &block)
|
8
|
+
@augmentation ||= block
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# "Augmentations" plugin for Rails.
|
2
|
+
# By Henrik Nyh <http://henrik.nyh.se> under the MIT license for DanceJam <http://dancejam.com> 2008-09-10.
|
3
|
+
# See README for usage.
|
4
|
+
# By Henrik Nyh 2015-04-02 under the MIT license.
|
5
|
+
|
6
|
+
class ::Object
|
7
|
+
def self.augment(*mods, **opts)
|
8
|
+
mods.each { |mod| class_exec **opts, &mod.augmentation }
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-augmentations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Michael Cizl
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '10.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '10.0'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- michael@mic-city.de
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- LICENSE.txt
|
36
|
+
- README.md
|
37
|
+
- augmentations.gemspec
|
38
|
+
- lib/augmentations.rb
|
39
|
+
- lib/augmentations/module.rb
|
40
|
+
- lib/augmentations/object.rb
|
41
|
+
- lib/augmentations/version.rb
|
42
|
+
homepage: https://github.com/mcizl/augmentations
|
43
|
+
licenses:
|
44
|
+
- MIT
|
45
|
+
metadata: {}
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 2.4.6
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: Gemified version of Henrik Nyh's augmentations
|
66
|
+
test_files: []
|