Sha256: 6ddb824fea8e6b2263a68e92930c06f353d86b5b5003ef0be17bf471acf3e433

Contents?: true

Size: 897 Bytes

Versions: 23

Compression:

Stored size: 897 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", "#{options[:directory]}/types/#{type_file_name}.rb"
      end

      private

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

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
graphql-1.8.1 lib/generators/graphql/enum_generator.rb
graphql-1.8.0 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre11 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre10 lib/generators/graphql/enum_generator.rb
graphql-1.7.14 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre9 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre8 lib/generators/graphql/enum_generator.rb
graphql-1.7.13 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre7 lib/generators/graphql/enum_generator.rb
graphql-1.7.12 lib/generators/graphql/enum_generator.rb
graphql-1.7.11 lib/generators/graphql/enum_generator.rb
graphql-1.7.10 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre6 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre5 lib/generators/graphql/enum_generator.rb
graphql-1.7.9 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre4 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre3 lib/generators/graphql/enum_generator.rb
graphql-1.7.8 lib/generators/graphql/enum_generator.rb
graphql-1.8.0.pre2 lib/generators/graphql/enum_generator.rb
graphql-1.7.7 lib/generators/graphql/enum_generator.rb