Sha256: 3f5647c8607750c1d5121151fc45e2d3f0a064de4ebe324075320168708dd37d

Contents?: true

Size: 1.37 KB

Versions: 79

Compression:

Stored size: 1.37 KB

Contents

class Jets::Router::MethodCreator
  class Index < Code
    def meth_name
      # TODO: figure out how to improve this and make easier to follow.
      #
      # Example 1:
      #
      #     resources :users, only: [] do
      #       resources :posts, only: :index
      #     end
      #
      # Results in:
      #
      #     full_as: user_posts
      #     method_name_leaf: nil
      #
      # Example 2:
      #
      #     resources :users, only: [] do
      #       get "posts", to: "posts#index"
      #     end
      #
      # Results in:
      #
      #     full_as: users
      #     method_name_leaf: posts
      #
      # This is because using resources contains all the info we need in parent scopes.
      # The scope.full_as already has the desired meth_name.
      #
      # However, when using the simple create_route methods like get, the parent scope does not contain
      # all the info we need. In this tricky case, the method_name_leaf is set.
      # We then have to reconstruct the meth_name.
      #

      if method_name_leaf
        path_items = @path.to_s.split('/')
        if path_items.size == 1
          join(singularize(full_as), method_name_leaf) # reconstruct
        else
          nil # fallback: do not define url method
        end
      else  # comes from resources
        join(full_as) # construct entirely from scope info
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 2 rubygems

Version Path
jets-4.0.12 lib/jets/router/method_creator/index.rb
jets-4.0.11 lib/jets/router/method_creator/index.rb
jets-4.0.10 lib/jets/router/method_creator/index.rb
jets-4.0.9 lib/jets/router/method_creator/index.rb
jets-4.0.8 lib/jets/router/method_creator/index.rb
jets-4.0.7 lib/jets/router/method_creator/index.rb
jets-4.0.6 lib/jets/router/method_creator/index.rb
jets-4.0.5 lib/jets/router/method_creator/index.rb
jets-4.0.4 lib/jets/router/method_creator/index.rb
jets-4.0.3 lib/jets/router/method_creator/index.rb
jets-4.0.2 lib/jets/router/method_creator/index.rb
jets-4.0.1 lib/jets/router/method_creator/index.rb
jets-4.0.0 lib/jets/router/method_creator/index.rb
jets-3.2.2 lib/jets/router/method_creator/index.rb
jets-3.2.1 lib/jets/router/method_creator/index.rb
jets.benforeva-3.0.17.pre.mount.pre.fix lib/jets/router/method_creator/index.rb
jets-3.2.0 lib/jets/router/method_creator/index.rb
jets-3.1.5 lib/jets/router/method_creator/index.rb
jets-3.1.4 lib/jets/router/method_creator/index.rb
jets-3.1.3 lib/jets/router/method_creator/index.rb