Class: ConvenientService::Config::Entities::OptionCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/config/entities/option_collection.rb

Overview

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options: {}) ⇒ void

Parameters:

Since:

  • 1.0.0



25
26
27
# File 'lib/convenient_service/config/entities/option_collection.rb', line 25

def initialize(options: {})
  @options = options
end

Instance Attribute Details

#options ⇒ Object (readonly)

Since:

  • 1.0.0



16
17
18
# File 'lib/convenient_service/config/entities/option_collection.rb', line 16

def options
  @options
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object) —

    Can be any type.

Returns:

  • (Boolean, nil)

Since:

  • 1.0.0



141
142
143
144
145
146
147
# File 'lib/convenient_service/config/entities/option_collection.rb', line 141

def ==(other)
  return unless other.instance_of?(self.class)

  return false if options != other.options

  true
end

#[](name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)

Since:

  • 1.0.0



84
85
86
# File 'lib/convenient_service/config/entities/option_collection.rb', line 84

def [](name)
  options[name]
end

#any? ⇒ Boolean

Returns:

  • (Boolean)

Since:

  • 1.0.0



42
43
44
# File 'lib/convenient_service/config/entities/option_collection.rb', line 42

def any?
  options.any? { |_name, option| option.enabled? }
end

#any_enabled?(*names) ⇒ Boolean

Parameters:

  • names (Array<Symbol>)

Returns:

  • (Boolean)

Since:

  • 1.0.0



68
69
70
# File 'lib/convenient_service/config/entities/option_collection.rb', line 68

def any_enabled?(*names)
  names.any? { |name| enabled?(name) }
end

#disabled?(name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)

Since:

  • 1.0.0



76
77
78
# File 'lib/convenient_service/config/entities/option_collection.rb', line 76

def disabled?(name)
  !enabled?(name)
end

#dup ⇒ ConvenientService::Config::Entities::OptionCollection



94
95
96
# File 'lib/convenient_service/config/entities/option_collection.rb', line 94

def dup
  self.class.new(options: options.dup)
end

#enabled?(name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)

Since:

  • 1.0.0



58
59
60
61
62
# File 'lib/convenient_service/config/entities/option_collection.rb', line 58

def enabled?(name)
  return false unless include?(name)

  options[name].enabled?
end

#include?(name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)

Since:

  • 1.0.0



50
51
52
# File 'lib/convenient_service/config/entities/option_collection.rb', line 50

def include?(name)
  options.has_key?(name)
end

#keys ⇒ Array<Symbol>

Returns:

  • (Array<Symbol>)

Since:

  • 1.0.0



32
33
34
# File 'lib/convenient_service/config/entities/option_collection.rb', line 32

def keys
  options.keys
end

#merge(other_options) ⇒ ConvenientService::Config::Entities::OptionCollection

Parameters:

  • other_options (Object) —

    Can be any type.

Returns:

Since:

  • 1.0.0



105
106
107
108
109
# File 'lib/convenient_service/config/entities/option_collection.rb', line 105

def merge(other_options)
  options.merge!(Commands::NormalizeOptions[options: other_options].to_h)

  self
end

#replace(other_options) ⇒ ConvenientService::Config::Entities::OptionCollection

Parameters:

  • other_options (Object) —

    Can be any type.

Returns:

Since:

  • 1.0.0



131
132
133
134
135
# File 'lib/convenient_service/config/entities/option_collection.rb', line 131

def replace(other_options)
  options.replace(Commands::NormalizeOptions[options: other_options].to_h)

  self
end

#subtract(other_options) ⇒ ConvenientService::Config::Entities::OptionCollection

Parameters:

  • other_options (Object) —

    Can be any type.

Returns:

Since:

  • 1.0.0



118
119
120
121
122
# File 'lib/convenient_service/config/entities/option_collection.rb', line 118

def subtract(other_options)
  Commands::NormalizeOptions[options: other_options].to_h.each_key { |name| options.delete(name) }

  self
end

#to_a ⇒ Array<ConvenientService::Config::Entities::Option>

Returns:

Since:

  • 1.0.0



152
153
154
# File 'lib/convenient_service/config/entities/option_collection.rb', line 152

def to_a
  options.values
end

#to_h ⇒ Hash{Symbol => ConvenientService::Config::Entities::Option}

Returns:

Since:

  • 1.0.0



159
160
161
# File 'lib/convenient_service/config/entities/option_collection.rb', line 159

def to_h
  options
end