active_admin-duplicatable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42f41d5e7fae2a92ff6a1f9313ef93c397a30405
4
+ data.tar.gz: f449e8e2636eabcc47df62b27120a52992dbc475
5
+ SHA512:
6
+ metadata.gz: fcbf8e38faf27424c3f3ff68aa4259338eb5dff2232cc552eae605c33420e698466471fc243db73771db5feff1776127b293ebc531ea00927e1e7b6eda879f81
7
+ data.tar.gz: 025e4868d42e24790bb1659fe62f7c341d3f8772592f82d3c0cca29406a15952cdc83e83bb8b0e4651ee4ac477672bf6ace62876ec2df49d47af07f5e5869328
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in activeadmin-subnav.gemspec
4
+ gemspec
@@ -0,0 +1,166 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ active_admin-duplicatable (0.0.1)
5
+ activeadmin
6
+ amoeba (>= 2.0.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (3.2.18)
12
+ actionpack (= 3.2.18)
13
+ mail (~> 2.5.4)
14
+ actionpack (3.2.18)
15
+ activemodel (= 3.2.18)
16
+ activesupport (= 3.2.18)
17
+ builder (~> 3.0.0)
18
+ erubis (~> 2.7.0)
19
+ journey (~> 1.0.4)
20
+ rack (~> 1.4.5)
21
+ rack-cache (~> 1.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.2.1)
24
+ activeadmin (0.6.3)
25
+ arbre (~> 1.0)
26
+ bourbon (>= 1.0.0, < 4)
27
+ devise (>= 1.5.4, < 4, != 2.2.2, != 2.2.1, != 2.2.0, != 2.1.2, != 2.1.1, != 2.1.0, != 2.0.4, != 2.0.3, != 2.0.2, != 2.0.1, != 2.0.0)
28
+ formtastic (~> 2.0)
29
+ inherited_resources (~> 1.3)
30
+ jquery-rails (>= 1.0.0, < 3)
31
+ kaminari (~> 0.13, != 0.15.0)
32
+ meta_search (~> 1.0)
33
+ rails (>= 3.0.0, < 4)
34
+ sass (~> 3.1)
35
+ activemodel (3.2.18)
36
+ activesupport (= 3.2.18)
37
+ builder (~> 3.0.0)
38
+ activerecord (3.2.18)
39
+ activemodel (= 3.2.18)
40
+ activesupport (= 3.2.18)
41
+ arel (~> 3.0.2)
42
+ tzinfo (~> 0.3.29)
43
+ activeresource (3.2.18)
44
+ activemodel (= 3.2.18)
45
+ activesupport (= 3.2.18)
46
+ activesupport (3.2.18)
47
+ i18n (~> 0.6, >= 0.6.4)
48
+ multi_json (~> 1.0)
49
+ amoeba (2.0.0)
50
+ activerecord (>= 3.0)
51
+ arbre (1.0.1)
52
+ activesupport (>= 3.0.0)
53
+ arel (3.0.3)
54
+ bcrypt (3.1.7)
55
+ bourbon (3.2.3)
56
+ sass (~> 3.2)
57
+ thor
58
+ builder (3.0.4)
59
+ devise (3.2.4)
60
+ bcrypt (~> 3.0)
61
+ orm_adapter (~> 0.1)
62
+ railties (>= 3.2.6, < 5)
63
+ thread_safe (~> 0.1)
64
+ warden (~> 1.2.3)
65
+ diff-lcs (1.2.5)
66
+ erubis (2.7.0)
67
+ formtastic (2.2.1)
68
+ actionpack (>= 3.0)
69
+ has_scope (0.6.0.rc)
70
+ actionpack (>= 3.2, < 5)
71
+ activesupport (>= 3.2, < 5)
72
+ hike (1.2.3)
73
+ i18n (0.6.9)
74
+ inherited_resources (1.4.1)
75
+ has_scope (~> 0.6.0.rc)
76
+ responders (~> 1.0.0.rc)
77
+ journey (1.0.4)
78
+ jquery-rails (2.3.0)
79
+ railties (>= 3.0, < 5.0)
80
+ thor (>= 0.14, < 2.0)
81
+ json (1.8.1)
82
+ kaminari (0.15.1)
83
+ actionpack (>= 3.0.0)
84
+ activesupport (>= 3.0.0)
85
+ mail (2.5.4)
86
+ mime-types (~> 1.16)
87
+ treetop (~> 1.4.8)
88
+ meta_search (1.1.3)
89
+ actionpack (~> 3.1)
90
+ activerecord (~> 3.1)
91
+ activesupport (~> 3.1)
92
+ polyamorous (~> 0.5.0)
93
+ mime-types (1.25.1)
94
+ multi_json (1.10.1)
95
+ orm_adapter (0.5.0)
96
+ polyamorous (0.5.0)
97
+ activerecord (~> 3.0)
98
+ polyglot (0.3.4)
99
+ rack (1.4.5)
100
+ rack-cache (1.2)
101
+ rack (>= 0.4)
102
+ rack-ssl (1.3.4)
103
+ rack
104
+ rack-test (0.6.2)
105
+ rack (>= 1.0)
106
+ rails (3.2.18)
107
+ actionmailer (= 3.2.18)
108
+ actionpack (= 3.2.18)
109
+ activerecord (= 3.2.18)
110
+ activeresource (= 3.2.18)
111
+ activesupport (= 3.2.18)
112
+ bundler (~> 1.0)
113
+ railties (= 3.2.18)
114
+ railties (3.2.18)
115
+ actionpack (= 3.2.18)
116
+ activesupport (= 3.2.18)
117
+ rack-ssl (~> 1.3.2)
118
+ rake (>= 0.8.7)
119
+ rdoc (~> 3.4)
120
+ thor (>= 0.14.6, < 2.0)
121
+ rake (10.3.2)
122
+ rdoc (3.12.2)
123
+ json (~> 1.4)
124
+ responders (1.0.0)
125
+ railties (>= 3.2, < 5)
126
+ rspec (3.0.0)
127
+ rspec-core (~> 3.0.0)
128
+ rspec-expectations (~> 3.0.0)
129
+ rspec-mocks (~> 3.0.0)
130
+ rspec-core (3.0.0)
131
+ rspec-support (~> 3.0.0)
132
+ rspec-expectations (3.0.0)
133
+ diff-lcs (>= 1.2.0, < 2.0)
134
+ rspec-support (~> 3.0.0)
135
+ rspec-mocks (3.0.0)
136
+ rspec-support (~> 3.0.0)
137
+ rspec-support (3.0.0)
138
+ sass (3.3.7)
139
+ sass-rails (3.2.6)
140
+ railties (~> 3.2.0)
141
+ sass (>= 3.1.10)
142
+ tilt (~> 1.3)
143
+ sprockets (2.2.2)
144
+ hike (~> 1.2)
145
+ multi_json (~> 1.0)
146
+ rack (~> 1.0)
147
+ tilt (~> 1.1, != 1.3.0)
148
+ thor (0.19.1)
149
+ thread_safe (0.3.3)
150
+ tilt (1.4.1)
151
+ treetop (1.4.15)
152
+ polyglot
153
+ polyglot (>= 0.3.1)
154
+ tzinfo (0.3.39)
155
+ warden (1.2.3)
156
+ rack (>= 1.0)
157
+
158
+ PLATFORMS
159
+ ruby
160
+
161
+ DEPENDENCIES
162
+ active_admin-duplicatable!
163
+ bundler (~> 1.6)
164
+ rake
165
+ rspec
166
+ sass-rails
@@ -0,0 +1,22 @@
1
+ Copyright (c) Charles Maresh
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,43 @@
1
+ # ActiveAdmin::Duplicatable
2
+
3
+ Simple duplication of [ActiveAdmin][] resources.
4
+
5
+ Allow user duplication of [ActiveAdmin][] resources through the power of the
6
+ [Amoeba][] gem. Resource duplication can be performed by either persisting the
7
+ model and its relations, or by pre-filling a new resource's form fields with
8
+ defaults.
9
+
10
+ ## Usage
11
+
12
+ Add duplication functionality a Post resource. See [Duplicatable][] for
13
+ documentation.
14
+
15
+ ```ruby
16
+ ActiveAdmin.register Post do
17
+ duplicatable
18
+ end
19
+ ```
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem 'active_admin-duplicatable'
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/zorab47/active_admin-duplicatable/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
40
+
41
+ [ActiveAdmin]: https://github.com/gregbell/active_admin
42
+ [Amoeba]: https://github.com/rocksolidwebdesign/amoeba
43
+ [Duplicatable]: lib/active_admin/duplicatable.rb
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_admin/duplicatable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_admin-duplicatable"
8
+ spec.version = Activeadmin::Duplicatable::VERSION
9
+ spec.authors = ["Charles Maresh"]
10
+ spec.email = ["charles.maresh@orm-tech.com"]
11
+ spec.summary = %q{Simple duplication of ActiveAdmin resources}
12
+ spec.description = <<DESC
13
+ Allow user duplication of ActiveAdmin resources using the power of the Amoeba
14
+ gem. Resource duplication can be performed by either persisting the model and its
15
+ relations, or by pre-filling a new resource's form fields.
16
+ DESC
17
+ spec.homepage = "https://github.com/zorab47/active_admin-duplicatable"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "activeadmin"
26
+ spec.add_dependency "amoeba", ">= 2.0.0"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.6"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rspec"
31
+
32
+ # required for active admin
33
+ spec.add_development_dependency "sass-rails"
34
+ end
@@ -0,0 +1,80 @@
1
+ require "active_admin"
2
+ require "active_admin/duplicatable/version"
3
+
4
+ module ActiveAdmin
5
+ module Duplicatable
6
+
7
+ extend ActiveSupport::Concern
8
+
9
+ # Public: Enable and configure resource duplication
10
+ #
11
+ # options - Duplication options (default: { via: :form }):
12
+ # :via - Method of duplication. Via `:save` is the only way to
13
+ # copy a resources relations not present in the form.
14
+ #
15
+ # Examples
16
+ #
17
+ # ActiveAdmin.register Post do
18
+ # duplicatable via: :save
19
+ # end
20
+ #
21
+ def duplicatable(options = {})
22
+ via = options.fetch(:via) { :form }
23
+
24
+ if via == :save
25
+ enable_resource_duplication_via_save
26
+ else
27
+ enable_resource_duplication_via_form
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ # Enables resource duplication via new form.
34
+ #
35
+ # - Adds a duplicate action button.
36
+ # - Preloads a duplicated resource on `:new` to pre-fill the form fields.
37
+ #
38
+ # No return.
39
+ def enable_resource_duplication_via_form
40
+ action_item :only => [:show] do
41
+ link_to(I18n.t(:duplicate_model, default: "Duplicate %{model}", scope: [:active_admin], model: active_admin_config.resource_label), action: :new, _source_id: resource.id)
42
+ end
43
+
44
+ controller do
45
+ before_filter only: :new do
46
+ if !params[:_source_id].blank?
47
+ source = resource_class.find(params[:_source_id])
48
+ @resource ||= source.amoeba_dup if source
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ # Enables resource duplication via save.
55
+ #
56
+ # - Adds a duplicate action button.
57
+ # - Duplicates a resource, persists it, and redirects the user to edit
58
+ # the newly duplicated resource.
59
+ #
60
+ # No return.
61
+ def enable_resource_duplication_via_save
62
+ action_item :only => [:show] do
63
+ link_to(I18n.t(:duplicate_model, default: "Duplicate %{model}", scope: [:active_admin], model: active_admin_config.resource_label), action: :duplicate)
64
+ end
65
+
66
+ member_action :duplicate do
67
+ resource = resource_class.find(params[:id])
68
+ duplicate = resource.amoeba_dup
69
+ if duplicate.save
70
+ redirect_to({ action: :edit, id: duplicate.id }, flash: { notice: "#{active_admin_config.resource_label} was successfully duplicated." })
71
+ else
72
+ redirect_to({ action: :show }, flash: { error: "#{active_admin_config.resource_label} could not be duplicated." })
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+ end
79
+
80
+ ActiveAdmin::ResourceDSL.send :include, ActiveAdmin::Duplicatable
@@ -0,0 +1,5 @@
1
+ module Activeadmin
2
+ module Duplicatable
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveAdmin::Duplicatable do
4
+
5
+ describe "extends ResourceDSL" do
6
+ it "by adding #duplicatable" do
7
+ dsl = ActiveAdmin::ResourceDSL
8
+
9
+ expect(dsl.public_instance_methods).to include(:duplicatable)
10
+ end
11
+ end
12
+
13
+ it "enables form-based duplication by default" do
14
+ dsl = ActiveAdmin::ResourceDSL.new(double 'config')
15
+
16
+ expect(dsl).to receive(:enable_resource_duplication_via_form)
17
+
18
+ dsl.duplicatable
19
+ end
20
+
21
+ it 'enables save-based duplication with option `via: :save`' do
22
+ dsl = ActiveAdmin::ResourceDSL.new(double 'config')
23
+
24
+ expect(dsl).to receive(:enable_resource_duplication_via_save)
25
+
26
+ dsl.duplicatable(via: :save)
27
+ end
28
+
29
+ end
@@ -0,0 +1,42 @@
1
+
2
+ require 'active_admin/duplicatable'
3
+
4
+ RSpec.configure do |config|
5
+ # These two settings work together to allow you to limit a spec run
6
+ # to individual examples or groups you care about by tagging them with
7
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
8
+ # get run.
9
+ config.filter_run :focus
10
+ config.run_all_when_everything_filtered = true
11
+
12
+ # Many RSpec users commonly either run the entire suite or an individual
13
+ # file, and it's useful to allow more verbose output when running an
14
+ # individual spec file.
15
+ if config.files_to_run.one?
16
+ # Use the documentation formatter for detailed output,
17
+ # unless a formatter has already been configured
18
+ # (e.g. via a command-line flag).
19
+ config.default_formatter = 'doc'
20
+ end
21
+
22
+ # Run specs in random order to surface order dependencies. If you find an
23
+ # order dependency and want to debug it, you can fix the order by providing
24
+ # the seed, which is printed after each run.
25
+ # --seed 1234
26
+ config.order = :random
27
+
28
+ # Seed global randomization in this process using the `--seed` CLI option.
29
+ # Setting this allows you to use `--seed` to deterministically reproduce
30
+ # test failures related to randomization by passing the same `--seed` value
31
+ # as the one that triggered the failure.
32
+ Kernel.srand config.seed
33
+
34
+ config.expect_with :rspec do |expectations|
35
+ expectations.syntax = :expect
36
+ end
37
+
38
+ config.mock_with :rspec do |mocks|
39
+ mocks.syntax = :expect
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_admin-duplicatable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Charles Maresh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeadmin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: amoeba
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sass-rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |
98
+ Allow user duplication of ActiveAdmin resources using the power of the Amoeba
99
+ gem. Resource duplication can be performed by either persisting the model and its
100
+ relations, or by pre-filling a new resource's form fields.
101
+ email:
102
+ - charles.maresh@orm-tech.com
103
+ executables: []
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - active_admin-duplicatable.gemspec
113
+ - lib/active_admin/duplicatable.rb
114
+ - lib/active_admin/duplicatable/version.rb
115
+ - spec/duplicatable_spec.rb
116
+ - spec/spec_helper.rb
117
+ homepage: https://github.com/zorab47/active_admin-duplicatable
118
+ licenses:
119
+ - MIT
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Simple duplication of ActiveAdmin resources
141
+ test_files:
142
+ - spec/duplicatable_spec.rb
143
+ - spec/spec_helper.rb
144
+ has_rdoc: