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
# 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 = Ports::Storage::FileStore.new
  @audit_log  = Ports::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
  Ports::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"))
  @events.publish(:store_loaded, ctx: Hooks::Context.new(scope: as(Role::DEFAULT)))
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

#as(role, dry_run: false, correlation_id: nil) ⇒ Object



53
54
55
# File 'lib/textus/store.rb', line 53

def as(role, dry_run: false, correlation_id: nil)
  RoleScope.new(container: container, role: role, dry_run: dry_run, correlation_id: correlation_id)
end

#containerObject



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

def container
  @container ||= Textus::Container.from_store(self)
end