inherited_resources_helpers 0.0.1 → 0.0.2
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.
| @@ -1,6 +1,10 @@ | |
| 1 1 | 
             
            module InheritedResources
         | 
| 2 2 | 
             
              module Helpers
         | 
| 3 3 | 
             
                module UrlFor
         | 
| 4 | 
            +
                  def self.included(base)
         | 
| 5 | 
            +
                    base.send(:helper_method, public_instance_methods(false))
         | 
| 6 | 
            +
                  end
         | 
| 7 | 
            +
             | 
| 4 8 | 
             
                  def index_url(options = {})
         | 
| 5 9 | 
             
                    polymorphic_url(parent_resources << resource_class, options)
         | 
| 6 10 | 
             
                  end
         | 
| @@ -10,12 +14,13 @@ module InheritedResources | |
| 10 14 | 
             
                  end
         | 
| 11 15 |  | 
| 12 16 | 
             
                  def show_url(options = {})
         | 
| 17 | 
            +
                    raise_invalid_url_helper(:show_url, resource) if resource.new_record?
         | 
| 13 18 | 
             
                    raise "can't generate show_url because the current resource (#{resource.inspect}) is a new record" if resource.new_record?
         | 
| 14 19 | 
             
                    polymorphic_url(resources, options)
         | 
| 15 20 | 
             
                  end
         | 
| 16 21 |  | 
| 17 22 | 
             
                  def edit_url(options = {})
         | 
| 18 | 
            -
                     | 
| 23 | 
            +
                    raise_invalid_url_helper(:edit_url, resource) if resource.new_record?
         | 
| 19 24 | 
             
                    polymorphic_url(resources.unshift(:edit), options)
         | 
| 20 25 | 
             
                  end
         | 
| 21 26 |  | 
| @@ -24,6 +29,64 @@ module InheritedResources | |
| 24 29 | 
             
                      send(:"#{action}_url", args.extract_options!.reverse_merge(:routing_type => :path))
         | 
| 25 30 | 
             
                    end
         | 
| 26 31 | 
             
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def parent_index_url(options = {})
         | 
| 34 | 
            +
                    polymorphic_url(parent_resources[0..-2] << parent_resources.last.class, options)
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  def parent_new_url(options = {})
         | 
| 38 | 
            +
                    polymorphic_url(parent_resources[0..-2].unshift(:new) << parent_resources.last.class.name.underscore, options)
         | 
| 39 | 
            +
                  end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                  def parent_show_url(options = {})
         | 
| 42 | 
            +
                    polymorphic_url(parent_resources, options)
         | 
| 43 | 
            +
                  end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                  def parent_edit_url(options = {})
         | 
| 46 | 
            +
                    polymorphic_url(parent_resources.unshift(:edit), options)
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                  [:index, :new, :show, :edit].each do |action|
         | 
| 50 | 
            +
                    define_method(:"parent_#{action}_path") do |*args|
         | 
| 51 | 
            +
                      send(:"parent_#{action}_url", args.extract_options!.reverse_merge(:routing_type => :path))
         | 
| 52 | 
            +
                    end
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  def children_index_url(child, options = {})
         | 
| 56 | 
            +
                    raise_invalid_url_helper("children_index_url(#{:child.inspect})", resource) if resource.new_record?
         | 
| 57 | 
            +
                    polymorphic_url(resources << child.to_s.pluralize, options)
         | 
| 58 | 
            +
                  end
         | 
| 59 | 
            +
                  
         | 
| 60 | 
            +
                  def children_index_path(*args)
         | 
| 61 | 
            +
                    children_index_url(*args << args.extract_options!.reverse_merge(:routing_type => :path))
         | 
| 62 | 
            +
                  end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                  def children_new_url(child, options = {})
         | 
| 65 | 
            +
                    raise_invalid_url_helper("children_new_url(#{:child.inspect})", resource) if resource.new_record?
         | 
| 66 | 
            +
                    polymorphic_url(resources.unshift(:new) << child.to_s.singularize, options)
         | 
| 67 | 
            +
                  end
         | 
| 68 | 
            +
                  
         | 
| 69 | 
            +
                  def children_new_path(*args)
         | 
| 70 | 
            +
                    children_new_url(*args << args.extract_options!.reverse_merge(:routing_type => :path))
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  alias :resources_url :index_url
         | 
| 74 | 
            +
                  alias :resources_path :index_path
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  alias :resource_url :show_url
         | 
| 77 | 
            +
                  alias :resource_path :show_path
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                  alias :parent_resources_url :parent_index_url
         | 
| 80 | 
            +
                  alias :parent_resources_path :parent_index_path
         | 
| 81 | 
            +
             | 
| 82 | 
            +
                  alias :parent_resource_url :parent_show_url
         | 
| 83 | 
            +
                  alias :parent_resource_path :parent_show_path
         | 
| 84 | 
            +
                  
         | 
| 85 | 
            +
                  protected
         | 
| 86 | 
            +
                     
         | 
| 87 | 
            +
                    def raise_invalid_url_helper(method, resource)
         | 
| 88 | 
            +
                      raise "can't generate #{method} because the current resource (#{resource.inspect}) is a new record"
         | 
| 89 | 
            +
                    end
         | 
| 27 90 | 
             
                end
         | 
| 28 91 | 
             
              end
         | 
| 29 92 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: inherited_resources_helpers
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 27
         | 
| 5 5 | 
             
              prerelease: false
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 8 | 
             
              - 0
         | 
| 9 | 
            -
              -  | 
| 10 | 
            -
              version: 0.0. | 
| 9 | 
            +
              - 2
         | 
| 10 | 
            +
              version: 0.0.2
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Sven Fuchs
         |