Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
serradura committed Nov 7, 2023
1 parent c0f00e3 commit eea648a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
31 changes: 25 additions & 6 deletions lib/bcdd/result/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ class BCDD::Result
class Config
include Singleton

ADDON = Switcher.factory(
options: {
continue: %w[
BCDD::Result
BCDD::Result::Context
BCDD::Result::Expectations
BCDD::Result::Context::Expectations
]
}
)

CONSTANT_ALIAS = Switcher.factory(
options: ConstantAlias::OPTIONS,
listener: ConstantAlias::Listener
Expand All @@ -24,32 +35,40 @@ class Config
}
)

attr_reader :constant_alias, :pattern_matching
attr_reader :addon, :constant_alias, :pattern_matching

def initialize
@addon = ADDON.call
@constant_alias = CONSTANT_ALIAS.call
@pattern_matching = PATTERN_MATCHING.call
end

def freeze
addon.freeze
constant_alias.freeze
pattern_matching.freeze

super
end

def self.freeze; instance.freeze; end

def self.addon; instance.addon; end
def self.constant_alias; instance.constant_alias; end
def self.pattern_matching; instance.pattern_matching; end

def self.options
%i[constant_alias pattern_matching]
def self.options(exclude: [])
options = {}

options[:addon] = addon unless exclude.include?(:addon)
options[:constant_alias] = constant_alias unless exclude.include?(:constant_alias)
options[:pattern_matching] = pattern_matching unless exclude.include?(:pattern_matching)

options
end

def self.inspect
"#<#{name} options=#{options.inspect}>"
"#<#{name} options=#{options.keys.inspect}>"
end

private_class_method :instance
end
end
7 changes: 6 additions & 1 deletion sig/bcdd/result.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -481,9 +481,11 @@ end
class BCDD::Result::Config
include Singleton

ADDON: Proc
CONSTANT_ALIAS: Proc
PATTERN_MATCHING: Proc

attr_reader addon: BCDD::Result::Config::Switcher
attr_reader constant_alias: BCDD::Result::Config::Switcher
attr_reader pattern_matching: BCDD::Result::Config::Switcher

Expand All @@ -494,9 +496,12 @@ class BCDD::Result::Config
def freeze: -> BCDD::Result::Config

def self.freeze: -> BCDD::Result::Config

def self.addon: -> BCDD::Result::Config::Switcher
def self.constant_alias: -> BCDD::Result::Config::Switcher
def self.pattern_matching: -> BCDD::Result::Config::Switcher
def self.options: -> Array[Symbol]

def self.options: (?exclude: Array[Symbol]) -> Hash[Symbol, BCDD::Result::Config::Switcher]
end

class BCDD::Result::Config::Switcher
Expand Down

0 comments on commit eea648a

Please sign in to comment.