Sha256: 2533e9e8bdae20e5e3d73fb2b340224c9ca8309810aa6e481dffdfe25bbe962f

Contents?: true

Size: 886 Bytes

Versions: 28

Compression:

Stored size: 886 Bytes

Contents

# frozen_string_literal: true
require 'generators/graphql/type_generator'

module Graphql
  module Generators
    # Generate an interface type by name,
    # with the specified fields.
    #
    # ```
    # rails g graphql:interface NamedEntityType name:String!
    # ```
    class EnumGenerator < TypeGeneratorBase
      desc "Create a GraphQL::EnumType with the given name and values"
      source_root File.expand_path('../templates', __FILE__)

      argument :values,
        type: :array,
        default: [],
        banner: "value{:ruby_value} value{:ruby_value} ...",
        desc: "Values for this enum (if present, ruby_value will be inserted verbatim)"

      def create_type_file
        template "enum.erb", "app/graphql/types/#{type_file_name}.rb"
      end

      private

      def prepared_values
        values.map { |v| v.split(":", 2) }
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
graphql-1.7.4 lib/generators/graphql/enum_generator.rb
graphql-1.7.3 lib/generators/graphql/enum_generator.rb
graphql-1.7.2 lib/generators/graphql/enum_generator.rb
graphql-1.7.1 lib/generators/graphql/enum_generator.rb
graphql-1.7.0 lib/generators/graphql/enum_generator.rb
graphql-1.6.8 lib/generators/graphql/enum_generator.rb
graphql-1.6.7 lib/generators/graphql/enum_generator.rb
graphql-1.6.6 lib/generators/graphql/enum_generator.rb
graphql-1.6.5 lib/generators/graphql/enum_generator.rb
graphql-1.6.4 lib/generators/graphql/enum_generator.rb
graphql-1.5.15 lib/generators/graphql/enum_generator.rb
graphql-1.6.3 lib/generators/graphql/enum_generator.rb
graphql-1.6.2 lib/generators/graphql/enum_generator.rb
graphql-1.6.1 lib/generators/graphql/enum_generator.rb
graphql-1.6.0 lib/generators/graphql/enum_generator.rb
graphql-1.5.14 lib/generators/graphql/enum_generator.rb
graphql-1.5.13 lib/generators/graphql/enum_generator.rb
graphql-1.5.7.1 lib/generators/graphql/enum_generator.rb
graphql-1.5.12 lib/generators/graphql/enum_generator.rb
graphql-1.5.11 lib/generators/graphql/enum_generator.rb