Module: Nero

Extended by:
Resolvable
Defined in:
lib/nero.rb,
lib/nero/util.rb,
lib/nero/railtie.rb,
lib/nero/version.rb

Overview

TODO fail on unknown tag TODO show missing env's at once TODO raise when missing arg(s) for tag

Defined Under Namespace

Modules: DigExt, Resolvable, Util Classes: BaseTag, Config, Configuration, EnvTag, Error, PathRootTag

Constant Summary collapse

VERSION =

NOTE this is written upon release via: $ rake gem:build[version=0.3.0]

"0.6.0.pre"

Class Method Summary collapse

Methods included from Resolvable

deep_resolve, resolve_nested!, try_resolve

Class Method Details

.config_for(file, root: nil, env: nil, **yaml_options) ⇒ Nero::Config (when the data is a Hash)

Convenience wrapper for load_file that works like Rails.application.config_for. The file-argument is expanded like so (configuration.config_dir / "#{file}.yml").expand_path.

Examples:

Nero.config_for(:app, env: Rails.env) #=> {...}

Parameters:

  • file (Symbol, String, Pathname)

    Symbol or String are expanded as shown above. A Pathname is used as-is.

  • env (Symbol, String) (defaults to: nil)

    return the value of this root key.

  • root (Symbol, String) (defaults to: nil)

    return the value of this root key.

  • resolve (Boolean)

    (for debug purposes) not resolving would leave the Nero-tags as-is.

  • extra_permitted_classes (Array<ClassName>)

    classes that are added to the default permitted_classes and passed to YAML.load.

  • yaml_options (Hash)

    options passed to YAML.load_file.

Returns:

See Also:



492
493
494
495
496
# File 'lib/nero.rb', line 492

def self.config_for(file, root: nil, env: nil, **yaml_options)
  root ||= env

  load_file(resolve_file(file), root:, **yaml_options)
end

.configurationObject



120
121
122
# File 'lib/nero.rb', line 120

def self.configuration
  @configuration ||= Configuration.new
end

.configureObject



131
132
133
134
135
# File 'lib/nero.rb', line 131

def self.configure
  yield configuration if block_given?
ensure
  add_tags!
end

.load(yaml, root: nil, resolve: true, **yaml_options) ⇒ Nero::Config (when the data is a Hash)

Like YAML.load with extra options.

Examples:

Nero.load(<<~YAML, extra_permitted_classes: [Time])
  home: !env HOME,
  created_at: 2010-02-11 11:02:57
  project_root: !path/git_root
YAML
#=> {
#    home: "/Users/gert",
#    created_at: 2010-02-11 12:02:57 +0100,
#    project_root: #<Pathname:/Users/gert/projects/nero>
#  }

Parameters:

  • root (Symbol, String) (defaults to: nil)

    return the value of this root key.

  • resolve (Boolean) (defaults to: true)

    (for debug purposes) not resolving would leave the Nero-tags as-is.

  • extra_permitted_classes (Array<ClassName>)

    classes that are added to the default permitted_classes and passed to YAML.load.

  • yaml_options (Hash)

    options passed to YAML.load.

Returns:



466
467
468
# File 'lib/nero.rb', line 466

def self.load(yaml, root: nil, resolve: true, **yaml_options)
  process_yaml(yaml_load(yaml, yaml_options(yaml_options)), root:, resolve:)
end

.load_config(file, root: nil, env: nil, resolve: true) ⇒ Object

Deprecated.

Use load_file or config_for instead.



499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'lib/nero.rb', line 499

def self.load_config(file, root: nil, env: nil, resolve: true)
  warn "[DEPRECATION] `load_config` is deprecated. Use `load_file` or `config_for` instead."
  root ||= env
  add_tags!

  config_file = resolve_file(file)

  if config_file.exist?
    process_yaml(yaml_load_file(config_file, yaml_options), root:, config_file:, resolve:)
  else
    raise "Can't find file #{config_file}"
  end
end

.load_file(file, root: nil, resolve: true, **yaml_options) ⇒ Nero::Config (when the YAML-data is a Hash)

Like YAML.load_file. See load for options.

Returns:



472
473
474
475
# File 'lib/nero.rb', line 472

def self.load_file(file, root: nil, resolve: true, **yaml_options)
  config_file = (file.is_a?(Pathname) ? file : Pathname.new(file)).expand_path
  process_yaml(yaml_load_file(config_file, yaml_options(yaml_options)), root:, config_file:, resolve:)
end

.reset_configuration!Object



419
420
421
422
423
424
425
426
427
428
# File 'lib/nero.rb', line 419

def self.reset_configuration!
  @configuration = nil

  configure do |config|
    config.config_dir = Pathname.new("config").expand_path
  end

  add_default_tags!
  add_tags!
end