decorators 1.0.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.
data/lib/decorators.rb ADDED
@@ -0,0 +1,35 @@
1
+ module Decorators
2
+ require 'decorators/paths'
3
+ require 'decorators/railtie'
4
+
5
+ class << self
6
+ def load!(cache_classes)
7
+ decorators.each do |decorator|
8
+ if cache_classes
9
+ require decorator
10
+ else
11
+ load decorator
12
+ end
13
+ end
14
+ end
15
+
16
+ attr_accessor :decorators
17
+ def decorators
18
+ paths.registered.map { |path|
19
+ Dir[path.join('app', 'decorators', '**', '*_decorator.rb')]
20
+ }.flatten.uniq
21
+ end
22
+
23
+ def register!(*paths_to_register)
24
+ paths_to_register.flatten.map do |path|
25
+ paths.register! path
26
+ end
27
+ end
28
+
29
+ protected
30
+ def paths
31
+ @paths ||= Paths.new
32
+ end
33
+ end
34
+
35
+ end
@@ -0,0 +1,16 @@
1
+ require 'pathname'
2
+
3
+ module Decorators
4
+ class Paths
5
+
6
+ attr_reader :registered
7
+ def initialize(*args)
8
+ @registered = Array.new(*args)
9
+ end
10
+
11
+ def register!(path)
12
+ @registered << Pathname.new(path)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require 'rails'
2
+
3
+ module Decorators
4
+ class Railtie < Rails::Railtie
5
+
6
+ config.to_prepare do
7
+ Decorators.load! Rails.application.config.cache_classes
8
+ end
9
+
10
+ end
11
+ end
data/license.md ADDED
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2013 [Philip Arndt](http://philiparndt.name)
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,45 @@
1
+ # Decorators Plugin
2
+
3
+ This is a very simple plugin that adds support for decorators to your Rails application.
4
+ Effectively all that this does is allow you to register paths in which to search
5
+ for decorators which are then loaded at the appropriate point in your application's
6
+ initialisation process.
7
+
8
+ Decorators must follow this naming convention:
9
+
10
+ app/decorators/<any number of directories>/something_decorator.rb
11
+
12
+ The important parts are being inside a sub directory of `app/decorators` and having
13
+ `_decorator.rb` at the end of the file's name.
14
+
15
+ ## How to install
16
+
17
+ In your Gemfile, add the gem:
18
+
19
+ ```ruby
20
+ gem 'decorators', '~> 1.0.0'
21
+ ```
22
+
23
+ Now, run `bundle install` and the gem should install.
24
+
25
+ ## How to use
26
+
27
+ There really is just one method to call; `Decorators#register!`.
28
+ Simply pass one path or many paths to the method to register paths to search
29
+ inside for decorators to be loaded from.
30
+
31
+ ```ruby
32
+ require 'decorators'
33
+ Decorators.register! Rails.root
34
+ ```
35
+
36
+ Or for many paths:
37
+
38
+ ```ruby
39
+ require 'decorators'
40
+ Decorators.register! Rails.root, Rails.root.join('vendor', 'extensions', 'extension_with_decorators')
41
+ ```
42
+ ## License
43
+
44
+ Decorators is released under the [MIT license](https://github.com/parndt/decorators/blob/master/license.md#readme)
45
+ and is copyright (c) 2013 [Philip Arndt](http://philiparndt.name)
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decorators
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Philip Arndt
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ prerelease: false
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.2.11
22
+ none: false
23
+ type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: 3.2.11
29
+ none: false
30
+ description: Manages the process of loading decorators into your Rails application.
31
+ email: parndt@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - lib/decorators.rb
37
+ - lib/decorators/paths.rb
38
+ - lib/decorators/railtie.rb
39
+ - license.md
40
+ - readme.md
41
+ homepage: http://philiparndt.name
42
+ licenses:
43
+ - MIT
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ none: false
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ none: false
60
+ requirements: []
61
+ rubyforge_project:
62
+ rubygems_version: 1.8.24
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Rails decorators plugin.
66
+ test_files: []
67
+ has_rdoc: