Class: I18nContextGenerator::Config::Schema::Definition

Inherits:
Data
  • Object
show all
Defined in:
lib/i18n_context_generator/config/schema.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, default:, values:, yaml_path:, cli:) ⇒ Definition

Returns a new instance of Definition.



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/i18n_context_generator/config/schema.rb', line 29

def initialize(name:, type:, default:, values:, yaml_path:, cli:)
  default.freeze if default.respond_to?(:freeze)
  super(
    name: name,
    type: type,
    default: default,
    values: values&.freeze,
    yaml_path: yaml_path&.freeze,
    cli: cli&.freeze
  )
end

Instance Attribute Details

#cliObject (readonly)

Returns the value of attribute cli

Returns:

  • (Object)

    the current value of cli



28
29
30
# File 'lib/i18n_context_generator/config/schema.rb', line 28

def cli
  @cli
end

#defaultObject (readonly)

Returns the value of attribute default

Returns:

  • (Object)

    the current value of default



28
29
30
# File 'lib/i18n_context_generator/config/schema.rb', line 28

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



28
29
30
# File 'lib/i18n_context_generator/config/schema.rb', line 28

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



28
29
30
# File 'lib/i18n_context_generator/config/schema.rb', line 28

def type
  @type
end

#valuesObject (readonly)

Returns the value of attribute values

Returns:

  • (Object)

    the current value of values



28
29
30
# File 'lib/i18n_context_generator/config/schema.rb', line 28

def values
  @values
end

#yaml_pathObject (readonly)

Returns the value of attribute yaml_path

Returns:

  • (Object)

    the current value of yaml_path



28
29
30
# File 'lib/i18n_context_generator/config/schema.rb', line 28

def yaml_path
  @yaml_path
end

Instance Method Details

#cli?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/i18n_context_generator/config/schema.rb', line 41

def cli?
  !cli.nil?
end

#cli_nameObject



45
46
47
# File 'lib/i18n_context_generator/config/schema.rb', line 45

def cli_name
  cli.fetch(:name, name)
end

#thor_optionsObject



49
50
51
52
53
54
55
56
# File 'lib/i18n_context_generator/config/schema.rb', line 49

def thor_options
  options = { desc: help_description }
  options[:aliases] = cli[:aliases] if cli[:aliases]
  options[:type] = cli.fetch(:type) { Schema.thor_type(type) }
  options[:enum] = values if values
  options[:repeatable] = true if cli[:repeatable]
  options
end