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

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options: {}) ⇒ void

Parameters:



29
30
31
# File 'lib/convenient_service/config/entities/option_collection.rb', line 29

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

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



20
21
22
# File 'lib/convenient_service/config/entities/option_collection.rb', line 20

def options
  @options
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


137
138
139
140
141
142
143
# File 'lib/convenient_service/config/entities/option_collection.rb', line 137

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

  return false if options != other.options

  true
end

#[](name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


80
81
82
# File 'lib/convenient_service/config/entities/option_collection.rb', line 80

def [](name)
  options[name]
end

#any?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/convenient_service/config/entities/option_collection.rb', line 46

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

#disabled?(name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


72
73
74
# File 'lib/convenient_service/config/entities/option_collection.rb', line 72

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

#dupConvenientService::Config::Entities::OptionCollection



90
91
92
# File 'lib/convenient_service/config/entities/option_collection.rb', line 90

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

#enabled?(name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


62
63
64
65
66
# File 'lib/convenient_service/config/entities/option_collection.rb', line 62

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

  options[name].enabled?
end

#include?(name) ⇒ Boolean

Parameters:

  • name (Symbol)

Returns:

  • (Boolean)


54
55
56
# File 'lib/convenient_service/config/entities/option_collection.rb', line 54

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

#keysArray<Symbol>

Returns:

  • (Array<Symbol>)


36
37
38
# File 'lib/convenient_service/config/entities/option_collection.rb', line 36

def keys
  options.keys
end

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

Parameters:

  • other_options (Object)

    Can be any type.

Returns:



101
102
103
104
105
# File 'lib/convenient_service/config/entities/option_collection.rb', line 101

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:



127
128
129
130
131
# File 'lib/convenient_service/config/entities/option_collection.rb', line 127

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:



114
115
116
117
118
# File 'lib/convenient_service/config/entities/option_collection.rb', line 114

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

  self
end

#to_aArray<ConvenientService::Config::Entities::Option>



148
149
150
# File 'lib/convenient_service/config/entities/option_collection.rb', line 148

def to_a
  options.values
end

#to_hHash{Symbol => ConvenientService::Config::Entities::Option}

Returns:



155
156
157
# File 'lib/convenient_service/config/entities/option_collection.rb', line 155

def to_h
  options
end