Sha256: 7417be58675bfaeba30fcf0dd6b64a701430cdec1b81185003b662ac0308cc5c

Contents?: true

Size: 817 Bytes

Versions: 1

Compression:

Stored size: 817 Bytes

Contents

# frozen_string_literal: true

require_relative '../controller/controller_function'

module GraphqlRails
  class Router
    # Generic class for any type graphql action. Should not be used directly
    class Route
      attr_reader :name, :module_name, :on, :relative_path

      def initialize(name, to:, on:, **options)
        @name = name.to_s.camelize(:lower)
        @module_name = options[:module].to_s
        @relative_path = to
        @on = on.to_sym
      end

      def path
        return relative_path if module_name.empty?
        [module_name, relative_path].join('/')
      end

      def collection?
        on == :collection
      end

      def member?
        on == :member
      end

      def options
        { function: Controller::ControllerFunction.build(path) }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql_rails-0.2.1 lib/graphql_rails/router/route.rb