redmine_acts_as_taggable_on 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8e7906b676412d6701a0571b01f4d24d11e09a87
4
+ data.tar.gz: e2dc4f0179c28dad2125a7f7c7b97cc730399517
5
+ SHA512:
6
+ metadata.gz: 91dc58aa65759906381c28f8460a72aadac61f50eca5244f257d0646096ce19e211af798fffc08df4860fd2a29bc3f46d7258b00fca9ec0d8657a4f7ac767203
7
+ data.tar.gz: e15b4738667b7f367e024e28fa368e62dcfd2cbb775fd026a49a16935162ba57ca2d102532682caeb9a24446935c991798d5a8a31a3aa582efca72112b7f4277
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redmine_acts_as_taggable_on.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Harry Garrood
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,64 @@
1
+ # redmine_acts_as_taggable_on
2
+
3
+ `redmine_acts_as_taggable_on` is a gem which allows multiple Redmine plugins to
4
+ use the tables provided by `acts_as_taggable_on` without stepping on each
5
+ others' toes.
6
+
7
+ ## How it works
8
+
9
+ The problem we ran into when we discovered that both `redmine_tags` and
10
+ `redmine_knowledgebase` want to use the `acts_as_taggable_on` gem is that after
11
+ either is installed, the migration for the other fails, since the database
12
+ tables already exist.
13
+
14
+ Additionally, the plugins must choose between two less than ideal options when
15
+ uninstalling:
16
+
17
+ * Drop the tables, destroying data which may still be in use by another plugin
18
+ * Leave the tables there, violating the user's expectation that the database
19
+ should be back to how it was before the plugin was installed
20
+
21
+ `redmine_acts_as_taggable_on` solves this issue by giving Redmine plugins a
22
+ mechanism to declare that they require these tables, and providing intelligent
23
+ migrations which only drop the tables when no other plugins are using them.
24
+
25
+ `redmine_acts_as_taggable_on` also provides a limited defence against plugins
26
+ which directly depend on `acts-as-taggable-on` by grepping through their
27
+ Gemfiles for the string `acts-as-taggable-on`, and treating them the same way
28
+ as plugins which use this gem, together with a gentle(-ish) suggestion to
29
+ use this gem instead.
30
+
31
+ ## Status
32
+
33
+ **Believed to be stable; not extensively tested in the wild.**
34
+
35
+ ## Limitations
36
+
37
+ This plugin cannot currently protect against situations where a plugin directly
38
+ using `acts-as-taggable-on` has put the generated migration into its
39
+ db/migrate, and the Redmine admin tries to uninstall it.
40
+
41
+ I'm in two minds about whether to fix this: one the one hand, it would require
42
+ some nasty hackery, and it's no worse than the current situation. On the other,
43
+ losing one's data is not fun.
44
+
45
+ ## Setup
46
+
47
+ Add it to your plugin's Gemfile:
48
+
49
+ gem 'redmine_acts_as_taggable_on', '~> 0.1'
50
+
51
+ Add the migration:
52
+
53
+ echo 'class AddTagsAndTaggings < RedmineActsAsTaggableOn::Migration; end' \
54
+ > db/migrate/001_add_tags_and_taggings.rb
55
+
56
+ Declare that your plugin needs `redmine_acts_as_taggable_on` inside init.rb:
57
+
58
+ require 'redmine_acts_as_taggable_on/initialize'
59
+
60
+ Redmine::Plugin.register :my_plugin do
61
+ requires_acts_as_taggable_on
62
+ ...
63
+
64
+ That's it. Your plugin should now migrate up and down intelligently.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ require 'redmine'
2
+ require 'acts-as-taggable-on'
3
+ require 'redmine_acts_as_taggable_on/migration'
4
+ require 'redmine_acts_as_taggable_on/redmine_plugin_patch'
5
+
6
+ module RedmineActsAsTaggableOn
7
+ def self.initialize
8
+ unless @initialized
9
+ Redmine::Plugin.send(:include,
10
+ RedmineActsAsTaggableOn::RedminePluginPatch)
11
+ end
12
+ @initialized = true
13
+ end
14
+ end
15
+
16
+ RedmineActsAsTaggableOn.initialize
@@ -0,0 +1,63 @@
1
+ require 'generators/acts_as_taggable_on/migration/templates/active_record/migration'
2
+
3
+ class RedmineActsAsTaggableOn::Migration < ActsAsTaggableOnMigration
4
+ def up
5
+ enforce_declarations!
6
+
7
+ if performed?
8
+ say 'Not creating "tags" and "taggings" because they already exist'
9
+ else
10
+ super
11
+ end
12
+ end
13
+
14
+ def down
15
+ enforce_declarations!
16
+
17
+ if ok_to_go_down?
18
+ super
19
+ else
20
+ say 'Not dropping "tags" and "taggings" because they\'re still needed by'
21
+ say 'the following plugins:'
22
+ requiring_plugins.each { |p| say p.id, true }
23
+ end
24
+ end
25
+
26
+ private
27
+ def performed?
28
+ ['tags', 'taggings'].any? do |table|
29
+ ActiveRecord::Base.connection.table_exists? table
30
+ end
31
+ end
32
+
33
+ # A list of plugins which require redmine_acts_as_taggable_on.
34
+ #
35
+ # We reject the current one because we don't want to say
36
+ #
37
+ # refusing to migrate redmine_foo down: tags and taggings tables are still
38
+ # required by redmine_foo
39
+ #
40
+ # That would be silly.
41
+ def requiring_plugins
42
+ Redmine::Plugin.all.
43
+ select(&:requires_acts_as_taggable_on?).
44
+ reject {|p| p == Redmine::Plugin::Migrator.current_plugin }
45
+ end
46
+
47
+ def ok_to_go_down?
48
+ requiring_plugins.empty?
49
+ end
50
+
51
+ def enforce_declarations!
52
+ unless current_plugin_declaration_made?
53
+ msg = "You have to declare that you need redmine_acts_as_taggable_on inside\n"
54
+ msg << "init.rb. See https://github.com/hdgarrood/redmine_acts_as_taggable_on\n"
55
+ msg << "for more details.\n\n"
56
+ fail msg
57
+ end
58
+ end
59
+
60
+ def current_plugin_declaration_made?
61
+ Redmine::Plugin::Migrator.current_plugin.requires_acts_as_taggable_on?
62
+ end
63
+ end
@@ -0,0 +1,36 @@
1
+ module RedmineActsAsTaggableOn::RedminePluginPatch
2
+ def requires_acts_as_taggable_on
3
+ @requires_acts_as_taggable_on = true
4
+ end
5
+
6
+ def requires_acts_as_taggable_on?
7
+ return true if @requires_acts_as_taggable_on
8
+
9
+ # Safety net: If the plugin uses the acts-as-taggable-on gem the old way,
10
+ # assume that it requires the tables.
11
+ if File.exist?(gemfile_path)
12
+ if File.read(gemfile_path).include? 'acts-as-taggable-on'
13
+ warn_about_acts_as_taggable_on
14
+ return true
15
+ end
16
+ end
17
+
18
+ false
19
+ end
20
+
21
+ private
22
+ def gemfile_path
23
+ File.join(self.directory, 'Gemfile')
24
+ end
25
+
26
+ def warn_about_acts_as_taggable_on
27
+ unless @already_warned_about_acts_as_taggable_on
28
+ msg = "\nWARNING: The plugin #{self.id} is using 'acts-as-taggable-on',\n"
29
+ msg << "which means that it might accidentally delete some of your data\n"
30
+ msg << "when you uninstall it. You should badger its maintainer to switch\n"
31
+ msg << "to https://github.com/hdgarrood/redmine_acts_as_taggable_on.\n\n"
32
+ $stderr.write msg
33
+ end
34
+ @already_warned_about_acts_as_taggable_on = true
35
+ end
36
+ end
@@ -0,0 +1,3 @@
1
+ module RedmineActsAsTaggableOn
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1 @@
1
+ require "redmine_acts_as_taggable_on/version"
@@ -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 'redmine_acts_as_taggable_on/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "redmine_acts_as_taggable_on"
8
+ spec.version = RedmineActsAsTaggableOn::VERSION
9
+ spec.authors = ["Harry Garrood"]
10
+ spec.email = ["hdgarrood@gmail.com"]
11
+ spec.description = %q{Allows multiple Redmine plugins to use tags safely}
12
+ spec.summary = %q{Allows multiple Redmine plugins to use the acts_as_taggable_on gem without stepping on each others' toes.}
13
+ spec.homepage = "https://github.com/hdgarrood/redmine_acts_as_taggable_on"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_runtime_dependency "acts-as-taggable-on", "~> 2.4"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redmine_acts_as_taggable_on
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Harry Garrood
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-05-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: acts-as-taggable-on
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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: Allows multiple Redmine plugins to use tags safely
56
+ email:
57
+ - hdgarrood@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/redmine_acts_as_taggable_on.rb
68
+ - lib/redmine_acts_as_taggable_on/initialize.rb
69
+ - lib/redmine_acts_as_taggable_on/migration.rb
70
+ - lib/redmine_acts_as_taggable_on/redmine_plugin_patch.rb
71
+ - lib/redmine_acts_as_taggable_on/version.rb
72
+ - redmine_acts_as_taggable_on.gemspec
73
+ homepage: https://github.com/hdgarrood/redmine_acts_as_taggable_on
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.0
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Allows multiple Redmine plugins to use the acts_as_taggable_on gem without
97
+ stepping on each others' toes.
98
+ test_files: []
99
+ has_rdoc: