Sha256: 0cfa1634f68e059ac9a034bcc2a4f00f7eb9bf31a5f08a03eb7afd3b4231fd79

Contents?: true

Size: 961 Bytes

Versions: 109

Compression:

Stored size: 961 Bytes

Contents

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

module Graphql
  module Generators
    # Generate an enum type by name, with the given values.
    # To add a `value:` option, add another value after a `:`.
    #
    # ```
    # rails g graphql:enum ProgrammingLanguage RUBY PYTHON PERL PERL6:"PERL"
    # ```
    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

109 entries across 109 versions & 2 rubygems

Version Path
graphql-1.11.12 lib/generators/graphql/enum_generator.rb
graphql-1.11.11 lib/generators/graphql/enum_generator.rb
graphql-1.12.25 lib/generators/graphql/enum_generator.rb
graphql_cody-1.13.0 lib/generators/graphql/enum_generator.rb
graphql-1.12.24 lib/generators/graphql/enum_generator.rb
graphql-1.13.6 lib/generators/graphql/enum_generator.rb
graphql-1.13.5 lib/generators/graphql/enum_generator.rb
graphql-1.13.4 lib/generators/graphql/enum_generator.rb
graphql-1.13.3 lib/generators/graphql/enum_generator.rb
graphql-1.12.23 lib/generators/graphql/enum_generator.rb
graphql-1.13.2 lib/generators/graphql/enum_generator.rb
graphql-1.13.1 lib/generators/graphql/enum_generator.rb
graphql-1.12.22 lib/generators/graphql/enum_generator.rb
graphql-1.13.0 lib/generators/graphql/enum_generator.rb
graphql-1.12.21 lib/generators/graphql/enum_generator.rb
graphql-1.12.20 lib/generators/graphql/enum_generator.rb
graphql-1.12.19 lib/generators/graphql/enum_generator.rb
graphql-1.11.10 lib/generators/graphql/enum_generator.rb
graphql-1.12.18 lib/generators/graphql/enum_generator.rb
graphql-1.11.9 lib/generators/graphql/enum_generator.rb