eager_decorator 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/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +27 -0
- data/Rakefile +7 -0
- data/eager_decorator.gemspec +20 -0
- data/gemfiles/Gemfile-rails.3.2.x +5 -0
- data/gemfiles/Gemfile-rails.4.0.x +5 -0
- data/gemfiles/Gemfile-rails.4.1.x +5 -0
- data/gemfiles/Gemfile-rails.4.2.x +5 -0
- data/lib/eager_decorator.rb +3 -0
- data/lib/eager_decorator/decorator.rb +19 -0
- data/lib/eager_decorator/railtie.rb +9 -0
- data/lib/eager_decorator/version.rb +3 -0
- data/lib/generators/rails/decorator_generator.rb +12 -0
- data/lib/generators/rails/templates/decorator.rb +2 -0
- data/spec/decorators/user_decorator_spec.rb +13 -0
- data/spec/dummy/app/decorators/user_decorator.rb +5 -0
- data/spec/dummy/config.rb +27 -0
- data/spec/spec_helper.rb +20 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9985de85e2f4c6e1412f1d47f442fcbbbf946764
|
4
|
+
data.tar.gz: 5c98cd1418bb39fd63c5d19873a9e9cf99d03ce3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 01671331b1e6ecd71a3bd0b95701df08b6cd059d30d49c192fd72138a908ad973391b1d58027561f44d6366db8bac407cabd076d54d64fa7ed41d78c9808809c
|
7
|
+
data.tar.gz: f9c9fe0f517cc2cc9e0c5e016eec7928da8801b6a2d553050dccf32bff5f78716f3f7eb767fd7fb699c23689fbde97bde46139289a737356dcbe5336659c07af
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 KouyaFukuda
|
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,27 @@
|
|
1
|
+
# EagerDecorator [![Build Status](https://travis-ci.org/kouyaf77/eager_decorator.svg)](https://travis-ci.org/kouyaf77/eager_decorator)
|
2
|
+
|
3
|
+
A simple decorator for Rails 3 and Rails 4.
|
4
|
+
Always, the decorator is mixed automatically in model.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'eager_decorator'
|
12
|
+
```
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
You can use the denerator like the following.
|
16
|
+
|
17
|
+
```
|
18
|
+
$ rails g decorator user
|
19
|
+
```
|
20
|
+
## Supported versions
|
21
|
+
|
22
|
+
* Ruby 1.9.3, 2.0.0, 2.1.0
|
23
|
+
* Ruby 3.2.0, 4.0.0, 4.1.0, 4.2.0
|
24
|
+
|
25
|
+
## Copyright
|
26
|
+
|
27
|
+
Copyright (c) 2015 Koya Fukuda. See MIT-LICENSE for further details.
|
data/Rakefile
ADDED
@@ -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 "eager_decorator/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "eager_decorator"
|
8
|
+
spec.version = EagerDecorator::VERSION
|
9
|
+
spec.authors = ["KoyaFukuda"]
|
10
|
+
spec.email = ["kouyaf77@gmail.com"]
|
11
|
+
spec.summary = %q{A simple Decorator for Rails}
|
12
|
+
spec.description = %q{A simple Decorator for Rails}
|
13
|
+
spec.homepage = ""
|
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
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "singleton"
|
2
|
+
|
3
|
+
module EagerDecorator
|
4
|
+
class Decorator
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
path = "#{Rails.root}/app/decorators/**/*.rb"
|
9
|
+
|
10
|
+
Dir.glob(path).each do |file|
|
11
|
+
model_name = File.basename(file, ".rb").sub(/_decorator/, "")
|
12
|
+
model = model_name.classify.constantize rescue nil
|
13
|
+
unless model.nil?
|
14
|
+
model.send(:include, "#{model_name.classify}Decorator".constantize)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Rails
|
2
|
+
module Generators
|
3
|
+
class DecoratorGenerator < Rails::Generators::NamedBase
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
def create_decorator_file
|
7
|
+
template("decorator.rb",
|
8
|
+
File.join("app/decorators", "#{singular_name}_decorator.rb"))
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe UserDecorator do
|
4
|
+
let(:user_name){"user_name"}
|
5
|
+
before do
|
6
|
+
User.create(:name => user_name)
|
7
|
+
end
|
8
|
+
|
9
|
+
context "When there is #reverse_name in user model" do
|
10
|
+
subject {User.first.reverse_name}
|
11
|
+
it {is_expected.to eq user_name.reverse}
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "action_controller/railtie"
|
3
|
+
require "action_view/railtie"
|
4
|
+
|
5
|
+
# model
|
6
|
+
class User < ActiveRecord::Base; end
|
7
|
+
|
8
|
+
# migrations
|
9
|
+
class CreateAllTables < ActiveRecord::Migration
|
10
|
+
def self.up
|
11
|
+
create_table(:users) {|t| t.string :name}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# config
|
16
|
+
ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
|
17
|
+
module EagerDecoratorTestApp
|
18
|
+
class Application < Rails::Application
|
19
|
+
config.root = "spec/dummy"
|
20
|
+
config.secret_token = "confusion will be my epitaph."
|
21
|
+
config.session_store :cookie_store, :key => "_myapp_session"
|
22
|
+
config.active_support.deprecation = :log
|
23
|
+
config.eager_load = false
|
24
|
+
config.action_dispatch.show_exceptions = false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
EagerDecoratorTestApp::Application.initialize!
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
|
3
|
+
require "rails"
|
4
|
+
require "eager_decorator"
|
5
|
+
require "dummy/config"
|
6
|
+
require "rspec/rails"
|
7
|
+
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.before :all do
|
12
|
+
unless ActiveRecord::Base.connection.table_exists?("users")
|
13
|
+
CreateAllTables.up
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
config.before :each do
|
18
|
+
User.delete_all
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eager_decorator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- KoyaFukuda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple Decorator for Rails
|
14
|
+
email:
|
15
|
+
- kouyaf77@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".travis.yml"
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- eager_decorator.gemspec
|
28
|
+
- gemfiles/Gemfile-rails.3.2.x
|
29
|
+
- gemfiles/Gemfile-rails.4.0.x
|
30
|
+
- gemfiles/Gemfile-rails.4.1.x
|
31
|
+
- gemfiles/Gemfile-rails.4.2.x
|
32
|
+
- lib/eager_decorator.rb
|
33
|
+
- lib/eager_decorator/decorator.rb
|
34
|
+
- lib/eager_decorator/railtie.rb
|
35
|
+
- lib/eager_decorator/version.rb
|
36
|
+
- lib/generators/rails/decorator_generator.rb
|
37
|
+
- lib/generators/rails/templates/decorator.rb
|
38
|
+
- spec/decorators/user_decorator_spec.rb
|
39
|
+
- spec/dummy/app/decorators/user_decorator.rb
|
40
|
+
- spec/dummy/config.rb
|
41
|
+
- spec/spec_helper.rb
|
42
|
+
homepage: ''
|
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.2.2
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: A simple Decorator for Rails
|
66
|
+
test_files:
|
67
|
+
- spec/decorators/user_decorator_spec.rb
|
68
|
+
- spec/dummy/app/decorators/user_decorator.rb
|
69
|
+
- spec/dummy/config.rb
|
70
|
+
- spec/spec_helper.rb
|