my_annotations 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/.rvmrc +1 -0
- data/AUTHORS.rdoc +5 -0
- data/CHANGELOG.rdoc +64 -0
- data/INDEX.rdoc +17 -0
- data/generators/annotations_migration/annotations_migration_generator.rb +32 -0
- data/generators/annotations_migration/templates/migration_v1.rb +60 -0
- data/generators/annotations_migration/templates/migration_v2.rb +9 -0
- data/generators/annotations_migration/templates/migration_v3.rb +74 -0
- data/generators/annotations_migration/templates/migration_v4.rb +13 -0
- data/install.rb +1 -0
- data/lib/annotations/acts_as_annotatable.rb +271 -0
- data/lib/annotations/acts_as_annotation_source.rb +117 -0
- data/lib/annotations/acts_as_annotation_value.rb +115 -0
- data/lib/annotations/config.rb +148 -0
- data/lib/annotations/routing.rb +8 -0
- data/lib/annotations/util.rb +82 -0
- data/lib/annotations_version_fu.rb +119 -0
- data/lib/app/controllers/annotations_controller.rb +162 -0
- data/lib/app/controllers/application_controller.rb +2 -0
- data/lib/app/helpers/application_helper.rb +2 -0
- data/lib/app/models/annotation.rb +413 -0
- data/lib/app/models/annotation_attribute.rb +37 -0
- data/lib/app/models/annotation_value_seed.rb +48 -0
- data/lib/app/models/number_value.rb +23 -0
- data/lib/app/models/text_value.rb +23 -0
- data/my_annotations.gemspec +4 -9
- data/rails/init.rb +8 -0
- data/test/acts_as_annotatable_test.rb +186 -0
- data/test/acts_as_annotation_source_test.rb +84 -0
- data/test/acts_as_annotation_value_test.rb +17 -0
- data/test/annotation_attribute_test.rb +22 -0
- data/test/annotation_test.rb +213 -0
- data/test/annotation_value_seed_test.rb +14 -0
- data/test/annotation_version_test.rb +39 -0
- data/test/annotations_controller_test.rb +27 -0
- data/test/app_root/app/controllers/application_controller.rb +9 -0
- data/test/app_root/app/models/book.rb +5 -0
- data/test/app_root/app/models/chapter.rb +5 -0
- data/test/app_root/app/models/group.rb +3 -0
- data/test/app_root/app/models/tag.rb +6 -0
- data/test/app_root/app/models/user.rb +3 -0
- data/test/app_root/app/views/annotations/edit.html.erb +12 -0
- data/test/app_root/app/views/annotations/index.html.erb +1 -0
- data/test/app_root/app/views/annotations/new.html.erb +11 -0
- data/test/app_root/app/views/annotations/show.html.erb +3 -0
- data/test/app_root/config/boot.rb +115 -0
- data/test/app_root/config/environment.rb +16 -0
- data/test/app_root/config/environments/mysql.rb +0 -0
- data/test/app_root/config/routes.rb +4 -0
- data/test/app_root/db/migrate/001_create_test_models.rb +38 -0
- data/test/app_root/db/migrate/002_annotations_migration_v1.rb +60 -0
- data/test/app_root/db/migrate/003_annotations_migration_v2.rb +9 -0
- data/test/app_root/db/migrate/004_annotations_migration_v3.rb +72 -0
- data/test/config_test.rb +383 -0
- data/test/fixtures/annotation_attributes.yml +49 -0
- data/test/fixtures/annotation_value_seeds.csv +16 -0
- data/test/fixtures/annotation_versions.yml +259 -0
- data/test/fixtures/annotations.yml +239 -0
- data/test/fixtures/books.yml +13 -0
- data/test/fixtures/chapters.yml +27 -0
- data/test/fixtures/groups.yml +7 -0
- data/test/fixtures/number_value_versions.csv +2 -0
- data/test/fixtures/number_values.csv +2 -0
- data/test/fixtures/text_value_versions.csv +35 -0
- data/test/fixtures/text_values.csv +35 -0
- data/test/fixtures/users.yml +8 -0
- data/test/number_value_version_test.rb +40 -0
- data/test/routing_test.rb +27 -0
- data/test/test_helper.rb +41 -0
- data/test/text_value_version_test.rb +40 -0
- metadata +77 -7
@@ -0,0 +1,115 @@
|
|
1
|
+
# Allow customization of the rails framework path
|
2
|
+
RAILS_FRAMEWORK_ROOT = (ENV['RAILS_FRAMEWORK_ROOT'] || "#{File.dirname(__FILE__)}/../../../../../../vendor/rails") unless defined?(RAILS_FRAMEWORK_ROOT)
|
3
|
+
|
4
|
+
# Don't change this file!
|
5
|
+
# Configure your app in config/environment.rb and config/environments/*.rb
|
6
|
+
|
7
|
+
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
|
8
|
+
|
9
|
+
module Rails
|
10
|
+
class << self
|
11
|
+
def boot!
|
12
|
+
unless booted?
|
13
|
+
preinitialize
|
14
|
+
pick_boot.run
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def booted?
|
19
|
+
defined? Rails::Initializer
|
20
|
+
end
|
21
|
+
|
22
|
+
def pick_boot
|
23
|
+
(vendor_rails? ? VendorBoot : GemBoot).new
|
24
|
+
end
|
25
|
+
|
26
|
+
def vendor_rails?
|
27
|
+
File.exist?(RAILS_FRAMEWORK_ROOT)
|
28
|
+
end
|
29
|
+
|
30
|
+
def preinitialize
|
31
|
+
load(preinitializer_path) if File.exist?(preinitializer_path)
|
32
|
+
end
|
33
|
+
|
34
|
+
def preinitializer_path
|
35
|
+
"#{RAILS_ROOT}/config/preinitializer.rb"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class Boot
|
40
|
+
def run
|
41
|
+
load_initializer
|
42
|
+
Rails::Initializer.run(:set_load_path)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class VendorBoot < Boot
|
47
|
+
def load_initializer
|
48
|
+
require "#{RAILS_FRAMEWORK_ROOT}/railties/lib/initializer"
|
49
|
+
Rails::Initializer.run(:install_gem_spec_stubs)
|
50
|
+
Rails::GemDependency.add_frozen_gem_path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class GemBoot < Boot
|
55
|
+
def load_initializer
|
56
|
+
self.class.load_rubygems
|
57
|
+
load_rails_gem
|
58
|
+
require 'initializer'
|
59
|
+
end
|
60
|
+
|
61
|
+
def load_rails_gem
|
62
|
+
if version = self.class.gem_version
|
63
|
+
gem 'rails', version
|
64
|
+
else
|
65
|
+
gem 'rails'
|
66
|
+
end
|
67
|
+
rescue Gem::LoadError => load_error
|
68
|
+
$stderr.puts %(Missing the Rails #{version} gem. Please `gem install -v=#{version} rails`, update your RAILS_GEM_VERSION setting in config/environment.rb for the Rails version you do have installed, or comment out RAILS_GEM_VERSION to use the latest version installed.)
|
69
|
+
exit 1
|
70
|
+
end
|
71
|
+
|
72
|
+
class << self
|
73
|
+
def rubygems_version
|
74
|
+
Gem::RubyGemsVersion rescue nil
|
75
|
+
end
|
76
|
+
|
77
|
+
def gem_version
|
78
|
+
if defined? RAILS_GEM_VERSION
|
79
|
+
RAILS_GEM_VERSION
|
80
|
+
elsif ENV.include?('RAILS_GEM_VERSION')
|
81
|
+
ENV['RAILS_GEM_VERSION']
|
82
|
+
else
|
83
|
+
parse_gem_version(read_environment_rb)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def load_rubygems
|
88
|
+
require 'rubygems'
|
89
|
+
min_version = '1.3.1'
|
90
|
+
unless rubygems_version >= min_version
|
91
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version} (you have #{rubygems_version}). Please `gem update --system` and try again.)
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
rescue LoadError
|
96
|
+
$stderr.puts %Q(Rails requires RubyGems >= #{min_version}. Please install RubyGems and try again: http://rubygems.rubyforge.org)
|
97
|
+
exit 1
|
98
|
+
end
|
99
|
+
|
100
|
+
def parse_gem_version(text)
|
101
|
+
$1 if text =~ /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
def read_environment_rb
|
106
|
+
environment_rb = "#{RAILS_ROOT}/config/environment.rb"
|
107
|
+
environment_rb = "#{HELPER_RAILS_ROOT}/config/environment.rb" unless File.exists?(environment_rb)
|
108
|
+
File.read(environment_rb)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
# All that for this:
|
115
|
+
Rails.boot!
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'boot')
|
2
|
+
|
3
|
+
Rails::Initializer.run do |config|
|
4
|
+
config.cache_classes = false
|
5
|
+
config.whiny_nils = true
|
6
|
+
config.action_controller.session = {:key => 'annotations_plugin_test', :secret => '6cae4d887b1afac29b3dc742c1657139'}
|
7
|
+
config.plugin_locators.unshift(
|
8
|
+
Class.new(Rails::Plugin::Locator) do
|
9
|
+
def plugins
|
10
|
+
[Rails::Plugin.new(File.expand_path('.'))]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
) unless defined?(PluginTestHelper::PluginLocator)
|
14
|
+
|
15
|
+
config.active_record.timestamped_migrations = false
|
16
|
+
end
|
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class CreateTestModels < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :books, :force => true do |t|
|
4
|
+
t.string :title
|
5
|
+
t.string :author_name
|
6
|
+
t.string :isbn
|
7
|
+
t.integer :pub_year
|
8
|
+
t.text :summary
|
9
|
+
end
|
10
|
+
|
11
|
+
create_table :chapters, :force => true do |t|
|
12
|
+
t.integer :chapter_number
|
13
|
+
t.string :title
|
14
|
+
t.text :summary
|
15
|
+
t.integer :book_id
|
16
|
+
end
|
17
|
+
|
18
|
+
create_table :users, :force => true do |t|
|
19
|
+
t.string :name
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table :groups, :force => true do |t|
|
23
|
+
t.string :name
|
24
|
+
end
|
25
|
+
|
26
|
+
create_table :tags, :force => true do |t|
|
27
|
+
t.string :name, :null => false
|
28
|
+
end
|
29
|
+
add_index :tags, [ :name ], :unique => true
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.down
|
33
|
+
drop_table :books
|
34
|
+
drop_table :chapters
|
35
|
+
drop_table :users
|
36
|
+
drop_table :groups
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class AnnotationsMigrationV1 < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :annotations, :force => true do |t|
|
4
|
+
t.string :source_type, :null => false
|
5
|
+
t.integer :source_id, :null => false
|
6
|
+
t.string :annotatable_type, :limit => 50, :null => false
|
7
|
+
t.integer :annotatable_id, :null => false
|
8
|
+
t.integer :attribute_id, :null => false
|
9
|
+
t.text :value, :limit => 20000, :null => false
|
10
|
+
t.string :value_type, :limit => 50, :null => false
|
11
|
+
t.integer :version, :null => false
|
12
|
+
t.integer :version_creator_id, :null => true
|
13
|
+
t.timestamps
|
14
|
+
end
|
15
|
+
|
16
|
+
add_index :annotations, [ :source_type, :source_id ]
|
17
|
+
add_index :annotations, [ :annotatable_type, :annotatable_id ]
|
18
|
+
add_index :annotations, [ :attribute_id ]
|
19
|
+
|
20
|
+
create_table :annotation_versions, :force => true do |t|
|
21
|
+
t.integer :annotation_id, :null => false
|
22
|
+
t.integer :version, :null => false
|
23
|
+
t.integer :version_creator_id, :null => true
|
24
|
+
t.string :source_type, :null => false
|
25
|
+
t.integer :source_id, :null => false
|
26
|
+
t.string :annotatable_type, :limit => 50, :null => false
|
27
|
+
t.integer :annotatable_id, :null => false
|
28
|
+
t.integer :attribute_id, :null => false
|
29
|
+
t.text :value, :limit => 20000, :null => false
|
30
|
+
t.string :value_type, :limit => 50, :null => false
|
31
|
+
t.timestamps
|
32
|
+
end
|
33
|
+
|
34
|
+
add_index :annotation_versions, [ :annotation_id ]
|
35
|
+
|
36
|
+
create_table :annotation_attributes, :force => true do |t|
|
37
|
+
t.string :name, :null => false
|
38
|
+
|
39
|
+
t.timestamps
|
40
|
+
end
|
41
|
+
|
42
|
+
add_index :annotation_attributes, [ :name ]
|
43
|
+
|
44
|
+
create_table :annotation_value_seeds, :force => true do |t|
|
45
|
+
t.integer :attribute_id, :null => false
|
46
|
+
t.string :value, :null => false
|
47
|
+
|
48
|
+
t.timestamps
|
49
|
+
end
|
50
|
+
|
51
|
+
add_index :annotation_value_seeds, [ :attribute_id ]
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.down
|
55
|
+
drop_table :annotations
|
56
|
+
drop_table :annotation_versions
|
57
|
+
drop_table :annotation_attributes
|
58
|
+
drop_table :annotation_value_seeds
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class AnnotationsMigrationV3 < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
|
4
|
+
change_table :annotations do |t|
|
5
|
+
t.rename :value, :old_value
|
6
|
+
t.remove :value_type
|
7
|
+
t.string :value_type, :limit => 50, :null => false, :default => "TextValue"
|
8
|
+
t.integer :value_id, :null => false, :default => 0
|
9
|
+
end
|
10
|
+
change_column :annotations, :old_value, :string, :null => true
|
11
|
+
add_index :annotations, [ :value_type, :value_id ]
|
12
|
+
|
13
|
+
change_table :annotation_versions do |t|
|
14
|
+
t.rename :value, :old_value
|
15
|
+
t.remove :value_type
|
16
|
+
t.string :value_type, :limit => 50, :null => false, :default => "TextValue"
|
17
|
+
t.integer :value_id, :null => false, :default => 0
|
18
|
+
end
|
19
|
+
change_column :annotation_versions, :old_value, :string, :null => true
|
20
|
+
|
21
|
+
create_table :text_values, :force => true do |t|
|
22
|
+
t.integer :version, :null => false
|
23
|
+
t.integer :version_creator_id, :null => true
|
24
|
+
t.text :text, :limit => 16777214, :null => false
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table :text_value_versions, :force => true do |t|
|
29
|
+
t.integer :text_value_id, :null => false
|
30
|
+
t.integer :version, :null => false
|
31
|
+
t.integer :version_creator_id, :null => true
|
32
|
+
t.text :text, :limit => 16777214, :null => false
|
33
|
+
t.timestamps
|
34
|
+
end
|
35
|
+
add_index :text_value_versions, [ :text_value_id ]
|
36
|
+
|
37
|
+
create_table :number_values, :force => true do |t|
|
38
|
+
t.integer :version, :null => false
|
39
|
+
t.integer :version_creator_id, :null => true
|
40
|
+
t.integer :number, :null => false
|
41
|
+
t.timestamps
|
42
|
+
end
|
43
|
+
|
44
|
+
create_table :number_value_versions, :force => true do |t|
|
45
|
+
t.integer :number_value_id, :null => false
|
46
|
+
t.integer :version, :null => false
|
47
|
+
t.integer :version_creator_id, :null => true
|
48
|
+
t.integer :number, :null => false
|
49
|
+
t.timestamps
|
50
|
+
end
|
51
|
+
add_index :number_value_versions, [ :number_value_id ]
|
52
|
+
|
53
|
+
# Migrate existing annotations to the v3 db schema
|
54
|
+
#
|
55
|
+
# TODO: IMPORTANT: please check the comments and logic in
|
56
|
+
# this util method to see if it is what you want.
|
57
|
+
# If you need to change the behaviour, redefine it in your app.
|
58
|
+
Annotations::Util::migrate_annotations_to_v3
|
59
|
+
|
60
|
+
change_table :annotation_value_seeds do |t|
|
61
|
+
t.rename :value, :old_value
|
62
|
+
t.string :value_type, :limit => 50, :null => false, :default => "FIXME"
|
63
|
+
t.integer :value_id, :null => false, :default => 0
|
64
|
+
end
|
65
|
+
change_column :annotation_value_seeds, :old_value, :string, :null => true
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.down
|
70
|
+
raise ActiveRecord::IrreversibleMigration.new
|
71
|
+
end
|
72
|
+
end
|