Module: Locd::Config::Types
- Extended by:
- tt::Factory
- Defined in:
- lib/locd/config/types.rb
Overview
Definitions
Type Factory Class Methods collapse
-
.ConfigPath(**options) ⇒ Type
A path we accept in the config.
- .PackagePath(**options) ⇒ Type
Class Method Summary collapse
-
.by_key ⇒ Hamster::Hash
A tree representing config key paths to the types they need to be.
-
.for_key(*key) ⇒ NRSER::Types::Type?
Dig in to BY_KEY and see if it has a type for a
key.
Class Method Details
.by_key ⇒ Hamster::Hash
A tree representing config key paths to the types they need to be.
Computed on first call and cached after that as it needs the type factories below.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/locd/config/types.rb', line 60 def self.by_key # Got sick of writing "Hamster::Hash[...]"... "I8" <=> "Immutable" @by_key ||= I8[ 'home' => self.ConfigPath, 'bin' => ( t.When( 'locd' ) | self.ConfigPath ), 'log' => I8[ 'dir' => self.ConfigPath, ], 'tmp' => I8[ 'dir' => self.ConfigPath, ], 'cli' => I8[ 'log' => I8[ 'application' => t.non_empty_str, 'level' => NRSER::Log::Types.level?, 'dest' => ( NRSER::Log::Types.stdio | self.ConfigPath ), ], 'bash_comp' => I8[ 'log' => I8[ 'level' => NRSER::Log::Types.level, 'dest' => self.ConfigPath, ], ] ] ] end |
.ConfigPath(**options) ⇒ Type
A path we accept in the config. One of:
A PackagePath that starts with
//..., denoting it's relative to the package root.A NRSER::Types.HomePath that starts with
~, meaning it's relative to a user's home directory.An NRSER::Types.AbsPath
151 152 153 154 155 156 157 158 |
# File 'lib/locd/config/types.rb', line 151 def_type :ConfigPath, &->( ** ) do t.Union \ self.PackagePath, t.HomePath, t.AbsPath, ** end |
.for_key(*key) ⇒ NRSER::Types::Type?
Dig in to BY_KEY and see if it has a type for a key.
98 99 100 |
# File 'lib/locd/config/types.rb', line 98 def self.for_key *key by_key.dig *Locd::Config.key_path_for( *key ) end |
.PackagePath(**options) ⇒ Type
TODO:
Document PackagePath type factory.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/locd/config/types.rb', line 114 def_type :PackagePath, from_s: ->( s ) { Locd::ROOT.join( s[2..-1] ) if s.start_with? '//' }, &->( ** ) do t.Intersection \ t.Path, t.Where { |path| begin false == path. to_pn. relative_path_from( Locd::ROOT ). start_with?( '..' + File::SEPARATOR ) rescue StandardError => error false end }, ** end |