Class: StateMate::Adapters::File
- Inherits:
-
Object
- Object
- StateMate::Adapters::File
- Defined in:
- lib/state_mate/adapters/file.rb
Overview
Abstract base class for adapters whose data is stored in a single file.
Class Method Summary collapse
-
.parse_key(key, key_sep = StateMate::Adapters::DEFAULT_KEY_SEP) ⇒ Array<String, Array<String>>
pure.
Instance Method Summary collapse
-
#initialize ⇒ File
constructor
Instantiate a new
StateMate::Adapters::File
. -
#parse(file_contents) ⇒ Hash
abstract
Parse file contents into state structure.
- #read(key, **options) ⇒ return_type
Constructor Details
#initialize ⇒ File
Instantiate a new StateMate::Adapters::File
.
107 108 109 |
# File 'lib/state_mate/adapters/file.rb', line 107 def initialize end |
Class Method Details
.parse_key(key, key_sep = StateMate::Adapters::DEFAULT_KEY_SEP) ⇒ Array<String, Array<String>>
pure
Parses a key into path segments, the first of which should be the file path.
Checks that there is at least one resulting segment and that none of the segments are empty.
If key
is an array, assumes it's already split, and just checks that
the segments meet the above criteria, allowing key segments that contain
the key separator (which defaults to the
DEFAULT_KEY_SEP :
).
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/state_mate/adapters/file.rb', line 68 def self.parse_key key, key_sep = StateMate::Adapters::DEFAULT_KEY_SEP strings = case key when Array key when String key.split key_sep else raise TypeError, "key must be string or array, not #{ key.inspect }" end # case # make sure there is at least one element if strings.empty? raise ArgumentError, "key parsed into empty list: #{ key.inspect }" end # check for non-strings, empty domain or key segments strings.each do |string| if !string.is_a?(String) || string.empty? raise ArgumentError.new NRSER.squish <<-END all key segments must be non-empty, found #{ string.inspect } in key #{ key.inspect }. END end end strings end |
Instance Method Details
#parse(file_contents) ⇒ Hash
This method is abstract.
Parse file contents into state structure.
126 127 128 |
# File 'lib/state_mate/adapters/file.rb', line 126 def parse file_contents raise NRSER::AbstractMethodError.new self, __method__ end |
#read(key, **options) ⇒ return_type
TODO:
Document read method.
Returns @todo Document return value.
140 141 142 |
# File 'lib/state_mate/adapters/file.rb', line 140 def read key, ** end |