aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_view/helpers.rb1
-rw-r--r--actionpack/lib/action_view/helpers/ajax_helper.rb68
-rw-r--r--actionpack/test/activerecord/render_partial_with_record_identification_test.rb3
-rw-r--r--actionpack/test/controller/record_identifier_test.rb3
-rw-r--r--actionpack/test/controller/redirect_test.rb3
-rw-r--r--actionpack/test/javascript/ajax_test.rb115
-rw-r--r--actionpack/test/lib/controller/fake_models.rb6
-rw-r--r--actionpack/test/template/active_record_helper_test.rb9
-rw-r--r--actionpack/test/template/atom_feed_helper_test.rb3
-rw-r--r--actionpack/test/template/form_helper_test.rb15
-rw-r--r--actionpack/test/template/prototype_helper_test.rb12
-rw-r--r--actionpack/test/template/record_tag_helper_test.rb3
-rw-r--r--actionpack/test/template/test_test.rb2
-rw-r--r--actionpack/test/template/url_helper_test.rb6
-rw-r--r--activemodel/examples/validations.rb (renamed from activemodel/examples/amo_ap_example.rb)23
-rw-r--r--activemodel/lib/active_model.rb4
-rw-r--r--activemodel/lib/active_model/api_compliant.rb25
-rw-r--r--activemodel/lib/active_model/attributes.rb25
-rw-r--r--activemodel/lib/active_model/base.rb8
-rw-r--r--activemodel/lib/active_model/conversion.rb8
-rw-r--r--activemodel/lib/active_model/observing.rb97
-rw-r--r--activemodel/lib/active_model/serializers/json.rb1
-rw-r--r--activemodel/lib/active_model/serializers/xml.rb1
-rw-r--r--activemodel/lib/activemodel.rb1
-rw-r--r--activemodel/test/cases/attributes_test.rb30
-rw-r--r--activemodel/test/cases/observing_test.rb7
-rw-r--r--activemodel/test/cases/serializeration/json_serialization_test.rb4
-rw-r--r--activemodel/test/cases/serializeration/xml_serialization_test.rb4
-rwxr-xr-xactiverecord/lib/active_record/base.rb8
-rw-r--r--activerecord/lib/active_record/callbacks.rb2
-rw-r--r--activeresource/lib/active_resource.rb1
-rw-r--r--activeresource/lib/active_resource/base.rb13
-rw-r--r--activeresource/lib/active_resource/observing.rb10
-rw-r--r--activesupport/lib/active_support/test_case.rb3
-rwxr-xr-xrailties/bin/about4
-rwxr-xr-xrailties/bin/console2
-rwxr-xr-xrailties/bin/dbconsole2
-rwxr-xr-xrailties/bin/destroy2
-rwxr-xr-xrailties/bin/generate2
-rwxr-xr-xrailties/bin/performance/benchmarker2
-rwxr-xr-xrailties/bin/performance/profiler2
-rwxr-xr-xrailties/bin/plugin2
-rwxr-xr-xrailties/bin/runner2
-rwxr-xr-xrailties/bin/server2
-rw-r--r--railties/lib/vendor/bundler/LICENSE20
-rw-r--r--railties/lib/vendor/bundler/Rakefile52
-rwxr-xr-xrailties/lib/vendor/bundler/bin/gem_bundler40
-rw-r--r--railties/lib/vendor/bundler/lib/bundler.rb24
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/cli.rb24
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/dependency.rb35
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/finder.rb42
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/gem_bundle.rb23
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/gem_specification.rb10
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/installer.rb44
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/manifest.rb130
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/resolver.rb19
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/resolver/builders.rb61
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/resolver/engine.rb38
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/resolver/inspect.rb24
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/resolver/search.rb71
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/resolver/stack.rb72
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/resolver/state.rb172
-rw-r--r--railties/lib/vendor/bundler/lib/bundler/runtime.rb39
63 files changed, 1319 insertions, 167 deletions
diff --git a/actionpack/lib/action_view/helpers.rb b/actionpack/lib/action_view/helpers.rb
index c1c0eb59ae..652561f7f8 100644
--- a/actionpack/lib/action_view/helpers.rb
+++ b/actionpack/lib/action_view/helpers.rb
@@ -1,6 +1,7 @@
module ActionView #:nodoc:
module Helpers #:nodoc:
autoload :ActiveModelHelper, 'action_view/helpers/active_model_helper'
+ autoload :AjaxHelper, 'action_view/helpers/ajax_helper'
autoload :AssetTagHelper, 'action_view/helpers/asset_tag_helper'
autoload :AtomFeedHelper, 'action_view/helpers/atom_feed_helper'
autoload :BenchmarkHelper, 'action_view/helpers/benchmark_helper'
diff --git a/actionpack/lib/action_view/helpers/ajax_helper.rb b/actionpack/lib/action_view/helpers/ajax_helper.rb
new file mode 100644
index 0000000000..9cc2acc239
--- /dev/null
+++ b/actionpack/lib/action_view/helpers/ajax_helper.rb
@@ -0,0 +1,68 @@
+module ActionView
+ module Helpers
+ module AjaxHelper
+ include UrlHelper
+
+ def link_to_remote(name, url, options = {})
+ html = options.delete(:html) || {}
+
+ update = options.delete(:update)
+ if update.is_a?(Hash)
+ html["data-update-success"] = update[:success]
+ html["data-update-failure"] = update[:failure]
+ else
+ html["data-update-success"] = update
+ end
+
+ html["data-update-position"] = options.delete(:position)
+ html["data-method"] = options.delete(:method)
+ html["data-remote"] = "true"
+
+ html.merge!(options)
+
+ url = url_for(url) if url.is_a?(Hash)
+ link_to(name, url, html)
+ end
+
+ def button_to_remote(name, options = {}, html_options = {})
+ url = options.delete(:url)
+ url = url_for(url) if url.is_a?(Hash)
+
+ html_options.merge!(:type => "button", :value => name,
+ :"data-url" => url)
+
+ tag(:input, html_options)
+ end
+
+ module Rails2Compatibility
+ def set_callbacks(options, html)
+ [:complete, :failure, :success, :interactive, :loaded, :loading].each do |type|
+ html["data-#{type}-code"] = options.delete(type.to_sym)
+ end
+
+ options.each do |option, value|
+ if option.is_a?(Integer)
+ html["data-#{option}-code"] = options.delete(option)
+ end
+ end
+ end
+
+ def link_to_remote(name, url, options = nil)
+ if !options && url.is_a?(Hash) && url.key?(:url)
+ url, options = url.delete(:url), url
+ end
+
+ set_callbacks(options, options[:html] ||= {})
+
+ super
+ end
+
+ def button_to_remote(name, options = {}, html_options = {})
+ set_callbacks(options, html_options)
+ super
+ end
+ end
+
+ end
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
index 0122bc7d8f..df50c3dc6f 100644
--- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
+++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb
@@ -126,7 +126,8 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base
end
class Game < Struct.new(:name, :id)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def to_param
id.to_s
end
diff --git a/actionpack/test/controller/record_identifier_test.rb b/actionpack/test/controller/record_identifier_test.rb
index 10f51639cf..44e49ed3f8 100644
--- a/actionpack/test/controller/record_identifier_test.rb
+++ b/actionpack/test/controller/record_identifier_test.rb
@@ -1,7 +1,8 @@
require 'abstract_unit'
class Comment
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
def save; @id = 1 end
diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb
index a71c39e504..b3321303c0 100644
--- a/actionpack/test/controller/redirect_test.rb
+++ b/actionpack/test/controller/redirect_test.rb
@@ -4,7 +4,8 @@ class WorkshopsController < ActionController::Base
end
class Workshop
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_accessor :id, :new_record
def initialize(id, new_record)
diff --git a/actionpack/test/javascript/ajax_test.rb b/actionpack/test/javascript/ajax_test.rb
new file mode 100644
index 0000000000..b67a91dad3
--- /dev/null
+++ b/actionpack/test/javascript/ajax_test.rb
@@ -0,0 +1,115 @@
+require "abstract_unit"
+
+class AjaxTestCase < ActiveSupport::TestCase
+ include ActionView::Helpers::AjaxHelper
+ include ActionView::Helpers::TagHelper
+
+ def assert_html(html, matches)
+ matches.each do |match|
+ assert_match Regexp.new(Regexp.escape(match)), html
+ end
+ end
+
+ def self.assert_callbacks_work(&blk)
+ define_method(:assert_callbacks_work, &blk)
+
+ [:complete, :failure, :success, :interactive, :loaded, :loading, 404].each do |callback|
+ test "#{callback} callback" do
+ markup = assert_callbacks_work(callback)
+ assert_html markup, %W(data-#{callback}-code="undoRequestCompleted\(request\)")
+ end
+ end
+ end
+end
+
+class LinkToRemoteTest < AjaxTestCase
+ def url_for(hash)
+ "/blog/destroy/4"
+ end
+
+ def link(options = {})
+ link_to_remote("Delete this post", "/blog/destroy/3", options)
+ end
+
+ test "with no update" do
+ assert_html link, %w(href="/blog/destroy/3" Delete\ this\ post data-remote="true")
+ end
+
+ test "basic" do
+ assert_html link(:update => "#posts"),
+ %w(data-update-success="#posts")
+ end
+
+ test "using a url hash" do
+ link = link_to_remote("Delete this post", {:controller => :blog}, :update => "#posts")
+ assert_html link, %w(href="/blog/destroy/4" data-update-success="#posts")
+ end
+
+ test "with :html options" do
+ expected = %{<a href="/blog/destroy/3" data-custom="me" data-update-success="#posts">Delete this post</a>}
+ assert_equal expected, link(:update => "#posts", :html => {"data-custom" => "me"})
+ end
+
+ test "with a hash for :update" do
+ link = link(:update => {:success => "#posts", :failure => "#error"})
+ assert_match /data-update-success="#posts"/, link
+ assert_match /data-update-failure="#error"/, link
+ end
+
+ test "with positional parameters" do
+ link = link(:position => :top, :update => "#posts")
+ assert_match /data\-update\-position="top"/, link
+ end
+
+ test "with an optional method" do
+ link = link(:method => "delete")
+ assert_match /data-method="delete"/, link
+ end
+
+ class LegacyLinkToRemoteTest < AjaxTestCase
+ include ActionView::Helpers::AjaxHelper::Rails2Compatibility
+
+ def link(options)
+ link_to_remote("Delete this post", "/blog/destroy/3", options)
+ end
+
+ test "basic link_to_remote with :url =>" do
+ expected = %{<a href="/blog/destroy/3" data-update-success="#posts">Delete this post</a>}
+ assert_equal expected,
+ link_to_remote("Delete this post", :url => "/blog/destroy/3", :update => "#posts")
+ end
+
+ assert_callbacks_work do |callback|
+ link(callback => "undoRequestCompleted(request)")
+ end
+ end
+end
+
+class ButtonToRemoteTest < AjaxTestCase
+ def button(options, html = {})
+ button_to_remote("Remote outpost", options, html)
+ end
+
+ def url_for(*)
+ "/whatnot"
+ end
+
+ class StandardTest < ButtonToRemoteTest
+ test "basic" do
+ button = button({:url => {:action => "whatnot"}}, {:class => "fine"})
+ [/input/, /class="fine"/, /type="button"/, /value="Remote outpost"/,
+ /data-url="\/whatnot"/].each do |match|
+ assert_match match, button
+ end
+ end
+ end
+
+ class LegacyButtonToRemoteTest < ButtonToRemoteTest
+ include ActionView::Helpers::AjaxHelper::Rails2Compatibility
+
+ assert_callbacks_work do |callback|
+ button(callback => "undoRequestCompleted(request)")
+ end
+ end
+
+end \ No newline at end of file
diff --git a/actionpack/test/lib/controller/fake_models.rb b/actionpack/test/lib/controller/fake_models.rb
index 07f01e1c47..c6726432ec 100644
--- a/actionpack/test/lib/controller/fake_models.rb
+++ b/actionpack/test/lib/controller/fake_models.rb
@@ -1,7 +1,8 @@
require "active_model"
class Customer < Struct.new(:name, :id)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def to_param
id.to_s
@@ -16,7 +17,8 @@ end
module Quiz
class Question < Struct.new(:name, :id)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def to_param
id.to_s
diff --git a/actionpack/test/template/active_record_helper_test.rb b/actionpack/test/template/active_record_helper_test.rb
index c1bbdae8fb..b07ce6cf5d 100644
--- a/actionpack/test/template/active_record_helper_test.rb
+++ b/actionpack/test/template/active_record_helper_test.rb
@@ -5,15 +5,18 @@ class ActiveRecordHelperTest < ActionView::TestCase
silence_warnings do
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
end
class User < Struct.new(:email)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
end
class Column < Struct.new(:type, :name, :human_name)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
end
end
diff --git a/actionpack/test/template/atom_feed_helper_test.rb b/actionpack/test/template/atom_feed_helper_test.rb
index 89ff01ab0e..3acaecd142 100644
--- a/actionpack/test/template/atom_feed_helper_test.rb
+++ b/actionpack/test/template/atom_feed_helper_test.rb
@@ -1,7 +1,8 @@
require 'abstract_unit'
class Scroll < Struct.new(:id, :to_param, :title, :body, :updated_at, :created_at)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def new_record?
true
diff --git a/actionpack/test/template/form_helper_test.rb b/actionpack/test/template/form_helper_test.rb
index 883afd985b..99160dd8b1 100644
--- a/actionpack/test/template/form_helper_test.rb
+++ b/actionpack/test/template/form_helper_test.rb
@@ -2,7 +2,8 @@ require 'abstract_unit'
silence_warnings do
class Post < Struct.new(:title, :author_name, :body, :secret, :written_on, :cost)
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
alias_method :secret?, :secret
@@ -25,7 +26,8 @@ silence_warnings do
end
class Comment
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :post_id
@@ -43,7 +45,8 @@ silence_warnings do
end
class Tag
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :post_id
@@ -61,7 +64,8 @@ silence_warnings do
end
class CommentRelevance
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :comment_id
@@ -75,7 +79,8 @@ silence_warnings do
end
class TagRelevance
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :tag_id
diff --git a/actionpack/test/template/prototype_helper_test.rb b/actionpack/test/template/prototype_helper_test.rb
index 301a110076..acbf311212 100644
--- a/actionpack/test/template/prototype_helper_test.rb
+++ b/actionpack/test/template/prototype_helper_test.rb
@@ -1,11 +1,14 @@
require 'abstract_unit'
require 'active_model'
-Bunny = Struct.new(:Bunny, :id)
-Bunny.extend ActiveModel::APICompliant
+class Bunny < Struct.new(:Bunny, :id)
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
+end
class Author
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
def save; @id = 1 end
@@ -16,7 +19,8 @@ class Author
end
class Article
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_reader :id
attr_reader :author_id
def save; @id = 1; @author_id = 1 end
diff --git a/actionpack/test/template/record_tag_helper_test.rb b/actionpack/test/template/record_tag_helper_test.rb
index bae26f555d..4144fea678 100644
--- a/actionpack/test/template/record_tag_helper_test.rb
+++ b/actionpack/test/template/record_tag_helper_test.rb
@@ -1,7 +1,8 @@
require 'abstract_unit'
class Post
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
def id
45
end
diff --git a/actionpack/test/template/test_test.rb b/actionpack/test/template/test_test.rb
index 98307fbae4..f32d0b3d42 100644
--- a/actionpack/test/template/test_test.rb
+++ b/actionpack/test/template/test_test.rb
@@ -41,7 +41,7 @@ class PeopleHelperTest < ActionView::TestCase
def test_link_to_person
person = mock(:name => "David")
- person.class.extend ActiveModel::APICompliant
+ person.class.extend ActiveModel::Naming
expects(:mocha_mock_path).with(person).returns("/people/1")
assert_equal '<a href="/people/1">David</a>', link_to_person(person)
end
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 4569689534..9eeb26831c 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -494,7 +494,8 @@ class LinkToUnlessCurrentWithControllerTest < ActionView::TestCase
end
class Workshop
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_accessor :id, :new_record
def initialize(id, new_record)
@@ -511,7 +512,8 @@ class Workshop
end
class Session
- extend ActiveModel::APICompliant
+ extend ActiveModel::Naming
+ include ActiveModel::Conversion
attr_accessor :id, :workshop_id, :new_record
def initialize(id, new_record)
diff --git a/activemodel/examples/amo_ap_example.rb b/activemodel/examples/validations.rb
index cef718d0d4..3f8311ff96 100644
--- a/activemodel/examples/amo_ap_example.rb
+++ b/activemodel/examples/validations.rb
@@ -1,31 +1,24 @@
-$:.push "activesupport/lib"
-$:.push "activemodel/lib"
-
-require "active_model/validations"
-require "active_model/deprecated_error_methods"
-require "active_model/errors"
-require "active_model/naming"
+require 'activemodel'
class Person
+ include ActiveModel::Conversion
include ActiveModel::Validations
- extend ActiveModel::Naming
-
+
validates_presence_of :name
-
+
attr_accessor :name
+
def initialize(attributes = {})
@name = attributes[:name]
end
-
+
def persist
@persisted = true
end
-
+
def new_record?
@persisted
end
-
- def to_model() self end
end
person1 = Person.new
@@ -33,4 +26,4 @@ p person1.valid?
person1.errors
person2 = Person.new(:name => "matz")
-p person2.valid? \ No newline at end of file
+p person2.valid?
diff --git a/activemodel/lib/active_model.rb b/activemodel/lib/active_model.rb
index c6f63d2fdc..2de19597b1 100644
--- a/activemodel/lib/active_model.rb
+++ b/activemodel/lib/active_model.rb
@@ -26,9 +26,7 @@ $:.unshift(activesupport_path) if File.directory?(activesupport_path)
require 'active_support'
module ActiveModel
- autoload :APICompliant, 'active_model/api_compliant'
- autoload :Attributes, 'active_model/attributes'
- autoload :Base, 'active_model/base'
+ autoload :Conversion, 'active_model/conversion'
autoload :DeprecatedErrorMethods, 'active_model/deprecated_error_methods'
autoload :Errors, 'active_model/errors'
autoload :Name, 'active_model/naming'
diff --git a/activemodel/lib/active_model/api_compliant.rb b/activemodel/lib/active_model/api_compliant.rb
deleted file mode 100644
index 26f83feb6b..0000000000
--- a/activemodel/lib/active_model/api_compliant.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-module ActiveModel
- module APICompliant
- include Naming
-
- def self.extended(klass)
- klass.class_eval do
- include Validations
- include InstanceMethods
- end
- end
-
- module InstanceMethods
- def to_model
- if respond_to?(:new_record?)
- self.class.class_eval { def to_model() self end }
- to_model
- else
- raise "In order to be ActiveModel API compliant, you need to define " \
- "a new_record? method, which should return true if it has not " \
- "yet been persisted."
- end
- end
- end
- end
-end \ No newline at end of file
diff --git a/activemodel/lib/active_model/attributes.rb b/activemodel/lib/active_model/attributes.rb
deleted file mode 100644
index ea8c8d5f72..0000000000
--- a/activemodel/lib/active_model/attributes.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'active_support/core_ext/object/instance_variables'
-
-module ActiveModel
- module Attributes
- def self.append_features(base)
- unless base.instance_methods.include?('attributes')
- super
- else
- false
- end
- end
-
- def attributes
- instance_values
- end
-
- def read_attribute(attr_name)
- instance_variable_get(:"@#{attr_name}")
- end
-
- def write_attribute(attr_name, value)
- instance_variable_set(:"@#{attr_name}", value)
- end
- end
-end
diff --git a/activemodel/lib/active_model/base.rb b/activemodel/lib/active_model/base.rb
deleted file mode 100644
index a500adfdf1..0000000000
--- a/activemodel/lib/active_model/base.rb
+++ /dev/null
@@ -1,8 +0,0 @@
-module ActiveModel
- class Base
- include Observing
- # disabled, until they're tested
- # include Callbacks
- # include Validations
- end
-end \ No newline at end of file
diff --git a/activemodel/lib/active_model/conversion.rb b/activemodel/lib/active_model/conversion.rb
new file mode 100644
index 0000000000..d5c65920f6
--- /dev/null
+++ b/activemodel/lib/active_model/conversion.rb
@@ -0,0 +1,8 @@
+module ActiveModel
+ # Include ActiveModel::Conversion if your object "acts like an ActiveModel model".
+ module Conversion
+ def to_model
+ self
+ end
+ end
+end
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb
index 7bad2397ae..3b230c43b9 100644
--- a/activemodel/lib/active_model/observing.rb
+++ b/activemodel/lib/active_model/observing.rb
@@ -1,7 +1,8 @@
require 'observer'
require 'singleton'
-require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/array/wrap'
+require 'active_support/core_ext/module/aliasing'
+require 'active_support/core_ext/string/inflections'
module ActiveModel
module Observing
@@ -39,8 +40,25 @@ module ActiveModel
observers.each { |o| instantiate_observer(o) }
end
+ # Wraps methods with before and after notifications.
+ #
+ # wrap_with_notifications :create, :save, :update, :destroy
+ def wrap_with_notifications(*methods)
+ methods.each do |method|
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
+ def #{method}_with_notifications(*args, &block)
+ notify_observers(:before_#{method})
+ result = #{method}_without_notifications(*args, &block)
+ notify_observers(:after_#{method})
+ result
+ end
+ EOS
+ alias_method_chain(method, :notifications)
+ end
+ end
+
protected
- def instantiate_observer(observer)
+ def instantiate_observer(observer) #:nodoc:
# string/symbol
if observer.respond_to?(:to_sym)
observer = observer.to_s.camelize.constantize.instance
@@ -60,12 +78,72 @@ module ActiveModel
end
private
- def notify(method) #:nodoc:
+ # Fires notifications to model's observers
+ #
+ # def save
+ # notify_observers(:before_save)
+ # ...
+ # notify_observers(:after_save)
+ # end
+ def notify_observers(method)
self.class.changed
self.class.notify_observers(method, self)
end
end
+ # Observer classes respond to lifecycle callbacks to implement trigger-like
+ # behavior outside the original class. This is a great way to reduce the
+ # clutter that normally comes when the model class is burdened with
+ # functionality that doesn't pertain to the core responsibility of the
+ # class. Example:
+ #
+ # class CommentObserver < ActiveModel::Observer
+ # def after_save(comment)
+ # Notifications.deliver_comment("admin@do.com", "New comment was posted", comment)
+ # end
+ # end
+ #
+ # This Observer sends an email when a Comment#save is finished.
+ #
+ # class ContactObserver < ActiveModel::Observer
+ # def after_create(contact)
+ # contact.logger.info('New contact added!')
+ # end
+ #
+ # def after_destroy(contact)
+ # contact.logger.warn("Contact with an id of #{contact.id} was destroyed!")
+ # end
+ # end
+ #
+ # This Observer uses logger to log when specific callbacks are triggered.
+ #
+ # == Observing a class that can't be inferred
+ #
+ # Observers will by default be mapped to the class with which they share a name. So CommentObserver will
+ # be tied to observing Comment, ProductManagerObserver to ProductManager, and so on. If you want to name your observer
+ # differently than the class you're interested in observing, you can use the Observer.observe class method which takes
+ # either the concrete class (Product) or a symbol for that class (:product):
+ #
+ # class AuditObserver < ActiveModel::Observer
+ # observe :account
+ #
+ # def after_update(account)
+ # AuditTrail.new(account, "UPDATED")
+ # end
+ # end
+ #
+ # If the audit observer needs to watch more than one kind of object, this can be specified with multiple arguments:
+ #
+ # class AuditObserver < ActiveModel::Observer
+ # observe :account, :balance
+ #
+ # def after_update(record)
+ # AuditTrail.new(record, "UPDATED")
+ # end
+ # end
+ #
+ # The AuditObserver will now act on both updates to Account and Balance by treating them both as records.
+ #
class Observer
include Singleton
@@ -77,6 +155,15 @@ module ActiveModel
define_method(:observed_classes) { models }
end
+ # Returns an array of Classes to observe.
+ #
+ # You can override this instead of using the +observe+ helper.
+ #
+ # class AuditObserver < ActiveModel::Observer
+ # def self.observed_classes
+ # [AccountObserver, BalanceObserver]
+ # end
+ # end
def observed_classes
Array.wrap(observed_class)
end
@@ -97,7 +184,7 @@ module ActiveModel
observed_classes.each { |klass| add_observer!(klass) }
end
- def observed_classes
+ def observed_classes #:nodoc:
self.class.observed_classes
end
@@ -114,7 +201,7 @@ module ActiveModel
end
protected
- def add_observer!(klass)
+ def add_observer!(klass) #:nodoc:
klass.add_observer(self)
end
end
diff --git a/activemodel/lib/active_model/serializers/json.rb b/activemodel/lib/active_model/serializers/json.rb
index adf200597d..e94512fd64 100644
--- a/activemodel/lib/active_model/serializers/json.rb
+++ b/activemodel/lib/active_model/serializers/json.rb
@@ -5,7 +5,6 @@ module ActiveModel
module Serializers
module JSON
extend ActiveSupport::Concern
- include ActiveModel::Attributes
included do
extend ActiveModel::Naming
diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb
index 7cdd281223..76a0e54a56 100644
--- a/activemodel/lib/active_model/serializers/xml.rb
+++ b/activemodel/lib/active_model/serializers/xml.rb
@@ -5,7 +5,6 @@ module ActiveModel
module Serializers
module Xml
extend ActiveSupport::Concern
- include ActiveModel::Attributes
class Serializer < ActiveModel::Serializer #:nodoc:
class Attribute #:nodoc:
diff --git a/activemodel/lib/activemodel.rb b/activemodel/lib/activemodel.rb
new file mode 100644
index 0000000000..da3133103b
--- /dev/null
+++ b/activemodel/lib/activemodel.rb
@@ -0,0 +1 @@
+require 'active_model'
diff --git a/activemodel/test/cases/attributes_test.rb b/activemodel/test/cases/attributes_test.rb
deleted file mode 100644
index 5f3ea839a4..0000000000
--- a/activemodel/test/cases/attributes_test.rb
+++ /dev/null
@@ -1,30 +0,0 @@
-require 'cases/helper'
-
-class AttributesTest < ActiveModel::TestCase
- class Person
- include ActiveModel::Attributes
- attr_accessor :name
- end
-
- test "reads attribute" do
- p = Person.new
- assert_equal nil, p.read_attribute(:name)
-
- p.name = "Josh"
- assert_equal "Josh", p.read_attribute(:name)
- end
-
- test "writes attribute" do
- p = Person.new
- assert_equal nil, p.name
-
- p.write_attribute(:name, "Josh")
- assert_equal "Josh", p.name
- end
-
- test "returns all attributes" do
- p = Person.new
- p.name = "Josh"
- assert_equal({"name" => "Josh"}, p.attributes)
- end
-end
diff --git a/activemodel/test/cases/observing_test.rb b/activemodel/test/cases/observing_test.rb
index 564451fa2f..fbf93c19ef 100644
--- a/activemodel/test/cases/observing_test.rb
+++ b/activemodel/test/cases/observing_test.rb
@@ -1,6 +1,8 @@
require 'cases/helper'
-class ObservedModel < ActiveModel::Base
+class ObservedModel
+ include ActiveModel::Observing
+
class Observer
end
end
@@ -17,7 +19,8 @@ class FooObserver < ActiveModel::Observer
end
end
-class Foo < ActiveModel::Base
+class Foo
+ include ActiveModel::Observing
end
class ObservingTest < ActiveModel::TestCase
diff --git a/activemodel/test/cases/serializeration/json_serialization_test.rb b/activemodel/test/cases/serializeration/json_serialization_test.rb
index 3e69db110e..6227aedc39 100644
--- a/activemodel/test/cases/serializeration/json_serialization_test.rb
+++ b/activemodel/test/cases/serializeration/json_serialization_test.rb
@@ -3,6 +3,10 @@ require 'models/contact'
class Contact
include ActiveModel::Serializers::JSON
+
+ def attributes
+ instance_values
+ end
end
class JsonSerializationTest < ActiveModel::TestCase
diff --git a/activemodel/test/cases/serializeration/xml_serialization_test.rb b/activemodel/test/cases/serializeration/xml_serialization_test.rb
index 57792e900e..e459f6433a 100644
--- a/activemodel/test/cases/serializeration/xml_serialization_test.rb
+++ b/activemodel/test/cases/serializeration/xml_serialization_test.rb
@@ -3,6 +3,10 @@ require 'models/contact'
class Contact
include ActiveModel::Serializers::Xml
+
+ def attributes
+ instance_values
+ end
end
class XmlSerializationTest < ActiveModel::TestCase
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index f6954813a4..85f7cbfad2 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2528,13 +2528,6 @@ module ActiveRecord #:nodoc:
(id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes
end
- # Returns the ActiveRecord object when asked for its
- # ActiveModel-compliant representation, because ActiveRecord is
- # ActiveModel-compliant.
- def to_model
- self
- end
-
# Returns a cache key that can be used to identify this record.
#
# ==== Examples
@@ -3215,6 +3208,7 @@ module ActiveRecord #:nodoc:
include Dirty
include Callbacks, ActiveModel::Observing, Timestamp
include Associations, AssociationPreload, NamedScope
+ include ActiveModel::Conversion
# AutosaveAssociation needs to be included before Transactions, because we want
# #save_with_autosave_associations to be wrapped inside a transaction.
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb
index 01e41c04df..3aa0b8f1b5 100644
--- a/activerecord/lib/active_record/callbacks.rb
+++ b/activerecord/lib/active_record/callbacks.rb
@@ -349,7 +349,7 @@ module ActiveRecord
result = send(method)
end
- notify(method)
+ notify_observers(method)
return result
end
diff --git a/activeresource/lib/active_resource.rb b/activeresource/lib/active_resource.rb
index 1dcb795a7d..fd4c199b48 100644
--- a/activeresource/lib/active_resource.rb
+++ b/activeresource/lib/active_resource.rb
@@ -34,6 +34,7 @@ module ActiveResource
autoload :Connection, 'active_resource/connection'
autoload :CustomMethods, 'active_resource/custom_methods'
autoload :Formats, 'active_resource/formats'
+ autoload :Observing, 'active_resource/observing'
autoload :Validations, 'active_resource/validations'
autoload :HttpMock, 'active_resource/http_mock'
end
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index 88a431a6d9..bc82139dac 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -804,8 +804,7 @@ module ActiveResource
# my_company.size = 10
# my_company.save # sends PUT /companies/1 (update)
def save
- notify(:before_save)
- (new? ? create : update).tap { notify(:after_save) }
+ new? ? create : update
end
# Deletes the resource from the remote service.
@@ -821,8 +820,7 @@ module ActiveResource
# new_person.destroy
# Person.find(new_id) # 404 (Resource Not Found)
def destroy
- notify(:before_destroy)
- connection.delete(element_path, self.class.headers).tap { notify(:after_destroy) }
+ connection.delete(element_path, self.class.headers)
end
# Evaluates to <tt>true</tt> if this resource is not <tt>new?</tt> and is
@@ -997,20 +995,16 @@ module ActiveResource
# Update the resource on the remote service.
def update
- notify(:before_update)
connection.put(element_path(prefix_options), encode, self.class.headers).tap do |response|
load_attributes_from_response(response)
- notify(:after_update)
end
end
# Create (i.e., \save to the remote service) the \new resource.
def create
- notify(:before_create)
connection.post(collection_path, encode, self.class.headers).tap do |response|
self.id = id_from_response(response)
load_attributes_from_response(response)
- notify(:after_create)
end
end
@@ -1093,7 +1087,6 @@ module ActiveResource
class Base
extend ActiveModel::Naming
- include CustomMethods, Validations
- include ActiveModel::Observing
+ include CustomMethods, Observing, Validations
end
end
diff --git a/activeresource/lib/active_resource/observing.rb b/activeresource/lib/active_resource/observing.rb
new file mode 100644
index 0000000000..94836f4bb1
--- /dev/null
+++ b/activeresource/lib/active_resource/observing.rb
@@ -0,0 +1,10 @@
+module ActiveResource
+ module Observing
+ extend ActiveSupport::Concern
+ include ActiveModel::Observing
+
+ included do
+ wrap_with_notifications :create, :save, :update, :destroy
+ end
+ end
+end
diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb
index d5282bad6a..c915bf799d 100644
--- a/activesupport/lib/active_support/test_case.rb
+++ b/activesupport/lib/active_support/test_case.rb
@@ -19,7 +19,8 @@ module ActiveSupport
class TestCase < ::Test::Unit::TestCase
if defined? MiniTest
Assertion = MiniTest::Assertion
- alias_method :method_name, :name
+ alias_method :method_name, :name if method_defined? :name
+ alias_method :method_name, :__name__ if method_defined? :__name__
else
# TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit
if defined?(Rails) && ENV['BACKTRACE'].nil?
diff --git a/railties/bin/about b/railties/bin/about
index ed8deb0dfc..1eeb6eb915 100755
--- a/railties/bin/about
+++ b/railties/bin/about
@@ -1,4 +1,4 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
+require File.expand_path('../../config/boot', __FILE__)
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
-require 'commands/about' \ No newline at end of file
+require 'commands/about'
diff --git a/railties/bin/console b/railties/bin/console
index 498077ab33..235a1f2780 100755
--- a/railties/bin/console
+++ b/railties/bin/console
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
+require File.expand_path('../../config/boot', __FILE__)
require 'commands/console'
diff --git a/railties/bin/dbconsole b/railties/bin/dbconsole
index caa60ce829..83c8436a9d 100755
--- a/railties/bin/dbconsole
+++ b/railties/bin/dbconsole
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
+require File.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'
diff --git a/railties/bin/destroy b/railties/bin/destroy
index a4df765a39..88d295f7aa 100755
--- a/railties/bin/destroy
+++ b/railties/bin/destroy
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
+require File.expand_path('../../config/boot', __FILE__)
require 'commands/destroy'
diff --git a/railties/bin/generate b/railties/bin/generate
index 173a9f147d..62a8a4c0c5 100755
--- a/railties/bin/generate
+++ b/railties/bin/generate
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
+require File.expand_path('../../config/boot', __FILE__)
require 'commands/generate'
diff --git a/railties/bin/performance/benchmarker b/railties/bin/performance/benchmarker
index c842d35d33..3bff809fb3 100755
--- a/railties/bin/performance/benchmarker
+++ b/railties/bin/performance/benchmarker
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot'
+require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
diff --git a/railties/bin/performance/profiler b/railties/bin/performance/profiler
index d855ac8b13..07640575cd 100755
--- a/railties/bin/performance/profiler
+++ b/railties/bin/performance/profiler
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../../config/boot'
+require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
diff --git a/railties/bin/plugin b/railties/bin/plugin
index 87cd2070fe..b82201fa83 100755
--- a/railties/bin/plugin
+++ b/railties/bin/plugin
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
+require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'
diff --git a/railties/bin/runner b/railties/bin/runner
index a4a7cb25ba..be4c5d4572 100755
--- a/railties/bin/runner
+++ b/railties/bin/runner
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
+require File.expand_path('../../config/boot', __FILE__)
require 'commands/runner'
diff --git a/railties/bin/server b/railties/bin/server
index 3c67f39b69..b9fcb71793 100755
--- a/railties/bin/server
+++ b/railties/bin/server
@@ -1,3 +1,3 @@
#!/usr/bin/env ruby
-require File.dirname(__FILE__) + '/../config/boot'
+require File.expand_path('../../config/boot', __FILE__)
require 'commands/server'
diff --git a/railties/lib/vendor/bundler/LICENSE b/railties/lib/vendor/bundler/LICENSE
new file mode 100644
index 0000000000..41decca113
--- /dev/null
+++ b/railties/lib/vendor/bundler/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2009 Engine Yard
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/Rakefile b/railties/lib/vendor/bundler/Rakefile
new file mode 100644
index 0000000000..fd39fbff77
--- /dev/null
+++ b/railties/lib/vendor/bundler/Rakefile
@@ -0,0 +1,52 @@
+require 'rubygems' unless ENV['NO_RUBYGEMS']
+require 'rake/gempackagetask'
+require 'rubygems/specification'
+require 'date'
+require 'spec/rake/spectask'
+
+spec = Gem::Specification.new do |s|
+ s.name = "bundler"
+ s.version = "0.0.1"
+ s.author = "Your Name"
+ s.email = "Your Email"
+ s.homepage = "http://example.com"
+ s.description = s.summary = "A gem that provides..."
+
+ s.platform = Gem::Platform::RUBY
+ s.has_rdoc = true
+ s.extra_rdoc_files = ["README", "LICENSE"]
+ s.summary = ""
+
+ # Uncomment this to add a dependency
+ # s.add_dependency "foo"
+
+ s.bindir = "bin"
+ s.executables = %w( gem_bundler )
+ s.require_path = 'lib'
+ s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
+end
+
+task :default => :spec
+
+desc "Run specs"
+Spec::Rake::SpecTask.new do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb']
+ t.spec_opts = %w(-fs --color)
+end
+
+
+Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.gem_spec = spec
+end
+
+desc "install the gem locally"
+task :install => [:package] do
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
+end
+
+desc "create a gemspec file"
+task :make_spec do
+ File.open("#{GEM}.gemspec", "w") do |file|
+ file.puts spec.to_ruby
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/bin/gem_bundler b/railties/lib/vendor/bundler/bin/gem_bundler
new file mode 100755
index 0000000000..7a8771efee
--- /dev/null
+++ b/railties/lib/vendor/bundler/bin/gem_bundler
@@ -0,0 +1,40 @@
+#!/usr/bin/env ruby
+require "optparse"
+require "bundler"
+
+options = {}
+
+parser = OptionParser.new do |op|
+ op.banner = "Usage: gem_bundler [OPTIONS] [PATH]"
+
+ op.on("-m", "--manifest MANIFEST") do |manifest|
+ options[:manifest] = manifest
+ end
+
+ op.on_tail("-h", "--help", "Show this message") do
+ puts op
+ exit
+ end
+end
+parser.parse!
+
+options[:path] = ARGV.shift
+
+unless options[:path]
+ puts parser
+ puts %(
+ [PATH] must be specified
+ )
+ exit
+end
+
+unless options[:manifest] && File.exist?(options[:manifest])
+ puts parser
+ puts %(
+ MANIFEST must be a valid manifest file
+ )
+ exit
+end
+
+
+Bundler.run(options) \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler.rb b/railties/lib/vendor/bundler/lib/bundler.rb
new file mode 100644
index 0000000000..4dcab20da9
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler.rb
@@ -0,0 +1,24 @@
+require 'logger'
+require 'set'
+# Required elements of rubygems
+require "rubygems/remote_fetcher"
+require "rubygems/installer"
+
+require "bundler/gem_bundle"
+require "bundler/installer"
+require "bundler/finder"
+require "bundler/gem_specification"
+require "bundler/resolver"
+require "bundler/manifest"
+require "bundler/dependency"
+require "bundler/runtime"
+require "bundler/cli"
+
+module Bundler
+ VERSION = "0.5.0"
+
+ def self.run(options = {})
+ manifest = ManifestBuilder.load(options[:path], options[:manifest])
+ manifest.install
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/cli.rb b/railties/lib/vendor/bundler/lib/bundler/cli.rb
new file mode 100644
index 0000000000..ed49ef88f0
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/cli.rb
@@ -0,0 +1,24 @@
+module Bundler
+ module CLI
+
+ def default_manifest
+ current = Pathname.new(Dir.pwd)
+
+ begin
+ manifest = current.join("Gemfile")
+ return manifest.to_s if File.exist?(manifest)
+ current = current.parent
+ end until current.root?
+ nil
+ end
+
+ module_function :default_manifest
+
+ def default_path
+ Pathname.new(File.dirname(default_manifest)).join("vendor").join("gems").to_s
+ end
+
+ module_function :default_path
+
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/dependency.rb b/railties/lib/vendor/bundler/lib/bundler/dependency.rb
new file mode 100644
index 0000000000..739a7a117d
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/dependency.rb
@@ -0,0 +1,35 @@
+module Bundler
+ class Dependency
+
+ attr_reader :name, :version, :require_as, :only, :except
+
+ def initialize(name, options = {})
+ options.each do |k, v|
+ options[k.to_s] = v
+ end
+
+ @name = name
+ @version = options["version"] || ">= 0"
+ @require_as = Array(options["require_as"] || name)
+ @only = Array(options["only"]).map {|e| e.to_s } if options["only"]
+ @except = Array(options["except"]).map {|e| e.to_s } if options["except"]
+ end
+
+ def in?(environment)
+ environment = environment.to_s
+
+ return false unless !@only || @only.include?(environment)
+ return false if @except && @except.include?(environment)
+ true
+ end
+
+ def to_s
+ to_gem_dependency.to_s
+ end
+
+ def to_gem_dependency
+ @gem_dep ||= Gem::Dependency.new(name, version)
+ end
+
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/finder.rb b/railties/lib/vendor/bundler/lib/bundler/finder.rb
new file mode 100644
index 0000000000..43ff370ae4
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/finder.rb
@@ -0,0 +1,42 @@
+module Bundler
+ class Finder
+ def initialize(*sources)
+ @results = {}
+ @index = Hash.new { |h,k| h[k] = {} }
+
+ sources.each { |source| fetch(source) }
+ end
+
+ def resolve(*dependencies)
+ resolved = Resolver.resolve(dependencies, self)
+ resolved && GemBundle.new(resolved.all_specs)
+ end
+
+ def fetch(source)
+ deflated = Gem::RemoteFetcher.fetcher.fetch_path("#{source}/Marshal.4.8.Z")
+ inflated = Gem.inflate deflated
+
+ append(Marshal.load(inflated), source)
+ rescue Gem::RemoteFetcher::FetchError => e
+ raise ArgumentError, "#{source} is not a valid source: #{e.message}"
+ end
+
+ def append(index, source)
+ index.gems.values.each do |spec|
+ next unless Gem::Platform.match(spec.platform)
+ spec.source = source
+ @index[spec.name][spec.version] ||= spec
+ end
+ self
+ end
+
+ def search(dependency)
+ @results[dependency.hash] ||= begin
+ possibilities = @index[dependency.name].values
+ possibilities.select do |spec|
+ dependency =~ spec
+ end.sort_by {|s| s.version }
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/gem_bundle.rb b/railties/lib/vendor/bundler/lib/bundler/gem_bundle.rb
new file mode 100644
index 0000000000..b749720fd9
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/gem_bundle.rb
@@ -0,0 +1,23 @@
+module Bundler
+ class GemBundle < Array
+ def download(directory)
+ FileUtils.mkdir_p(directory)
+
+ current = Dir[File.join(directory, "cache", "*.gem*")]
+
+ each do |spec|
+ cached = File.join(directory, "cache", "#{spec.full_name}.gem")
+
+ unless File.file?(cached)
+ Gem::RemoteFetcher.fetcher.download(spec, spec.source, directory)
+ end
+
+ current.delete(cached)
+ end
+
+ current.each { |file| File.delete(file) }
+
+ self
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/gem_specification.rb b/railties/lib/vendor/bundler/lib/bundler/gem_specification.rb
new file mode 100644
index 0000000000..680b61fd69
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/gem_specification.rb
@@ -0,0 +1,10 @@
+module Gem
+ class Specification
+ attribute :source
+
+ def source=(source)
+ @source = source.is_a?(URI) ? source : URI.parse(source)
+ raise ArgumentError, "The source must be an absolute URI" unless @source.absolute?
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/installer.rb b/railties/lib/vendor/bundler/lib/bundler/installer.rb
new file mode 100644
index 0000000000..581d9d3c8e
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/installer.rb
@@ -0,0 +1,44 @@
+module Bundler
+ class Installer
+ def initialize(path)
+ if !File.directory?(path)
+ raise ArgumentError, "#{path} is not a directory"
+ elsif !File.directory?(File.join(path, "cache"))
+ raise ArgumentError, "#{path} is not a valid environment (it does not contain a cache directory)"
+ end
+
+ @path = path
+ @gems = Dir[(File.join(path, "cache", "*.gem"))]
+ end
+
+ def install(options = {})
+ bin_dir = options[:bin_dir] ||= File.join(@path, "bin")
+
+ specs = Dir[File.join(@path, "specifications", "*.gemspec")]
+ gems = Dir[File.join(@path, "gems", "*")]
+
+ @gems.each do |gem|
+ name = File.basename(gem).gsub(/\.gem$/, '')
+ installed = specs.any? { |g| File.basename(g) == "#{name}.gemspec" } &&
+ gems.any? { |g| File.basename(g) == name }
+
+ unless installed
+ installer = Gem::Installer.new(gem, :install_dir => @path,
+ :ignore_dependencies => true,
+ :env_shebang => true,
+ :wrappers => true,
+ :bin_dir => bin_dir)
+ installer.install
+ end
+
+ # remove this spec
+ specs.delete_if { |g| File.basename(g) == "#{name}.gemspec"}
+ gems.delete_if { |g| File.basename(g) == name }
+ end
+
+ (specs + gems).each do |path|
+ FileUtils.rm_rf(path)
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/manifest.rb b/railties/lib/vendor/bundler/lib/bundler/manifest.rb
new file mode 100644
index 0000000000..847a41940d
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/manifest.rb
@@ -0,0 +1,130 @@
+require "rubygems/source_index"
+require "pathname"
+
+module Bundler
+ class VersionConflict < StandardError; end
+
+ class Manifest
+ attr_reader :sources, :dependencies, :path
+
+ def initialize(sources, dependencies, path)
+ sources.map! {|s| s.is_a?(URI) ? s : URI.parse(s) }
+ @sources, @dependencies, @path = sources, dependencies, Pathname.new(path)
+ end
+
+ def fetch
+ return if all_gems_installed?
+
+ finder = Finder.new(*sources)
+ unless bundle = finder.resolve(*gem_dependencies)
+ gems = @dependencies.map {|d| " #{d.to_s}" }.join("\n")
+ raise VersionConflict, "No compatible versions could be found for:\n#{gems}"
+ end
+
+ bundle.download(@path)
+ end
+
+ def install(options = {})
+ fetch
+ installer = Installer.new(@path)
+ installer.install # options come here
+ create_load_paths_files(File.join(@path, "environments"))
+ create_fake_rubygems(File.join(@path, "environments"))
+ end
+
+ def activate(environment = "default")
+ require File.join(@path, "environments", "#{environment}.rb")
+ end
+
+ def require_all
+ dependencies.each do |dep|
+ dep.require_as.each {|file| require file }
+ end
+ end
+
+ def gems_for(environment)
+ deps = dependencies.select { |d| d.in?(environment) }
+ deps.map! { |d| d.to_gem_dependency }
+ index = Gem::SourceIndex.from_gems_in(File.join(@path, "specifications"))
+ Resolver.resolve(deps, index).all_specs
+ end
+
+ def environments
+ envs = dependencies.map {|dep| Array(dep.only) + Array(dep.except) }.flatten
+ envs << "default"
+ end
+
+ private
+
+ def gem_dependencies
+ @gem_dependencies ||= dependencies.map { |d| d.to_gem_dependency }
+ end
+
+ def all_gems_installed?
+ gem_versions = {}
+
+ Dir[File.join(@path, "cache", "*.gem")].each do |file|
+ file =~ /\/([^\/]+)-([\d\.]+)\.gem$/
+ name, version = $1, $2
+ gem_versions[name] = Gem::Version.new(version)
+ end
+
+ gem_dependencies.all? do |dep|
+ gem_versions[dep.name] &&
+ dep.version_requirements.satisfied_by?(gem_versions[dep.name])
+ end
+ end
+
+ def create_load_paths_files(path)
+ FileUtils.mkdir_p(path)
+ environments.each do |environment|
+ gem_specs = gems_for(environment)
+ File.open(File.join(path, "#{environment}.rb"), "w") do |file|
+ file.puts <<-RUBY_EVAL
+ module Bundler
+ def self.rubygems_required
+ #{create_gem_stubs(path, gem_specs)}
+ end
+ end
+ RUBY_EVAL
+ file.puts "$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__))"
+ load_paths_for_specs(gem_specs).each do |load_path|
+ file.puts "$LOAD_PATH.unshift #{load_path.inspect}"
+ end
+ end
+ end
+ end
+
+ def create_gem_stubs(path, gem_specs)
+ gem_specs.map do |spec|
+ path = File.expand_path(File.join(path, '..', 'specifications', "#{spec.full_name}.gemspec"))
+ %{
+ Gem.loaded_specs["#{spec.name}"] = eval(File.read("#{path}"))
+ }
+ end.join("\n")
+ end
+
+ def create_fake_rubygems(path)
+ File.open(File.join(path, "rubygems.rb"), "w") do |file|
+ file.puts <<-RUBY_EVAL
+ $:.delete File.expand_path(File.dirname(__FILE__))
+ load "rubygems.rb"
+ if defined?(Bundler) && Bundler.respond_to?(:rubygems_required)
+ Bundler.rubygems_required
+ end
+ RUBY_EVAL
+ end
+ end
+
+ def load_paths_for_specs(specs)
+ load_paths = []
+ specs.each do |spec|
+ load_paths << File.join(spec.full_gem_path, spec.bindir) if spec.bindir
+ spec.require_paths.each do |path|
+ load_paths << File.join(spec.full_gem_path, path)
+ end
+ end
+ load_paths
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/resolver.rb b/railties/lib/vendor/bundler/lib/bundler/resolver.rb
new file mode 100644
index 0000000000..1ec89e53c4
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/resolver.rb
@@ -0,0 +1,19 @@
+require 'bundler/resolver/inspect'
+require 'bundler/resolver/search'
+require 'bundler/resolver/engine'
+require 'bundler/resolver/stack'
+require 'bundler/resolver/state'
+
+module Bundler
+ module Resolver
+ def self.resolve(deps, source_index = Gem.source_index, logger = nil)
+ unless logger
+ logger = Logger.new($stderr)
+ logger.datetime_format = ""
+ logger.level = ENV["GEM_RESOLVER_DEBUG"] ? Logger::DEBUG : Logger::ERROR
+ end
+
+ Engine.resolve(deps, source_index, logger)
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/resolver/builders.rb b/railties/lib/vendor/bundler/lib/bundler/resolver/builders.rb
new file mode 100644
index 0000000000..2b7b48211c
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/resolver/builders.rb
@@ -0,0 +1,61 @@
+module Bundler
+ module Resolver
+ module Builders
+ def build_index(&block)
+ index = Gem::SourceIndex.new
+ IndexBuilder.run(index, &block) if block_given?
+ index
+ end
+
+ def build_spec(name, version, &block)
+ spec = Gem::Specification.new
+ spec.instance_variable_set(:@name, name)
+ spec.instance_variable_set(:@version, Gem::Version.new(version))
+ DepBuilder.run(spec, &block) if block_given?
+ spec
+ end
+
+ def build_dep(name, requirements, type = :runtime)
+ Gem::Dependency.new(name, requirements, type)
+ end
+
+ class IndexBuilder
+ include Builders
+
+ def self.run(index, &block)
+ new(index).run(&block)
+ end
+
+ def initialize(index)
+ @index = index
+ end
+
+ def run(&block)
+ instance_eval(&block)
+ end
+
+ def add_spec(*args, &block)
+ @index.add_spec(build_spec(*args, &block))
+ end
+ end
+
+ class DepBuilder
+ def self.run(spec, &block)
+ new(spec).run(&block)
+ end
+
+ def initialize(spec)
+ @spec = spec
+ end
+
+ def run(&block)
+ instance_eval(&block)
+ end
+
+ def runtime(name, requirements)
+ @spec.add_runtime_dependency(name, requirements)
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/resolver/engine.rb b/railties/lib/vendor/bundler/lib/bundler/resolver/engine.rb
new file mode 100644
index 0000000000..475ba516ff
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/resolver/engine.rb
@@ -0,0 +1,38 @@
+module Bundler
+ module Resolver
+ class ClosedSet < Set
+ end
+
+ class Engine
+ include Search, Inspect
+
+ def self.resolve(deps, source_index, logger)
+ new(deps, source_index, logger).resolve
+ end
+
+ def initialize(deps, source_index, logger)
+ @deps, @source_index, @logger = deps, source_index, logger
+ logger.debug "searching for #{gem_resolver_inspect(@deps)}"
+ end
+ attr_reader :deps, :source_index, :logger, :solution
+
+ def resolve
+ state = State.initial(self, [], Stack.new, Stack.new([[[], @deps.dup]]))
+ if solution = search(state)
+ logger.info "got the solution with #{solution.all_specs.size} specs"
+ solution.dump(Logger::INFO)
+ solution
+ end
+ end
+
+ def open
+ @open ||= []
+ end
+
+ def closed
+ @closed ||= ClosedSet.new
+ end
+ end
+ end
+
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/resolver/inspect.rb b/railties/lib/vendor/bundler/lib/bundler/resolver/inspect.rb
new file mode 100644
index 0000000000..59640aa5f3
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/resolver/inspect.rb
@@ -0,0 +1,24 @@
+module Bundler
+ module Resolver
+ module Inspect
+ def gem_resolver_inspect(o)
+ case o
+ when Gem::Specification
+ "#<Spec: #{o.full_name}>"
+ when Array
+ '[' + o.map {|x| gem_resolver_inspect(x)}.join(", ") + ']'
+ when Set
+ gem_resolver_inspect(o.to_a)
+ when Hash
+ '{' + o.map {|k,v| "#{gem_resolver_inspect(k)} => #{gem_resolver_inspect(v)}"}.join(", ") + '}'
+ when Stack
+ o.gem_resolver_inspect
+ else
+ o.inspect
+ end
+ end
+
+ module_function :gem_resolver_inspect
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/resolver/search.rb b/railties/lib/vendor/bundler/lib/bundler/resolver/search.rb
new file mode 100644
index 0000000000..34102ff04c
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/resolver/search.rb
@@ -0,0 +1,71 @@
+module Bundler
+ module Resolver
+ module Search
+ def search(initial, max_depth = (1.0 / 0.0))
+ if initial.goal_met?
+ return initial
+ end
+
+ open << initial
+
+ while open.any?
+ current = open.pop
+ closed << current
+
+ new = []
+ current.each_possibility do |attempt|
+ unless closed.include?(attempt)
+ if attempt.goal_met?
+ return attempt
+ elsif attempt.depth < max_depth
+ new << attempt
+ end
+ end
+ end
+ new.reverse.each do |state|
+ open << state
+ end
+ end
+
+ nil
+ end
+
+ def open
+ raise "implement #open in #{self.class}"
+ end
+
+ def closed
+ raise "implement #closed in #{self.class}"
+ end
+
+ module Node
+ def self.included(base)
+ base.extend(ClassMethods)
+ end
+
+ module ClassMethods
+ def initial(*data)
+ new(0, *data)
+ end
+ end
+
+ def initialize(depth)
+ @depth = depth
+ end
+ attr_reader :depth
+
+ def child(*data)
+ self.class.new(@depth + 1, *data)
+ end
+
+ def each_possibility
+ raise "implement #each_possibility on #{self.class}"
+ end
+
+ def goal_met?
+ raise "implement #goal_met? on #{self.class}"
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/resolver/stack.rb b/railties/lib/vendor/bundler/lib/bundler/resolver/stack.rb
new file mode 100644
index 0000000000..6e1ac67e1f
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/resolver/stack.rb
@@ -0,0 +1,72 @@
+module Bundler
+ module Resolver
+ class Stack
+ def initialize(initial = [])
+ @data = []
+ initial.each do |(path,value)|
+ self[path] = value
+ end
+ end
+
+ def last
+ @data.last
+ end
+
+ def []=(path, value)
+ raise ArgumentError, "#{path.inspect} already has a value" if key?(path)
+ @data << [path.dup, value]
+ end
+
+ def [](path)
+ if key?(path)
+ _, value = @data.find do |(k,v)|
+ k == path
+ end
+ value
+ else
+ raise "No value for #{path.inspect}"
+ end
+ end
+
+ def key?(path)
+ @data.any? do |(k,v)|
+ k == path
+ end
+ end
+
+ def each
+ @data.each do |(k,v)|
+ yield k, v
+ end
+ end
+
+ def map
+ @data.map do |(k,v)|
+ yield k, v
+ end
+ end
+
+ def each_value
+ @data.each do |(k,v)|
+ yield v
+ end
+ end
+
+ def dup
+ self.class.new(@data.dup)
+ end
+
+ def to_s
+ @data.to_s
+ end
+
+ def inspect
+ @data.inspect
+ end
+
+ def gem_resolver_inspect
+ Inspect.gem_resolver_inspect(@data)
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/resolver/state.rb b/railties/lib/vendor/bundler/lib/bundler/resolver/state.rb
new file mode 100644
index 0000000000..f13ecbbee7
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/resolver/state.rb
@@ -0,0 +1,172 @@
+module Bundler
+ module Resolver
+ class State
+ include Search::Node, Inspect
+
+ def initialize(depth, engine, path, spec_stack, dep_stack)
+ super(depth)
+ @engine, @path, @spec_stack, @dep_stack = engine, path, spec_stack, dep_stack
+ end
+ attr_reader :path
+
+ def logger
+ @engine.logger
+ end
+
+ def goal_met?
+ logger.info "checking if goal is met"
+ dump
+ no_duplicates?
+ all_deps.all? do |dep|
+ dependency_satisfied?(dep)
+ end
+ end
+
+ def no_duplicates?
+ names = []
+ all_specs.each do |s|
+ if names.include?(s.name)
+ raise "somehow got duplicates for #{s.name}"
+ end
+ names << s.name
+ end
+ end
+
+ def dependency_satisfied?(dep)
+ all_specs.any? do |spec|
+ spec.satisfies_requirement?(dep)
+ end
+ end
+
+ def each_possibility(&block)
+ index, dep = remaining_deps.first
+ if dep
+ logger.warn "working on #{dep} for #{spec_name}"
+ handle_dep(index, dep, &block)
+ else
+ logger.warn "no dependencies left for #{spec_name}"
+ jump_to_parent(&block)
+ end
+ end
+
+ def handle_dep(index, dep)
+ specs = @engine.source_index.search(dep)
+
+ specs.reverse.each do |s|
+ logger.info "attempting with spec: #{s.full_name}"
+ new_path = @path + [index]
+ new_spec_stack = @spec_stack.dup
+ new_dep_stack = @dep_stack.dup
+
+ new_spec_stack[new_path] = s
+ new_dep_stack[new_path] = s.runtime_dependencies.sort_by do |dep|
+ @engine.source_index.search(dep).size
+ end
+ yield child(@engine, new_path, new_spec_stack, new_dep_stack)
+ end
+ end
+
+ def jump_to_parent
+ if @path.empty?
+ dump
+ logger.warn "at the end"
+ return
+ end
+
+ logger.info "jumping to parent for #{spec_name}"
+ new_path = @path[0..-2]
+ new_spec_stack = @spec_stack.dup
+ new_dep_stack = @dep_stack.dup
+
+ yield child(@engine, new_path, new_spec_stack, new_dep_stack)
+ end
+
+ def remaining_deps
+ remaining_deps_for(@path)
+ end
+
+ def remaining_deps_for(path)
+ no_duplicates?
+ remaining = []
+ @dep_stack[path].each_with_index do |dep,i|
+ remaining << [i, dep] unless all_specs.find {|s| s.name == dep.name}
+ end
+ remaining
+ end
+
+ def deps
+ @dep_stack[@path]
+ end
+
+ def spec
+ @spec_stack[@path]
+ end
+
+ def spec_name
+ @path.empty? ? "<top>" : spec.full_name
+ end
+
+ def all_deps
+ all_deps = Set.new
+ @dep_stack.each_value do |deps|
+ all_deps.merge(deps)
+ end
+ all_deps.to_a
+ end
+
+ def all_specs
+ @spec_stack.map do |path,spec|
+ spec
+ end
+ end
+
+ def dump(level = Logger::DEBUG)
+ logger.add level, "v" * 80
+ logger.add level, "path: #{@path.inspect}"
+ logger.add level, "deps: (#{deps.size})"
+ deps.map do |dep|
+ logger.add level, gem_resolver_inspect(dep)
+ end
+ logger.add level, "remaining_deps: (#{remaining_deps.size})"
+ remaining_deps.each do |dep|
+ logger.add level, gem_resolver_inspect(dep)
+ end
+ logger.add level, "dep_stack: "
+ @dep_stack.each do |path,deps|
+ logger.add level, "#{path.inspect} (#{deps.size})"
+ deps.each do |dep|
+ logger.add level, "-> #{gem_resolver_inspect(dep)}"
+ end
+ end
+ logger.add level, "spec_stack: "
+ @spec_stack.each do |path,spec|
+ logger.add level, "#{path.inspect}: #{gem_resolver_inspect(spec)}"
+ end
+ logger.add level, "^" * 80
+ end
+
+ def to_dot
+ io = StringIO.new
+ io.puts 'digraph deps {'
+ io.puts ' fontname = "Courier";'
+ io.puts ' mincross = 4.0;'
+ io.puts ' ratio = "auto";'
+ dump_to_dot(io, "<top>", [])
+ io.puts '}'
+ io.string
+ end
+
+ def dump_to_dot(io, name, path)
+ @dep_stack[path].each_with_index do |dep,i|
+ new_path = path + [i]
+ spec_name = all_specs.find {|x| x.name == dep.name}.full_name
+ io.puts ' "%s" -> "%s";' % [name, dep.to_s]
+ io.puts ' "%s" -> "%s";' % [dep.to_s, spec_name]
+ if @spec_stack.key?(new_path)
+ dump_to_dot(io, spec_name, new_path)
+ end
+ end
+ end
+ end
+ end
+end \ No newline at end of file
diff --git a/railties/lib/vendor/bundler/lib/bundler/runtime.rb b/railties/lib/vendor/bundler/lib/bundler/runtime.rb
new file mode 100644
index 0000000000..2376deef28
--- /dev/null
+++ b/railties/lib/vendor/bundler/lib/bundler/runtime.rb
@@ -0,0 +1,39 @@
+module Bundler
+ class ManifestBuilder
+
+ attr_reader :sources
+
+ def self.build(path, string)
+ builder = new(path)
+ builder.instance_eval(string)
+ builder.to_manifest
+ end
+
+ def self.load(path, file)
+ string = File.read(file)
+ build(path, string)
+ end
+
+ def initialize(path)
+ @path = path
+ @sources = %w(http://gems.rubyforge.org)
+ @dependencies = []
+ end
+
+ def to_manifest
+ Manifest.new(@sources, @dependencies, @path)
+ end
+
+ def source(source)
+ @sources << source
+ end
+
+ def gem(name, *args)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ version = args.last
+
+ @dependencies << Dependency.new(name, options.merge(:version => version))
+ end
+
+ end
+end \ No newline at end of file