Sha256: bb926111e08b61d394248361c9c3dc63fa1d65961d793543fd4926168a1beb69

Contents?: true

Size: 1.53 KB

Versions: 21

Compression:

Stored size: 1.53 KB

Contents

module InheritedResources #:nodoc:
  module SingletonHelpers #:nodoc:

    # Protected helpers. You might want to overwrite some of them.
    protected
      # Singleton methods does not deal with collections.
      #
      def collection
        nil
      end

      # Overwrites how singleton deals with resource.
      # If you are going to overwrite it, you should notice that the
      # end_of_association_chain here is not the same as in default belongs_to.
      #
      #   class TasksController < InheritedResources::Base
      #     belongs_to :project
      #   end
      #
      # In this case, the association chain would be:
      #
      #   Project.find(params[:project_id]).tasks
      #
      # So you would just have to call find(:all) at the end of association
      # chain. And this is what happened.
      #
      # In singleton controllers:
      #
      #   class ManagersController < InheritedResources::Base
      #     belongs_to :project, :singleton => true
      #   end
      #
      # The association chain will be:
      #
      #   Project.find(params[:project_id])
      #
      # So we have to call manager on it. And again, this is what happens.
      #
      def resource
        get_resource_ivar || set_resource_ivar(end_of_association_chain.send(resource_instance_name))
      end

    # Private helpers, you probably don't have to worry with them.
    private

      # Returns the appropriated method to build the resource.
      #
      def method_for_build
        "build_#{resource_instance_name}"
      end

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
josevalim-inherited_resources-0.1.1 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.1.2 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.1 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.2.0 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.2.1 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.2.2 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.3 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.4.1 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.4.2 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.4.3 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.4.4 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.4.5 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.4.6 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.4 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.5.0 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.5.1 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.5.2 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.6.0 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.6.1 lib/inherited_resources/singleton_helpers.rb
josevalim-inherited_resources-0.6.2 lib/inherited_resources/singleton_helpers.rb