decco 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 974d9239198f155da63fbacdd3db453d6db54399
4
+ data.tar.gz: 499b6ee248ec6a1e5312108072014078c8a9af3c
5
+ SHA512:
6
+ metadata.gz: b3890e3f22f3df6b44cd9bc88b7c3656e7a14000b1c460cb507fdb11ad79f911e6589b71be32db0bb791675e95fcb545b9c40309a5714ad4d54c289f5ab109d2
7
+ data.tar.gz: 43479762624960fe062cc9670672d110c6683f8d1ca640399e9e452f9714da50abef65f467642d4c8754dc0b71156fc295c1f498cbbb975f6c7dcf59d07cc045
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in d.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 kris
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.
@@ -0,0 +1,56 @@
1
+ # Decco
2
+
3
+ A simple, light weight decorator system based on PORO.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'decco'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install decco
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ # Attempt to decorate based on object
25
+ instance = Decco.decorate(@user) # UserDecorator
26
+ instance.gravatar
27
+ ```
28
+
29
+ If you're using Rails, you get a convenient helper
30
+ ```ruby
31
+ d(@user).gravatar
32
+ ```
33
+
34
+ To define a decorator
35
+ ```ruby
36
+ class UserDecorator
37
+ def initialize(user, view)
38
+ @user = user
39
+ @view = view
40
+ end
41
+
42
+ def gravatar(options = {})
43
+ hash = Digest::MD5.hexdigest(@user.email)
44
+ gravatar_url = "http://www.gravatar.com/avatar/#{hash}?#{options.to_query}"
45
+ @view.image_tag gravatar_url
46
+ end
47
+ end
48
+ ```
49
+
50
+ ## Contributing
51
+
52
+ 1. Fork it ( https://github.com/[my-github-username]/d/fork )
53
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
54
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
55
+ 4. Push to the branch (`git push origin my-new-feature`)
56
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require 'rspec/core/rake_task'
2
+ require 'bundler/gem_tasks'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |task|
5
+ task.rspec_opts = ['--color', '--format', 'documentation']
6
+ end
7
+
8
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'decco/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "decco"
8
+ spec.version = Decco::VERSION
9
+ spec.authors = ["kris"]
10
+ spec.email = ["kris@octohq.com"]
11
+ spec.summary = %q{Simple Decorators}
12
+ spec.description = %q{A simple decorator based on PORO}
13
+ spec.homepage = "http://github.com/kris/decco"
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.7"
22
+ spec.add_development_dependency "rake", "~> 10.4"
23
+ spec.add_development_dependency "rspec", "~> 3.1"
24
+ spec.add_development_dependency "rspec-rails", "~> 3.1"
25
+ end
@@ -0,0 +1,31 @@
1
+ require 'decco/version'
2
+ require 'decco/helpers'
3
+ require 'decco/railtie' if defined?(Rails)
4
+
5
+ module Decco
6
+ # When no decorates are found, raise DecoratorNotFound
7
+ class DecoratorNotFound < NameError; end
8
+
9
+ # Decorate an object
10
+ #
11
+ # @param [Object] Object to decorate
12
+ # @param [Mixed] Decorator to use, default to <Class>Decorator
13
+ # @param [Mixed] View context
14
+ # @return [Mixed]
15
+ def self.decorate(object, decorator = nil, view = nil)
16
+ @_d ||= {}
17
+ @_d[object] ||= builder(object, decorator, view)
18
+ rescue NameError
19
+ raise DecoratorNotFound
20
+ end
21
+
22
+ # Get decorator
23
+ #
24
+ # @see .decorate
25
+ # @return [Mixed]
26
+ def self.builder(object, decorator, view)
27
+ decorator || begin
28
+ [object.class.to_s, 'Decorator'].join('').classify.constantize
29
+ end.new(object, view)
30
+ end
31
+ end
@@ -0,0 +1,12 @@
1
+ module Decco
2
+ module Helpers
3
+ # Decorate, passing view context
4
+ #
5
+ # @param [Mixed] Object to decorate
6
+ # @param [Mixed] Decorator to use
7
+ # @return [Mixed] Decorator
8
+ def d(object, decorator = nil)
9
+ Decco.decorate(object, decorator, self)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ module Decco
2
+ class Railtie < Rails::Railtie
3
+ initializer 'decco.view_helpers' do
4
+ ActionView::Base.send :include, Helpers
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module Decco
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Decco do
4
+ context 'decorating' do
5
+ it 'should decorate a User instance' do
6
+ expect(Decco.decorate(User.new)).to be_an_instance_of(UserDecorator)
7
+ end
8
+
9
+ it 'should raise a DecoratorNotFound exception' do
10
+ expect {
11
+ Decco.decorate('test')
12
+ }.to raise_error(Decco::DecoratorNotFound)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'bundler/setup'
2
+ require 'decco'
3
+ require 'rails/version'
4
+ require 'action_controller'
5
+ require 'action_controller/test_case'
6
+
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.expect_with(:rspec) { |c| c.syntax = :expect }
10
+ config.order = :random
11
+ end
12
+
13
+ class User; end
14
+ class UserDecorator
15
+ def initialize(user, view); end
16
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decco
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - kris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ description: A simple decorator based on PORO
70
+ email:
71
+ - kris@octohq.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - decco.gemspec
82
+ - lib/decco.rb
83
+ - lib/decco/helpers.rb
84
+ - lib/decco/railtie.rb
85
+ - lib/decco/version.rb
86
+ - spec/decco_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: http://github.com/kris/decco
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Simple Decorators
112
+ test_files:
113
+ - spec/decco_spec.rb
114
+ - spec/spec_helper.rb