Class: Hexx::Storage::Base

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/hexx/storage/base.rb

Overview

The container to load and store ROM settings

Examples:

storage = Storage::Base.new

storage.root = "path_to_application"
storage.load "config/initializers/my_gem.rb", env: :test
storage.migrations = "path_to_my_gem/db/migrate"

ROM.setup storage.settings

Direct Known Subclasses

Repositories::SQL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



23
24
25
# File 'lib/hexx/storage/base.rb', line 23

def initialize
  super({})
end

Instance Attribute Details

#rootString?

Returns the root of the application to #load settings from

Returns:

  • (String, nil)


43
44
45
# File 'lib/hexx/storage/base.rb', line 43

def root
  @root
end

Instance Method Details

#[](repository) ⇒ Hexx::Storage::Repositories::Memory

Returns the object that stores settings for some repository

Parameters:

  • repository (Symbol)

Returns:



# File 'lib/hexx/storage/base.rb', line 32

#keysArray<Symbol>

Returns the list of names for ROM repositories’

Returns:

  • (Array<Symbol>)


# File 'lib/hexx/storage/base.rb', line 27

#load(file, env:) ⇒ undefined

Loads ROM settings from given yml file for given environment

Parameters:

  • file (#to_s)

    The path relative to the #root

  • [#to_sym] (Hash)

    a customizable set of options

Returns:

  • (undefined)

Raises:

  • (NotImplementedError)

    if the #root hasn’t been defined yet



63
64
65
66
# File 'lib/hexx/storage/base.rb', line 63

def load(file, env:)
  check_root # need to know where to load the file from
  setup [root, file].to_path.from_file.from_yaml.sub(env)
end

#settingsHash

Returns settings as an argument for ROM.setup

Returns:

  • (Hash)

Raises:

  • (NotImplementedError)

    if the settings haven’t been set



85
86
87
88
# File 'lib/hexx/storage/base.rb', line 85

def settings
  check_storage
  __getobj__.wrap(&:settings)
end

#setup(hash) ⇒ undefined

Sets ROM settings from hash

Parameters:

  • hash (Hash)

Returns:

  • (undefined)

Raises:

  • (NotImplementedError)

    if the #root hasn’t been defined yet



75
76
77
78
# File 'lib/hexx/storage/base.rb', line 75

def setup(hash)
  check_root # need to know where to place logs to
  __setobj__ hash.normalize.wrap(&new_repo)
end