heritage 0.1.0

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.
Files changed (91) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +4 -0
  3. data/README.textile +246 -0
  4. data/Rakefile +2 -0
  5. data/heritage.gemspec +19 -0
  6. data/heritage_demo/.gitignore +4 -0
  7. data/heritage_demo/Gemfile +32 -0
  8. data/heritage_demo/Gemfile.lock +79 -0
  9. data/heritage_demo/README +256 -0
  10. data/heritage_demo/Rakefile +7 -0
  11. data/heritage_demo/app/controllers/application_controller.rb +3 -0
  12. data/heritage_demo/app/controllers/blog_posts_controller.rb +45 -0
  13. data/heritage_demo/app/controllers/image_posts_controller.rb +45 -0
  14. data/heritage_demo/app/controllers/posts_controller.rb +19 -0
  15. data/heritage_demo/app/helpers/application_helper.rb +2 -0
  16. data/heritage_demo/app/helpers/blog_posts_helper.rb +2 -0
  17. data/heritage_demo/app/helpers/image_posts_helper.rb +2 -0
  18. data/heritage_demo/app/helpers/posts_helper.rb +2 -0
  19. data/heritage_demo/app/models/blog_post.rb +9 -0
  20. data/heritage_demo/app/models/image_post.rb +5 -0
  21. data/heritage_demo/app/models/post.rb +9 -0
  22. data/heritage_demo/app/views/blog_posts/_form.html.erb +13 -0
  23. data/heritage_demo/app/views/blog_posts/edit.html.erb +2 -0
  24. data/heritage_demo/app/views/blog_posts/index.html.erb +11 -0
  25. data/heritage_demo/app/views/blog_posts/new.html.erb +2 -0
  26. data/heritage_demo/app/views/blog_posts/show.html.erb +12 -0
  27. data/heritage_demo/app/views/image_posts/_form.html.erb +13 -0
  28. data/heritage_demo/app/views/image_posts/edit.html.erb +2 -0
  29. data/heritage_demo/app/views/image_posts/index.html.erb +11 -0
  30. data/heritage_demo/app/views/image_posts/new.html.erb +2 -0
  31. data/heritage_demo/app/views/image_posts/show.html.erb +12 -0
  32. data/heritage_demo/app/views/layouts/application.html.erb +14 -0
  33. data/heritage_demo/app/views/posts/index.html.erb +9 -0
  34. data/heritage_demo/config.ru +4 -0
  35. data/heritage_demo/config/application.rb +42 -0
  36. data/heritage_demo/config/boot.rb +6 -0
  37. data/heritage_demo/config/database.yml +22 -0
  38. data/heritage_demo/config/environment.rb +5 -0
  39. data/heritage_demo/config/environments/development.rb +26 -0
  40. data/heritage_demo/config/environments/production.rb +49 -0
  41. data/heritage_demo/config/environments/test.rb +35 -0
  42. data/heritage_demo/config/initializers/backtrace_silencers.rb +7 -0
  43. data/heritage_demo/config/initializers/inflections.rb +10 -0
  44. data/heritage_demo/config/initializers/mime_types.rb +5 -0
  45. data/heritage_demo/config/initializers/secret_token.rb +7 -0
  46. data/heritage_demo/config/initializers/session_store.rb +8 -0
  47. data/heritage_demo/config/locales/en.yml +5 -0
  48. data/heritage_demo/config/routes.rb +62 -0
  49. data/heritage_demo/db/migrate/20110411095519_create_posts.rb +15 -0
  50. data/heritage_demo/db/migrate/20110411095612_create_blog_posts.rb +11 -0
  51. data/heritage_demo/db/migrate/20110411095655_create_image_posts.rb +11 -0
  52. data/heritage_demo/db/schema.rb +45 -0
  53. data/heritage_demo/db/seeds.rb +7 -0
  54. data/heritage_demo/doc/README_FOR_APP +2 -0
  55. data/heritage_demo/lib/tasks/.gitkeep +0 -0
  56. data/heritage_demo/public/404.html +26 -0
  57. data/heritage_demo/public/422.html +26 -0
  58. data/heritage_demo/public/500.html +26 -0
  59. data/heritage_demo/public/favicon.ico +0 -0
  60. data/heritage_demo/public/images/rails.png +0 -0
  61. data/heritage_demo/public/index.html +239 -0
  62. data/heritage_demo/public/javascripts/application.js +2 -0
  63. data/heritage_demo/public/javascripts/controls.js +965 -0
  64. data/heritage_demo/public/javascripts/dragdrop.js +974 -0
  65. data/heritage_demo/public/javascripts/effects.js +1123 -0
  66. data/heritage_demo/public/javascripts/prototype.js +6001 -0
  67. data/heritage_demo/public/javascripts/rails.js +191 -0
  68. data/heritage_demo/public/robots.txt +5 -0
  69. data/heritage_demo/public/stylesheets/.gitkeep +0 -0
  70. data/heritage_demo/script/rails +6 -0
  71. data/heritage_demo/test/fixtures/blog_posts.yml +9 -0
  72. data/heritage_demo/test/fixtures/image_posts.yml +9 -0
  73. data/heritage_demo/test/fixtures/posts.yml +11 -0
  74. data/heritage_demo/test/functional/blog_posts_controller_test.rb +8 -0
  75. data/heritage_demo/test/functional/image_posts_controller_test.rb +8 -0
  76. data/heritage_demo/test/functional/posts_controller_test.rb +8 -0
  77. data/heritage_demo/test/performance/browsing_test.rb +9 -0
  78. data/heritage_demo/test/test_helper.rb +13 -0
  79. data/heritage_demo/test/unit/blog_post_test.rb +8 -0
  80. data/heritage_demo/test/unit/helpers/blog_posts_helper_test.rb +4 -0
  81. data/heritage_demo/test/unit/helpers/image_posts_helper_test.rb +4 -0
  82. data/heritage_demo/test/unit/helpers/posts_helper_test.rb +4 -0
  83. data/heritage_demo/test/unit/image_post_test.rb +8 -0
  84. data/heritage_demo/test/unit/post_test.rb +8 -0
  85. data/heritage_demo/vendor/plugins/.gitkeep +0 -0
  86. data/lib/heritage.rb +5 -0
  87. data/lib/heritage/active_record/acts_as_heir.rb +57 -0
  88. data/lib/heritage/active_record/acts_as_predecessor.rb +31 -0
  89. data/lib/heritage/railtie.rb +20 -0
  90. data/lib/heritage/version.rb +3 -0
  91. metadata +157 -0
@@ -0,0 +1,7 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+ require 'rake'
6
+
7
+ HeritageDemo::Application.load_tasks
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,45 @@
1
+ class BlogPostsController < ApplicationController
2
+
3
+ def index
4
+ @blog_posts = BlogPost.all(:include => :predecessor)
5
+ end
6
+
7
+ def new
8
+ @blog_post = BlogPost.new
9
+ end
10
+
11
+ def create
12
+ @blog_post = BlogPost.new(params[:blog_post])
13
+
14
+ if @blog_post.save
15
+ redirect_to blog_posts_url
16
+ else
17
+ render :action => 'new'
18
+ end
19
+ end
20
+
21
+ def show
22
+ @blog_post = BlogPost.find(params[:id])
23
+ end
24
+
25
+ def edit
26
+ @blog_post = BlogPost.find(params[:id])
27
+ end
28
+
29
+ def update
30
+ @blog_post = BlogPost.find(params[:id])
31
+
32
+ if @blog_post.update_attributes(params[:blog_post])
33
+ redirect_to blog_posts_url
34
+ else
35
+ render :action => 'edit'
36
+ end
37
+ end
38
+
39
+ def destroy
40
+ @blog_post = BlogPost.find(params[:id])
41
+ @blog_post.destroy
42
+ redirect_to blog_posts_url
43
+ end
44
+
45
+ end
@@ -0,0 +1,45 @@
1
+ class ImagePostsController < ApplicationController
2
+
3
+ def index
4
+ @image_posts = ImagePost.all
5
+ end
6
+
7
+ def new
8
+ @image_post = ImagePost.new
9
+ end
10
+
11
+ def create
12
+ @image_post = ImagePost.new(params[:image_post])
13
+
14
+ if @image_post.save
15
+ redirect_to image_posts_url
16
+ else
17
+ render :action => 'new'
18
+ end
19
+ end
20
+
21
+ def show
22
+ @image_post = ImagePost.find(params[:id])
23
+ end
24
+
25
+ def edit
26
+ @image_post = ImagePost.find(params[:id])
27
+ end
28
+
29
+ def update
30
+ @image_post = ImagePost.find(params[:id])
31
+
32
+ if @image_post.update_attributes(params[:image_post])
33
+ redirect_to image_posts_url
34
+ else
35
+ render :action => 'edit'
36
+ end
37
+ end
38
+
39
+ def destroy
40
+ @image_post = ImagePost.find(params[:id])
41
+ @image_post.destroy
42
+ redirect_to image_posts_url
43
+ end
44
+
45
+ end
@@ -0,0 +1,19 @@
1
+ class PostsController < ApplicationController
2
+
3
+ def index
4
+ @posts = Post.all
5
+ end
6
+
7
+ def show
8
+ @post = Post.find(params[:id])
9
+
10
+ if @post.heir.is_a?(BlogPost)
11
+ redirect_to blog_post_url(@post.heir)
12
+ elsif @post.heir.is_a?(ImagePost)
13
+ redirect_to image_post_url(@post.heir)
14
+ else
15
+ render :text => "Unknown post-type"
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module BlogPostsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module ImagePostsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,9 @@
1
+ class BlogPost < ActiveRecord::Base
2
+
3
+ acts_as_heir_of :post
4
+
5
+ def hello
6
+ "Yo! #{predecessor.hello}"
7
+ end
8
+
9
+ end
@@ -0,0 +1,5 @@
1
+ class ImagePost < ActiveRecord::Base
2
+
3
+ acts_as_heir_of :post
4
+
5
+ end
@@ -0,0 +1,9 @@
1
+ class Post < ActiveRecord::Base
2
+
3
+ acts_as_predecessor :exposes => :hello
4
+
5
+ def hello
6
+ "Hi there!"
7
+ end
8
+
9
+ end
@@ -0,0 +1,13 @@
1
+ <% form_for @blog_post do |f| -%>
2
+ <p>
3
+ <%= f.label :title, "Title" %>
4
+ <%= f.text_field :title %>
5
+ </p>
6
+ <p>
7
+ <%= f.label :body, "Body" %>
8
+ <%= f.text_field :body %>
9
+ </p>
10
+ <p>
11
+ <%= f.submit "Save", :disable_with => 'Saving...' %>
12
+ </p>
13
+ <% end -%>
@@ -0,0 +1,2 @@
1
+ <h1>Edit blog post</h1>
2
+ <%= render 'form' %>
@@ -0,0 +1,11 @@
1
+ <h1>Blog posts</h1>
2
+ <p>
3
+ <%= link_to "Create new", new_blog_post_path %>
4
+ </p>
5
+ <ul>
6
+ <% @blog_posts.each do |blog_post| %>
7
+ <li><%= link_to blog_post.title, blog_post_path(blog_post) %>
8
+ (<%= link_to "E", edit_blog_post_path(blog_post) %>,
9
+ <%= link_to "D", blog_post_path(blog_post), :method => :delete %>)</li>
10
+ <% end %>
11
+ </ul>
@@ -0,0 +1,2 @@
1
+ <h1>New blog post</h1>
2
+ <%= render 'form' %>
@@ -0,0 +1,12 @@
1
+ <h1>Blog post</h1>
2
+ <p>
3
+ <%= link_to "List", blog_posts_path %>
4
+ <%= link_to "Edit", edit_blog_post_path(@blog_post) %>
5
+ <%= link_to "Delete", blog_post_path(@blog_post), :method => :delete %>
6
+ </p>
7
+ <ul>
8
+ <li><strong>Title:</strong> <%= @blog_post.title %></li>
9
+ <li><strong>Body:</strong> <%= @blog_post.body %></li>
10
+ <li><strong>Created at:</strong> <%= @blog_post.created_at %></li>
11
+ <li><strong>Updated at:</strong> <%= @blog_post.updated_at %></li>
12
+ </ul>
@@ -0,0 +1,13 @@
1
+ <% form_for @image_post do |f| -%>
2
+ <p>
3
+ <%= f.label :title, "Title" %>
4
+ <%= f.text_field :title %>
5
+ </p>
6
+ <p>
7
+ <%= f.label :aspect, "Aspect" %>
8
+ <%= f.text_field :aspect %>
9
+ </p>
10
+ <p>
11
+ <%= f.submit "Save", :disable_with => 'Saving...' %>
12
+ </p>
13
+ <% end -%>
@@ -0,0 +1,2 @@
1
+ <h1>Edit image post</h1>
2
+ <%= render 'form' %>
@@ -0,0 +1,11 @@
1
+ <h1>Image posts</h1>
2
+ <p>
3
+ <%= link_to "Create new", new_image_post_path %>
4
+ </p>
5
+ <ul>
6
+ <% @image_posts.each do |image_post| %>
7
+ <li><%= link_to image_post.title, image_post_path(image_post) %>
8
+ (<%= link_to "E", edit_image_post_path(image_post) %>,
9
+ <%= link_to "D", image_post_path(image_post), :method => :delete %>)</li>
10
+ <% end %>
11
+ </ul>
@@ -0,0 +1,2 @@
1
+ <h1>New image post</h1>
2
+ <%= render 'form' %>
@@ -0,0 +1,12 @@
1
+ <h1>Image post</h1>
2
+ <p>
3
+ <%= link_to "List", image_posts_path %>
4
+ <%= link_to "Edit", edit_image_post_path(@image_post) %>
5
+ <%= link_to "Delete", image_post_path(@image_post), :method => :delete %>
6
+ </p>
7
+ <ul>
8
+ <li><strong>Title:</strong> <%= @image_post.title %></li>
9
+ <li><strong>Aspect:</strong> <%= @image_post.aspect %></li>
10
+ <li><strong>Created at:</strong> <%= @image_post.created_at %></li>
11
+ <li><strong>Updated at:</strong> <%= @image_post.updated_at %></li>
12
+ </ul>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>HeritageDemo</title>
5
+ <%= stylesheet_link_tag :all %>
6
+ <%= javascript_include_tag :defaults %>
7
+ <%= csrf_meta_tag %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,9 @@
1
+ <h1>Posts</h1>
2
+ <ul>
3
+ <% @posts.each do |post| %>
4
+ <li>
5
+ <strong><%= post.heir_type %></strong>
6
+ <%= link_to post.title, post_path(post) %>
7
+ </li>
8
+ <% end %>
9
+ </ul>
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run HeritageDemo::Application
@@ -0,0 +1,42 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ # If you have a Gemfile, require the gems listed there, including any gems
6
+ # you've limited to :test, :development, or :production.
7
+ Bundler.require(:default, Rails.env) if defined?(Bundler)
8
+
9
+ module HeritageDemo
10
+ class Application < Rails::Application
11
+ # Settings in config/environments/* take precedence over those specified here.
12
+ # Application configuration should go into files in config/initializers
13
+ # -- all .rb files in that directory are automatically loaded.
14
+
15
+ # Custom directories with classes and modules you want to be autoloadable.
16
+ # config.autoload_paths += %W(#{config.root}/extras)
17
+
18
+ # Only load the plugins named here, in the order given (default is alphabetical).
19
+ # :all can be used as a placeholder for all plugins not explicitly named.
20
+ # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
21
+
22
+ # Activate observers that should always be running.
23
+ # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
24
+
25
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
26
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
27
+ # config.time_zone = 'Central Time (US & Canada)'
28
+
29
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
30
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
31
+ # config.i18n.default_locale = :de
32
+
33
+ # JavaScript files you want as :defaults (application.js is always included).
34
+ # config.action_view.javascript_expansions[:defaults] = %w(jquery rails)
35
+
36
+ # Configure the default encoding used in templates for Ruby 1.9.
37
+ config.encoding = "utf-8"
38
+
39
+ # Configure sensitive parameters which will be filtered from the log file.
40
+ config.filter_parameters += [:password]
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+
3
+ # Set up gems listed in the Gemfile.
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+
6
+ require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -0,0 +1,22 @@
1
+ # SQLite version 3.x
2
+ # gem install sqlite3
3
+ development:
4
+ adapter: sqlite3
5
+ database: db/development.sqlite3
6
+ pool: 5
7
+ timeout: 5000
8
+
9
+ # Warning: The database defined as "test" will be erased and
10
+ # re-generated from your development database when you run "rake".
11
+ # Do not set this db to the same as development or production.
12
+ test:
13
+ adapter: sqlite3
14
+ database: db/test.sqlite3
15
+ pool: 5
16
+ timeout: 5000
17
+
18
+ production:
19
+ adapter: sqlite3
20
+ database: db/production.sqlite3
21
+ pool: 5
22
+ timeout: 5000
@@ -0,0 +1,5 @@
1
+ # Load the rails application
2
+ require File.expand_path('../application', __FILE__)
3
+
4
+ # Initialize the rails application
5
+ HeritageDemo::Application.initialize!
@@ -0,0 +1,26 @@
1
+ HeritageDemo::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # In the development environment your application's code is reloaded on
5
+ # every request. This slows down response time but is perfect for development
6
+ # since you don't have to restart the webserver when you make code changes.
7
+ config.cache_classes = false
8
+
9
+ # Log error messages when you accidentally call methods on nil.
10
+ config.whiny_nils = true
11
+
12
+ # Show full error reports and disable caching
13
+ config.consider_all_requests_local = true
14
+ config.action_view.debug_rjs = true
15
+ config.action_controller.perform_caching = false
16
+
17
+ # Don't care if the mailer can't send
18
+ config.action_mailer.raise_delivery_errors = false
19
+
20
+ # Print deprecation notices to the Rails logger
21
+ config.active_support.deprecation = :log
22
+
23
+ # Only use best-standards-support built into browsers
24
+ config.action_dispatch.best_standards_support = :builtin
25
+ end
26
+
@@ -0,0 +1,49 @@
1
+ HeritageDemo::Application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb
3
+
4
+ # The production environment is meant for finished, "live" apps.
5
+ # Code is not reloaded between requests
6
+ config.cache_classes = true
7
+
8
+ # Full error reports are disabled and caching is turned on
9
+ config.consider_all_requests_local = false
10
+ config.action_controller.perform_caching = true
11
+
12
+ # Specifies the header that your server uses for sending files
13
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
14
+
15
+ # For nginx:
16
+ # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
17
+
18
+ # If you have no front-end server that supports something like X-Sendfile,
19
+ # just comment this out and Rails will serve the files
20
+
21
+ # See everything in the log (default is :info)
22
+ # config.log_level = :debug
23
+
24
+ # Use a different logger for distributed setups
25
+ # config.logger = SyslogLogger.new
26
+
27
+ # Use a different cache store in production
28
+ # config.cache_store = :mem_cache_store
29
+
30
+ # Disable Rails's static asset server
31
+ # In production, Apache or nginx will already do this
32
+ config.serve_static_assets = false
33
+
34
+ # Enable serving of images, stylesheets, and javascripts from an asset server
35
+ # config.action_controller.asset_host = "http://assets.example.com"
36
+
37
+ # Disable delivery errors, bad email addresses will be ignored
38
+ # config.action_mailer.raise_delivery_errors = false
39
+
40
+ # Enable threaded mode
41
+ # config.threadsafe!
42
+
43
+ # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
44
+ # the I18n.default_locale when a translation can not be found)
45
+ config.i18n.fallbacks = true
46
+
47
+ # Send deprecation notices to registered listeners
48
+ config.active_support.deprecation = :notify
49
+ end