Class: Fuguta::Configuration::Loader
- Inherits:
-
Object
- Object
- Fuguta::Configuration::Loader
- Defined in:
- lib/fuguta.rb
Instance Method Summary collapse
-
#initialize(conf) ⇒ Loader
constructor
A new instance of Loader.
- #load(path = nil) ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(conf) ⇒ Loader
Returns a new instance of Loader.
65 66 67 |
# File 'lib/fuguta.rb', line 65 def initialize(conf) @conf = conf end |
Instance Method Details
#load(path = nil) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fuguta.rb', line 69 def load(path = nil) buf = case path when NilClass raise "No path given and usual_paths not set" unless @conf.usual_paths path = @conf.usual_paths.find { |path| File.exists?(path) } || raise("None of the usual paths existed: #{@conf.usual_paths.join(", ")}") File.read(path) when String raise "does not exist: #{path}" unless File.exists?(path) File.read(path) when IO path.lines.join else raise "Unknown type: #{path.class}" end @conf.parse_dsl do |me| me.instance_variable_set(:@loading_path, path.to_s) me.instance_eval(buf, path.to_s) me.instance_variable_set(:@loading_path, nil) end end |
#validate ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/fuguta.rb', line 94 def validate errors = [] Configuration.walk_tree(@conf) do |c| c.validate(errors) end raise ValidationError, errors if errors.size > 0 end |