enrich 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +36 -0
- data/Rakefile +6 -0
- data/bin/console +7 -0
- data/bin/setup +6 -0
- data/enrich.gemspec +30 -0
- data/lib/enrich.rb +5 -0
- data/lib/enrich/auto_delegate.rb +55 -0
- data/lib/enrich/base.rb +32 -0
- data/lib/enrich/railtie.rb +9 -0
- data/lib/enrich/version.rb +3 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f017828aa13e54e144a8522671f22bddb56ccc5c
|
4
|
+
data.tar.gz: c8d564e3e8714e5fcef4cbe6b6fe7f91cb0b88fb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7bfbcb184f6c2e0e50e53879e609de2905c2e161780e5ab27a56932cf6c07ffb85d7752cd16c448a2f62ee8ec2c5bbdb6c3db0dafa45bd721c6f26cf27712f8e
|
7
|
+
data.tar.gz: 26e1d8698ab4d6213adc0a32f2aee49283ec4bd3569328eb92028445457ed48c075ca7844575323668c9dbee9ec8d4e09608fa8cfd0dc54d53699daff5f7dfbf
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.0
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Ricardo Otero
|
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,36 @@
|
|
1
|
+
# Enrich
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'enrich'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install enrich
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rikas/enrich.
|
32
|
+
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/enrich.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'enrich/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'enrich'
|
8
|
+
spec.version = Enrich::VERSION
|
9
|
+
spec.authors = %w(Ricardo Otero)
|
10
|
+
spec.email = %w(oterosantos@gmail.com)
|
11
|
+
|
12
|
+
spec.summary = 'Very basic gem to make Rails decorators'
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = 'https://github.com/rikas/enrich'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = %w(lib)
|
21
|
+
|
22
|
+
spec.add_dependency 'activesupport'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'pry'
|
25
|
+
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'rake'
|
27
|
+
spec.add_development_dependency 'rspec'
|
28
|
+
spec.add_development_dependency 'rubocop'
|
29
|
+
spec.add_development_dependency 'rubocop-rspec'
|
30
|
+
end
|
data/lib/enrich.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module Enrich
|
4
|
+
module AutoDelegate
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
# Delegates missing instance methods to the source object.
|
8
|
+
def method_missing(method, *args, &block)
|
9
|
+
return super unless delegatable?(method)
|
10
|
+
|
11
|
+
# self.singleton_class.delegate method, to: :object
|
12
|
+
object.send(method, *args, &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Checks if the decorator responds to an instance method, or is able to
|
16
|
+
# proxy it to the source object.
|
17
|
+
def respond_to_missing?(method, include_private = false)
|
18
|
+
super || delegatable?(method)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delegatable?(method)
|
22
|
+
object.respond_to?(method)
|
23
|
+
end
|
24
|
+
|
25
|
+
module ClassMethods
|
26
|
+
# Proxies missing class methods to the source class.
|
27
|
+
def method_missing(method, *args, &block)
|
28
|
+
return super unless delegatable?(method)
|
29
|
+
|
30
|
+
object_class.send(method, *args, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Checks if the decorator responds to a class method, or is able to proxy
|
34
|
+
# it to the source class.
|
35
|
+
def respond_to_missing?(method, include_private = false)
|
36
|
+
super || delegatable?(method)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @private
|
40
|
+
def delegatable?(method)
|
41
|
+
object_class? && object_class.respond_to?(method)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Avoids reloading the model class when ActiveSupport clears autoloaded
|
45
|
+
# dependencies in development mode.
|
46
|
+
def before_remove_const
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
included do
|
51
|
+
private :delegatable?
|
52
|
+
private_class_method :delegatable?
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/enrich/base.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'enrich/auto_delegate'
|
2
|
+
|
3
|
+
module Enrich
|
4
|
+
class Base
|
5
|
+
include AutoDelegate
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def decorate(object)
|
9
|
+
if object.is_a?(ActiveRecord::Base)
|
10
|
+
new(object)
|
11
|
+
else
|
12
|
+
object.map { |obj| new(obj) }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :d, :decorate
|
17
|
+
end
|
18
|
+
|
19
|
+
def initialize(object)
|
20
|
+
@object = object
|
21
|
+
end
|
22
|
+
|
23
|
+
def object
|
24
|
+
@object
|
25
|
+
end
|
26
|
+
|
27
|
+
# Ability to use ActionController helpers
|
28
|
+
def h
|
29
|
+
ActionController::Base.helpers
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: enrich
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ricardo
|
8
|
+
- Otero
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: pry
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: bundler
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rspec
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rubocop
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: rubocop-rspec
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
description: Very basic gem to make Rails decorators
|
113
|
+
email:
|
114
|
+
- oterosantos@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".ruby-version"
|
122
|
+
- ".travis.yml"
|
123
|
+
- Gemfile
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- enrich.gemspec
|
130
|
+
- lib/enrich.rb
|
131
|
+
- lib/enrich/auto_delegate.rb
|
132
|
+
- lib/enrich/base.rb
|
133
|
+
- lib/enrich/railtie.rb
|
134
|
+
- lib/enrich/version.rb
|
135
|
+
homepage: https://github.com/rikas/enrich
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.5.1
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Very basic gem to make Rails decorators
|
159
|
+
test_files: []
|