Class: Textus::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/store.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root) ⇒ Store

Returns a new instance of Store.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/textus/store.rb', line 31

def initialize(root)
  @root       = File.expand_path(root)
  @manifest   = Manifest.load(@root)
  @schemas    = Schemas.new(File.join(@root, "schemas"))
  @file_store = Infra::Storage::FileStore.new
  @audit_log  = Infra::AuditLog.new(
    @root,
    max_size: @manifest.data.audit_config[:max_size],
    keep: @manifest.data.audit_config[:keep],
  )
  @events = Hooks::EventBus.new
  @rpc = Hooks::RpcRegistry.new
  Infra::AuditSubscriber.new(@audit_log).attach(@events)
  Hooks::Builtin.register_all(events: @events, rpc: @rpc)
  Hooks::Loader.new(events: @events, rpc: @rpc).load_dir(File.join(@root, "hooks"))
  sess = Session.for(self, role: Role::DEFAULT)
  @events.publish(:store_loaded, ctx: sess.hook_context)
end

Instance Attribute Details

#audit_logObject (readonly)

Returns the value of attribute audit_log.



5
6
7
# File 'lib/textus/store.rb', line 5

def audit_log
  @audit_log
end

#eventsObject (readonly)

Returns the value of attribute events.



5
6
7
# File 'lib/textus/store.rb', line 5

def events
  @events
end

#file_storeObject (readonly)

Returns the value of attribute file_store.



5
6
7
# File 'lib/textus/store.rb', line 5

def file_store
  @file_store
end

#manifestObject (readonly)

Returns the value of attribute manifest.



5
6
7
# File 'lib/textus/store.rb', line 5

def manifest
  @manifest
end

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/textus/store.rb', line 5

def root
  @root
end

#rpcObject (readonly)

Returns the value of attribute rpc.



5
6
7
# File 'lib/textus/store.rb', line 5

def rpc
  @rpc
end

#schemasObject (readonly)

Returns the value of attribute schemas.



5
6
7
# File 'lib/textus/store.rb', line 5

def schemas
  @schemas
end

Class Method Details

.discover(start_dir = Dir.pwd, root: nil) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/textus/store.rb', line 7

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

Instance Method Details

#session(role: Role::DEFAULT, correlation_id: nil, dry_run: false) ⇒ Object



50
51
52
# File 'lib/textus/store.rb', line 50

def session(role: Role::DEFAULT, correlation_id: nil, dry_run: false)
  Session.for(self, role: role, correlation_id: correlation_id, dry_run: dry_run)
end