Class: Lagoon::Options

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Enumerable[[Symbol,
Defined in:
lib/lagoon/options.rb,
sig/lagoon.rbs

Constant Summary collapse

COMMON_KEYS =

Returns:

  • (Array[Symbol])
%i[output verbose strict eager_load].freeze
KEYS =

Returns:

  • (Hash[Symbol, Array[Symbol]])
{
  model: COMMON_KEYS + %i[
    direction brief show_attributes show_methods include_inheritance exclude specify
    all_models show_belongs_to hide_through all_columns hide_magic hide_types
    include_framework_bases duplicate_sti_attributes
  ],
  controller: COMMON_KEYS + %i[
    direction brief include_inheritance exclude specify all_controllers hide_public
    hide_protected hide_private include_framework_bases
  ],
  er: COMMON_KEYS + %i[exclude specify connections internal_tables],
  controller_model: COMMON_KEYS + %i[
    direction exclude specify all_controllers show_actions helper_models
  ]
}.transform_values(&:freeze).freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, raw_options = {}, config: Lagoon.configuration) ⇒ Options

Returns a new instance of Options.

Parameters:

  • kind (Symbol)
  • raw_options (options_hash) (defaults to: {})
  • config: (Configuration) (defaults to: Lagoon.configuration)


35
36
37
38
39
40
41
42
# File 'lib/lagoon/options.rb', line 35

def initialize(kind, raw_options = {}, config: Lagoon.configuration)
  @kind = kind.to_sym
  @config = config
  @raw = symbolize_keys(raw_options)
  validate_keys!
  @values = normalize.freeze
  freeze
end

Instance Attribute Details

#kindSymbol (readonly)

Returns the value of attribute kind.

Returns:

  • (Symbol)


24
25
26
# File 'lib/lagoon/options.rb', line 24

def kind
  @kind
end

Class Method Details

.allowed_keys(kind) ⇒ Array[Symbol]

Parameters:

  • kind (Symbol)

Returns:

  • (Array[Symbol])


31
32
33
# File 'lib/lagoon/options.rb', line 31

def self.allowed_keys(kind)
  KEYS.fetch(kind)
end

.for(kind, raw_options = nil, config: Lagoon.configuration, **keyword_options) ⇒ Options

Parameters:

  • kind (Symbol)
  • raw_options (options_hash, nil) (defaults to: nil)
  • config: (Configuration) (defaults to: Lagoon.configuration)
  • keyword_options (Object)

Returns:



26
27
28
29
# File 'lib/lagoon/options.rb', line 26

def self.for(kind, raw_options = nil, config: Lagoon.configuration, **keyword_options)
  options = (raw_options || {}).to_h.merge(keyword_options)
  new(kind, options, config: config)
end

Instance Method Details

#[](key) ⇒ Object

Parameters:

  • key (option_key)

Returns:

  • (Object)


44
45
46
# File 'lib/lagoon/options.rb', line 44

def [](key)
  @values[key.to_sym]
end

#each {|arg0| ... } ⇒ Options

Yields:

Yield Parameters:

  • arg0 ([Symbol, untyped])

Yield Returns:

  • (void)

Returns:



56
57
58
# File 'lib/lagoon/options.rb', line 56

def each(&)
  @values.each(&)
end

#fetch(key, defaults) ⇒ Object #fetch(key, defaults) ⇒ Object

Overloads:

  • #fetch(key, defaults) ⇒ Object

    Parameters:

    • key (option_key)
    • defaults (Object)

    Returns:

    • (Object)
  • #fetch(key, defaults) ⇒ Object

    Parameters:

    • key (option_key)
    • defaults (Object)

    Returns:

    • (Object)

Yields:

Yield Parameters:

  • arg0 (Symbol)

Yield Returns:

  • (Object)


48
49
50
# File 'lib/lagoon/options.rb', line 48

def fetch(key, *defaults, &)
  @values.fetch(key.to_sym, *defaults, &)
end

#key?(key) ⇒ Boolean

Parameters:

  • key (option_key)

Returns:

  • (Boolean)


52
53
54
# File 'lib/lagoon/options.rb', line 52

def key?(key)
  @values.key?(key.to_sym)
end

#to_hHash[Symbol, untyped]

Returns:

  • (Hash[Symbol, untyped])


60
61
62
# File 'lib/lagoon/options.rb', line 60

def to_h
  @values.dup
end