augmentations 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 +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +80 -0
- data/Rakefile +2 -0
- data/augmentations.gemspec +23 -0
- data/lib/augmentations.rb +16 -0
- data/lib/augmentations/version.rb +3 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b70b548d4c94b39b133cd288a1eaee38fae9a509
|
4
|
+
data.tar.gz: 4bfb874eecba260b418bbd79982f22a04b3b98df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51759b7c1ba281bbc4553e5297b3b626ebcb4772c06eaf61e7c7476c6ad1354407259754c4e7f7672ce4c38745c3aa5e6cb53b27244bdd4eae9c591a62066377
|
7
|
+
data.tar.gz: 771c9511ed5f321e5796f66fa81f61c689338bd239afb2f3e4555d1edeb99e53ff8ebff770219b33cfbf35989d9138f5a253a4855bded47a794fa2b622a2d32a
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Benjamin Randles-Dunkley
|
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,80 @@
|
|
1
|
+
# Augmentations gem
|
2
|
+
|
3
|
+
*Augmentations* is a tiny Ruby gem to easily extend any class with instance methods and class methods, as well as running class methods like `belongs_to` at extend time.
|
4
|
+
|
5
|
+
It's basically like `include`ing a module, but you can also 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.
|
6
|
+
|
7
|
+
Why do we need this now ActiveSupport has Concerns? Several reasons.
|
8
|
+
|
9
|
+
1: You're using plain Ruby or a non-Rails framework and you want the behaviour without the bulk of ActiveSupport.
|
10
|
+
|
11
|
+
2: You don't like the fact that ActiveSupport calls them 'Concerns' when they're just modules effectively implementing a form of multiple inheritance.
|
12
|
+
|
13
|
+
3: You don't like the module dependency management system built in to ActiveSupport Concerns. (Modules that depend on eachother are a code smell, cyclical dependencies doubly so.)
|
14
|
+
|
15
|
+
Use it like
|
16
|
+
|
17
|
+
class User < ActiveRecord::Base
|
18
|
+
augment Shared::Pingable, User::PasswordResetExtension
|
19
|
+
end
|
20
|
+
|
21
|
+
with modules like
|
22
|
+
|
23
|
+
module User::PasswordResetExtension
|
24
|
+
augmentation do
|
25
|
+
|
26
|
+
has_many :password_resets
|
27
|
+
|
28
|
+
def self.a_class_method
|
29
|
+
# …
|
30
|
+
end
|
31
|
+
|
32
|
+
def an_instance_method
|
33
|
+
# …
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
(If you want to weird things up in the name of fewer lines of code, the Ruby parser will accept
|
40
|
+
|
41
|
+
module User::PasswordResetExtension augmentation do
|
42
|
+
|
43
|
+
…
|
44
|
+
|
45
|
+
end end
|
46
|
+
|
47
|
+
too.)
|
48
|
+
|
49
|
+
|
50
|
+
## Installation
|
51
|
+
|
52
|
+
Add this line to your application's Gemfile:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
gem 'augmentations'
|
56
|
+
```
|
57
|
+
|
58
|
+
And then execute:
|
59
|
+
|
60
|
+
$ bundle
|
61
|
+
|
62
|
+
Or install it yourself as:
|
63
|
+
|
64
|
+
$ gem install augmentations
|
65
|
+
|
66
|
+
|
67
|
+
## Credits
|
68
|
+
|
69
|
+
Originally by [Henrik Nyh](http://henrik.nyh.se/) for [DanceJam](http://dancejam.com) under the MIT license.
|
70
|
+
|
71
|
+
[Original repository](https://github.com/henrik/augmentations/)
|
72
|
+
|
73
|
+
|
74
|
+
## Contributing
|
75
|
+
|
76
|
+
1. Fork it ( https://github.com/[my-github-username]/augmentations/fork )
|
77
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
78
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
79
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
80
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -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 'augmentations/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "augmentations"
|
8
|
+
spec.version = Augmentations::VERSION
|
9
|
+
spec.authors = ["Benjamin Randles-Dunkley"]
|
10
|
+
spec.email = ["ben@chemica.co.uk"]
|
11
|
+
spec.summary = %q{A tiny, focussed gem for easily creating 'concerns', based on https://github.com/henrik/augmentations}
|
12
|
+
spec.description = %q{The concern mechanism in ActiveSupport is handy but the code does a lot of stuff, most of which isn't needed in the vast majority of cases. Code you don't need is code that can cause unexpected issues. This gem, based on the wonderful 'augmnentations' plugin by henrik, provides similar behaviour without the cruft. Or, indeed, ActiveSupport.}
|
13
|
+
spec.homepage = "https://github.com/chemica/augmentations-gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require "augmentations/version"
|
2
|
+
|
3
|
+
module Augmentations
|
4
|
+
class ::Object
|
5
|
+
def self.augment(*mods)
|
6
|
+
include *mods
|
7
|
+
mods.each {|mod| class_eval &mod.augmentation }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class ::Module
|
12
|
+
def augmentation(&block)
|
13
|
+
@augmentation ||= block
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: augmentations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Benjamin Randles-Dunkley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ~>
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '1.6'
|
19
|
+
prerelease: false
|
20
|
+
name: bundler
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ~>
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '1.6'
|
26
|
+
type: :development
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '10.0'
|
33
|
+
prerelease: false
|
34
|
+
name: rake
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ~>
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '10.0'
|
40
|
+
type: :development
|
41
|
+
description: The concern mechanism in ActiveSupport is handy but the code does a lot
|
42
|
+
of stuff, most of which isn't needed in the vast majority of cases. Code you don't
|
43
|
+
need is code that can cause unexpected issues. This gem, based on the wonderful
|
44
|
+
'augmnentations' plugin by henrik, provides similar behaviour without the cruft.
|
45
|
+
Or, indeed, ActiveSupport.
|
46
|
+
email:
|
47
|
+
- ben@chemica.co.uk
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- .gitignore
|
53
|
+
- Gemfile
|
54
|
+
- LICENSE.txt
|
55
|
+
- README.md
|
56
|
+
- Rakefile
|
57
|
+
- augmentations.gemspec
|
58
|
+
- lib/augmentations.rb
|
59
|
+
- lib/augmentations/version.rb
|
60
|
+
homepage: https://github.com/chemica/augmentations-gem
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.2.2
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: A tiny, focussed gem for easily creating 'concerns', based on https://github.com/henrik/augmentations
|
84
|
+
test_files: []
|