Sha256: b2ea55d283ae79ac1ebf408a76db24b4e684a1b3880b245918211d9429d51cdc

Contents?: true

Size: 1.29 KB

Versions: 83

Compression:

Stored size: 1.29 KB

Contents

class Jets::Router
  class MethodCreator
    include Util

    def initialize(options, scope)
      @options, @scope = options, scope
      @controller, @action = get_controller_action(@options)
    end

    def define_url_helper!
      return unless @options[:method] == :get

      if %w[index new show edit].include?(@action)
        create_method(@action)
      else
        create_method("generic")
      end
    end

    # Examples:
    #
    #   posts_path: path: 'posts'
    #   admin_posts_path: prefix: 'admin', path: 'posts'
    #   new_post_path
    #
    def create_method(action)
      # Code eventually does this:
      #
      #     code = Jets::Router::MethodCreator::Edit.new
      #     def_meth code.path_method
      #
      class_name = "Jets::Router::MethodCreator::#{action.camelize}"
      klass = class_name.constantize # Index, Show, Edit, New
      code = klass.new(@options, @scope, @controller)

      def_meth(code.path_method) if code.path_method
      def_meth(code.url_method) if code.url_method
    end

    def create_root_helper
      code = Jets::Router::MethodCreator::Root.new(@options, @scope, @controller)
      def_meth(code.path_method)
      def_meth(code.url_method)
    end

    def def_meth(str)
      Jets::Router::Helpers::NamedRoutesHelper.class_eval(str)
    end
  end
end

Version data entries

83 entries across 83 versions & 2 rubygems

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