Module: Nero

Defined in:
lib/nero.rb,
lib/nero/ref.rb,
lib/nero/error.rb,
lib/nero/rails.rb,
lib/nero/ip_tag.rb,
lib/nero/parser.rb,
lib/nero/result.rb,
lib/nero/context.rb,
lib/nero/env_tag.rb,
lib/nero/railtie.rb,
lib/nero/ref_tag.rb,
lib/nero/version.rb,
lib/nero/visitor.rb,
lib/nero/base_tag.rb,
lib/nero/deferred.rb,
lib/nero/proc_tag.rb,
lib/nero/format_tag.rb,
lib/nero/root_path_tag.rb,
lib/nero/rails/duration_tag.rb,
lib/nero/rails/credentials_tag.rb,
lib/nero/rails/string_inquirer_tag.rb,
lib/nero/rails.rb

Defined Under Namespace

Modules: Rails Classes: BaseTag, Context, Deferred, EnvTag, Error, FormatTag, IpTag, ParseError, Parser, ProcTag, Ref, RefTag, Result, RootPathTag, Visitor

Constant Summary collapse

CONFIG_PERMITTED_CLASSES =

Classes config files may instantiate: dates and times are plausible config values. Unlike Rails' config_for (YAML.unsafe_load), arbitrary objects (!ruby/object) are refused.

%w[Symbol Date Time].freeze
VERSION =

NOTE this is written upon release via: $ rake gem:build

"0.7.0.rc7"

Class Method Summary collapse

Class Method Details

.config_dir ⇒ Object

Where config_for looks for <name>.yml: config/ in the current directory. With Rails (nero/rails), Rails.root/config instead.



59
# File 'lib/nero.rb', line 59

def self.config_dir = Pathname.pwd / "config"

.config_for(file, env: nil, root: nil, permitted_classes: CONFIG_PERMITTED_CLASSES, &block) ⇒ Object

Like Rails.application.config_for: symbol keys. See CONFIG_PERMITTED_CLASSES. file: a name (:app → config_dir/app.yml) or a Pathname (used as is, relative to the cwd).



63
64
65
66
67
68
69
70
# File 'lib/nero.rb', line 63

def self.config_for(file, env: nil, root: nil, permitted_classes: CONFIG_PERMITTED_CLASSES, &block)
  root ||= env&.to_s
  path = case file
  when Pathname then file.expand_path
  else config_dir / "#{file}.yml"
  end
  load_file(path, root:, permitted_classes:, symbolize_names: true, &block)
end

.load(yaml, **opts, &block) ⇒ Object

Like YAML.load, plus Nero's tags: string keys (symbolize_names: true for symbols), only permitted_classes (default Symbol) instantiated, aliases allowed. Raises Nero::ParseError with all errors at once. Nero::Parser#parse returns a Result instead of raising.



27
28
29
30
31
# File 'lib/nero.rb', line 27

def self.load(yaml, **opts, &block)
  result = Parser.new(**opts, &block).parse(yaml)
  emit_warnings result.warnings if result.warnings?
  result.value!
end

.load_file(path, env: nil, root: nil, **opts, &block) ⇒ Object

Like YAML.load_file; see load. root: (or env:) picks a top-level key, e.g. :development.



34
35
36
37
38
39
# File 'lib/nero.rb', line 34

def self.load_file(path, env: nil, root: nil, **opts, &block)
  root ||= env&.to_s
  result = Parser.new(root:, **opts, &block).parse_file(path)
  emit_warnings result.warnings if result.warnings?
  result.value!
end

.parse ⇒ Object

Deprecated.

Use load. Removed in 0.8.



42
43
44
45
# File 'lib/nero.rb', line 42

def self.parse(...)
  emit_warnings ["DEPRECATION WARNING: Nero.parse is deprecated and will be removed in nero 0.8 (use Nero.load)"]
  load(...)
end

.parse_file ⇒ Object

Deprecated.

Use load_file. Removed in 0.8.



48
49
50
51
# File 'lib/nero.rb', line 48

def self.parse_file(...)
  emit_warnings ["DEPRECATION WARNING: Nero.parse_file is deprecated and will be removed in nero 0.8 (use Nero.load_file)"]
  load_file(...)
end