Class: Textus::Store
- Inherits:
-
Object
show all
- Defined in:
- lib/textus/store.rb,
lib/textus/store/mover.rb,
lib/textus/store/reader.rb,
lib/textus/store/writer.rb,
lib/textus/store/audit_log.rb,
lib/textus/store/staleness.rb,
lib/textus/store/validator.rb
Defined Under Namespace
Classes: AuditLog, Mover, Reader, Staleness, Validator, Writer
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#accept(key, as: Role::DEFAULT) ⇒ Object
-
#audit_log ⇒ Object
-
#delete(key, if_etag: nil, as: Role::DEFAULT, suppress_events: false) ⇒ Object
rubocop:enable Metrics/ParameterLists.
-
#deps(key) ⇒ Object
-
#fire_event(event) ⇒ Object
-
#get(key, as: Textus::Role::DEFAULT) ⇒ Object
-
#initialize(root) ⇒ Store
constructor
-
#list ⇒ Object
-
#load_hooks ⇒ Object
-
#mv(old_key, new_key, as: Role::DEFAULT, dry_run: false, correlation_id: nil) ⇒ Object
Move an entry from old_key to new_key within the same zone.
-
#published ⇒ Object
-
#put(key, meta: nil, body: nil, content: nil, if_etag: nil, as: Role::DEFAULT, suppress_events: false) ⇒ Object
rubocop:disable Metrics/ParameterLists.
-
#rdeps(key) ⇒ Object
-
#reject ⇒ Object
-
#schema_envelope(key) ⇒ Object
-
#schema_for(name) ⇒ Object
-
#stale ⇒ Object
-
#uid(key) ⇒ Object
-
#validate_all ⇒ Object
-
#where(key) ⇒ Object
Constructor Details
#initialize(root) ⇒ Store
Returns a new instance of Store.
Instance Attribute Details
#bus ⇒ Object
Returns the value of attribute bus.
6
7
8
|
# File 'lib/textus/store.rb', line 6
def bus
@bus
end
|
#manifest ⇒ Object
Returns the value of attribute manifest.
6
7
8
|
# File 'lib/textus/store.rb', line 6
def manifest
@manifest
end
|
#reader ⇒ Object
Returns the value of attribute reader.
6
7
8
|
# File 'lib/textus/store.rb', line 6
def reader
@reader
end
|
#registry ⇒ Object
Returns the value of attribute registry.
6
7
8
|
# File 'lib/textus/store.rb', line 6
def registry
@registry
end
|
#root ⇒ Object
Returns the value of attribute root.
6
7
8
|
# File 'lib/textus/store.rb', line 6
def root
@root
end
|
#writer ⇒ Object
Returns the value of attribute writer.
6
7
8
|
# File 'lib/textus/store.rb', line 6
def writer
@writer
end
|
Class Method Details
.discover(start_dir = Dir.pwd, root: nil) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/textus/store.rb', line 15
def self.discover(start_dir = Dir.pwd, root: nil)
explicit = root || ENV.fetch("TEXTUS_ROOT", nil)
return discover_explicit(explicit) if explicit
dir = File.expand_path(start_dir)
loop do
candidate = File.join(dir, ".textus")
return new(candidate) if File.directory?(candidate) && File.exist?(File.join(candidate, "manifest.yaml"))
parent = File.dirname(dir)
break if parent == dir
dir = parent
end
raise IoError.new("no .textus directory found from #{start_dir}")
end
|
.mint_uid ⇒ Object
A Textus UID: 16 lowercase hex chars (SecureRandom.hex(8)). Not a UUID —short on purpose. Random enough for collision-never-in-practice within a single store.
11
12
13
|
# File 'lib/textus/store.rb', line 11
def self.mint_uid
SecureRandom.hex(8)
end
|
Instance Method Details
#accept(key, as: Role::DEFAULT) ⇒ Object
#audit_log ⇒ Object
132
133
134
|
# File 'lib/textus/store.rb', line 132
def audit_log
@audit_log ||= Store::AuditLog.new(@root)
end
|
#delete(key, if_etag: nil, as: Role::DEFAULT, suppress_events: false) ⇒ Object
rubocop:enable Metrics/ParameterLists
#deps(key) ⇒ Object
116
|
# File 'lib/textus/store.rb', line 116
def deps(key) = @reader.deps(key)
|
#fire_event(event) ⇒ Object
104
105
106
107
|
# File 'lib/textus/store.rb', line 104
def fire_event(event, **)
view = Textus::Application::Context.new(store: self, role: "human")
@bus.publish(event, store: view, **)
end
|
#get(key, as: Textus::Role::DEFAULT) ⇒ Object
#list ⇒ Object
87
|
# File 'lib/textus/store.rb', line 87
def list(**) = @reader.list(**)
|
#load_hooks ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/textus/store.rb', line 51
def load_hooks
Textus.with_registry(@registry) do
Hooks::Builtin.register_all
dir = File.join(@root, "hooks")
return unless File.directory?(dir)
Dir.glob(File.join(dir, "**/*.rb")).sort.each do |f| begin
load(f)
rescue StandardError, ScriptError => e
raise UsageError.new("failed loading hook #{File.basename(f)}: #{e.class}: #{e.message}")
end
end
end
end
|
#mv(old_key, new_key, as: Role::DEFAULT, dry_run: false, correlation_id: nil) ⇒ Object
Move an entry from old_key to new_key within the same zone. Preserves uid (minting one first if absent), validates both keys against the manifest, refuses to clobber, and writes one mv audit row.
127
128
129
130
|
# File 'lib/textus/store.rb', line 127
def mv(old_key, new_key, as: Role::DEFAULT, dry_run: false, correlation_id: nil)
Mover.new(store: self, reader: @reader, writer: @writer, manifest: @manifest, audit_log: audit_log)
.call(old_key, new_key, as: as, dry_run: dry_run, correlation_id: correlation_id)
end
|
#published ⇒ Object
118
|
# File 'lib/textus/store.rb', line 118
def published = @reader.published
|
#put(key, meta: nil, body: nil, content: nil, if_etag: nil, as: Role::DEFAULT, suppress_events: false) ⇒ Object
rubocop:disable Metrics/ParameterLists
91
92
93
94
95
96
|
# File 'lib/textus/store.rb', line 91
def put(key, meta: nil, body: nil, content: nil, if_etag: nil, as: Role::DEFAULT, suppress_events: false)
ctx = Textus::Composition.context(self, role: as)
Textus::Composition.writes_put(ctx).call(
key, meta: meta, body: body, content: content, if_etag: if_etag, suppress_events: suppress_events
)
end
|
#rdeps(key) ⇒ Object
117
|
# File 'lib/textus/store.rb', line 117
def rdeps(key) = @reader.rdeps(key)
|
#reject ⇒ Object
114
|
# File 'lib/textus/store.rb', line 114
def reject(...) = @writer.reject(...)
|
#schema_envelope(key) ⇒ Object
88
|
# File 'lib/textus/store.rb', line 88
def schema_envelope(key) = @reader.schema_envelope(key)
|
#schema_for(name) ⇒ Object
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/textus/store.rb', line 67
def schema_for(name)
return nil if name.nil?
@schemas[name] ||= begin
sp = File.join(@root, "schemas", "#{name}.yaml")
raise IoError.new("schema not found: #{sp}") unless File.exist?(sp)
Schema.load(sp)
end
end
|
#stale ⇒ Object
119
|
# File 'lib/textus/store.rb', line 119
def stale(**) = @reader.stale(**)
|
#uid(key) ⇒ Object
122
|
# File 'lib/textus/store.rb', line 122
def uid(key) = @reader.uid(key)
|
#validate_all ⇒ Object
120
|
# File 'lib/textus/store.rb', line 120
def validate_all = @reader.validate_all
|
#where(key) ⇒ Object
86
|
# File 'lib/textus/store.rb', line 86
def where(key) = @reader.where(key)
|