activeadmin-poro-decorator 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 205e0292c9de856479a602d2614bd6bcf34bccd8
4
+ data.tar.gz: 313c729a50491886d17fdc503f13aedc17dab638
5
+ SHA512:
6
+ metadata.gz: 8094bb66b7e7dcf04e710e631a9ac881c2f4ef76e45ca128cf5a83301581245c2536d1cb610184d186ad4a4af3d4cd46c4e889e91c987d81f2f6f47b48e705e8
7
+ data.tar.gz: ae48c621199a707a9402e273b95876d4def30953578f32ef8d23f97a7bbeb269f7fe2ee5623b8a4b064690fb206b691f5dceaa88fcdbffe449bafaa7e62bac65
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ pkg
2
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activeadmin-poro-decorator.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ activeadmin-poro-decorator (0.0.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.2.5)
10
+ rake (10.3.2)
11
+ rspec (3.1.0)
12
+ rspec-core (~> 3.1.0)
13
+ rspec-expectations (~> 3.1.0)
14
+ rspec-mocks (~> 3.1.0)
15
+ rspec-core (3.1.7)
16
+ rspec-support (~> 3.1.0)
17
+ rspec-expectations (3.1.2)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.1.0)
20
+ rspec-mocks (3.1.3)
21
+ rspec-support (~> 3.1.0)
22
+ rspec-support (3.1.2)
23
+
24
+ PLATFORMS
25
+ ruby
26
+
27
+ DEPENDENCIES
28
+ activeadmin-poro-decorator!
29
+ bundler (~> 1.7)
30
+ rake (~> 10.0)
31
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Krivich Ekaterina
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,70 @@
1
+ # Activeadmin Poro Decorator
2
+
3
+ Alternative for draper, if you need decorators at ActiveAdmin (and Rails).
4
+ Active Admin uses the Draper gem for [decorators](http://activeadmin.info/docs/11-decorators.html), but sometimes you don't need that.
5
+ For reasons you could read this article: http://thepugautomatic.com/2014/03/draper.
6
+
7
+ See discussion of PORO with Active Admin authors [here](https://github.com/activeadmin/activeadmin/issues/3600).
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'activeadmin-poro-decorator'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install activeadmin-poro-decorator
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ # app/admin/post.rb
29
+ ActiveAdmin.register Post do
30
+ decorate_with PostDecorator
31
+
32
+ permit_params :title
33
+
34
+ index do
35
+ column :id
36
+ column :title
37
+ column :hello #delegated
38
+ column :link_title #delegated
39
+ end
40
+ end
41
+
42
+ # app/presenters/post_decorator.rb
43
+ class PostDecorator < DelegateClass(Post)
44
+ include ActiveadminPoroDecorator
45
+
46
+ def self.model_name
47
+ ActiveModel::Name.new Post
48
+ end
49
+
50
+ def self.columns
51
+ Post.columns
52
+ end
53
+
54
+ def hello
55
+ "Hello, #{title}"
56
+ end
57
+
58
+ def link_title
59
+ helpers.link_to(id, url_helpers.admin_post_path(self))
60
+ end
61
+ end
62
+ ```
63
+
64
+ ## Contributing
65
+
66
+ 1. Fork it ( https://github.com/[my-github-username]/activeadmin-poro-decorator/fork )
67
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
68
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
69
+ 4. Push to the branch (`git push origin my-new-feature`)
70
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+ import "./lib/tasks/copy_config.rake"
3
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activeadmin-poro-decorator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activeadmin-poro-decorator"
8
+ spec.version = ActiveadminPoroDecorator::VERSION
9
+ spec.authors = ["Krivich Ekaterina"]
10
+ spec.email = ["krivich.ekaterina@gmail.com"]
11
+ spec.summary = %q{Plain Old Ruby Objects as Decorators for Active Admin}
12
+ spec.description = %q{Inspired by http://thepugautomatic.com/2014/03/draper/ to not use draper while decorating th}
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
+
21
+ spec.add_development_dependency 'bundler', '~> 1.7'
22
+ spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'rspec'
24
+ end
File without changes
@@ -0,0 +1,58 @@
1
+ require 'activeadmin-poro-decorator/version'
2
+ require 'activeadmin-poro-decorator/config'
3
+
4
+ module ActiveadminPoroDecorator
5
+ extend ActiveSupport::Concern
6
+
7
+ def helpers
8
+ ActionController::Base.helpers
9
+ end
10
+
11
+ included do
12
+ delegate :url_helpers, to: "Rails.application.routes"
13
+ end
14
+
15
+ module ClassMethods
16
+ def decorate(*args)
17
+ collection_or_object = args[0]
18
+ if collection_or_object.respond_to?(:to_ary)
19
+ class_name = collection_or_object.class.to_s.demodulize.gsub('ActiveRecord_Relation_', '')
20
+ DecoratedEnumerableProxy.new(collection_or_object, class_name)
21
+ else
22
+ new(collection_or_object)
23
+ end
24
+ end
25
+
26
+ def helpers
27
+ ActionController::Base.helpers
28
+ end
29
+ end
30
+
31
+ class DecoratedEnumerableProxy < DelegateClass(ActiveRecord::Relation)
32
+ include Enumerable
33
+
34
+ delegate :as_json, :collect, :map, :each, :[], :all?, :include?, :first, :last, :shift, :to => :decorated_collection
35
+
36
+ def initialize(collection, class_name)
37
+ super(collection)
38
+ @class_name = class_name
39
+ end
40
+
41
+ def klass
42
+ "#{@class_name}Decorator".constantize
43
+ end
44
+
45
+ def wrapped_collection
46
+ __getobj__
47
+ end
48
+
49
+ def decorated_collection
50
+ @decorated_collection ||= wrapped_collection.collect { |member| klass.decorate(member) }
51
+ end
52
+ alias_method :to_ary, :decorated_collection
53
+
54
+ def each(&blk)
55
+ to_ary.each(&blk)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,15 @@
1
+ require 'yaml'
2
+
3
+ module ActiveadminPoroDecorator
4
+ module Config
5
+ class Reader
6
+ def initialize
7
+ @config = YAML.load_file('activeadmin-poro-decorator.yml.example')
8
+ end
9
+ end
10
+
11
+ def read(option)
12
+ @config[option]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveadminPoroDecorator
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,8 @@
1
+ namespace :config do
2
+ desc "Copy the config of the active admin poro decorator"
3
+ task :copy do
4
+ source = File.join(Gem.loaded_specs["activeadmin-poro-decorator"].full_gem_path, "activeadmin-poro-decorator.yml.example")
5
+ target = File.join(Rails.root, "config", "activeadmin-poro-decorator.yml.example")
6
+ FileUtils.cp_r source, target
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ require 'activeadmin-poro-decorator'
3
+
4
+ RSpec.configure do |config|
5
+ config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ config.expect_with(:rspec) {|c| c.syntax = :expect}
7
+ config.order = :random
8
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activeadmin-poro-decorator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Krivich Ekaterina
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-26 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.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Inspired by http://thepugautomatic.com/2014/03/draper/ to not use draper
56
+ while decorating th
57
+ email:
58
+ - krivich.ekaterina@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - activeadmin-poro-decorator-0.0.1.gem
70
+ - activeadmin-poro-decorator.gemspec
71
+ - activeadmin-poro-decorator.yml.example
72
+ - lib/activeadmin-poro-decorator.rb
73
+ - lib/activeadmin-poro-decorator/config.rb
74
+ - lib/activeadmin-poro-decorator/version.rb
75
+ - lib/tasks/copy_config.rake
76
+ - spec/spec_helper.rb
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ metadata: {}
81
+ post_install_message:
82
+ rdoc_options: []
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ requirements: []
96
+ rubyforge_project:
97
+ rubygems_version: 2.0.14
98
+ signing_key:
99
+ specification_version: 4
100
+ summary: Plain Old Ruby Objects as Decorators for Active Admin
101
+ test_files:
102
+ - spec/spec_helper.rb