Class: RailsAppGenerator::BuildOption

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_app_generator/options/build_option.rb

Overview

Option for the rails generator

This class maps closely (but not exactly) to Thor’s options The pattern is not exactly the same, it is easy to map the options you need from other generators such as: railties/lib/rails/generators/app_base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, **args) ⇒ BuildOption

Returns a new instance of BuildOption.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
21
# File 'lib/rails_app_generator/options/build_option.rb', line 12

def initialize(name, **args)
  @name = name
  @description = args[:description] || ''
  @type = args[:type] || :string
  @required = args.fetch(:required, false)
  @default = args[:default] || sane_default
  @mapper = args[:mapper] || sane_mapper

  raise ArgumentError, ':required should not be nil' if @required.nil?
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



10
11
12
# File 'lib/rails_app_generator/options/build_option.rb', line 10

def default
  @default
end

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/rails_app_generator/options/build_option.rb', line 10

def description
  @description
end

#mapperObject (readonly)

Returns the value of attribute mapper.



10
11
12
# File 'lib/rails_app_generator/options/build_option.rb', line 10

def mapper
  @mapper
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/rails_app_generator/options/build_option.rb', line 10

def name
  @name
end

#requiredObject (readonly)

Returns the value of attribute required.



10
11
12
# File 'lib/rails_app_generator/options/build_option.rb', line 10

def required
  @required
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/rails_app_generator/options/build_option.rb', line 10

def type
  @type
end

Instance Method Details

#cmd_option(value) ⇒ Object



23
# File 'lib/rails_app_generator/options/build_option.rb', line 23

def cmd_option(value); end

#to_hObject



25
26
27
28
29
30
31
32
33
# File 'lib/rails_app_generator/options/build_option.rb', line 25

def to_h
  {
    name: name,
    description: description,
    type: type,
    default: default,
    required: required
  }
end