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
# 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)
  @bus = Hooks::Bus.new
  Infra::AuditSubscriber.new(@audit_log).attach(@bus)
  Hooks::Builtin.register_all(@bus)
  Hooks::Loader.new(bus: @bus).load_dir(File.join(@root, "hooks"))
  ops = Operations.for(self, role: Role::DEFAULT)
  @bus.publish(:store_loaded, ctx: ops.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

#busObject (readonly)

Returns the value of attribute bus.



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

def bus
  @bus
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

#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