Class: Itsi::Server::Config::Include

Inherits:
Option
  • Object
show all
Defined in:
lib/itsi/server/config/options/include.rb

Instance Method Summary collapse

Methods included from ConfigHelpers

included, #initialize, load_and_register, #normalize_keys!

Instance Method Details

#build!Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/itsi/server/config/options/include.rb', line 13

def build!
  caller_location = caller_locations(2, 1).first.path
  included_file = \
    if caller_location =~ %r{lib/itsi/server}
      File.expand_path("#{@params}.rb")
    else
      File.expand_path("#{@params}.rb", File.dirname(caller_location))
    end

  location.instance_eval do
    @included ||= []
    @included << included_file

    if @auto_reloading
      if ENV["BUNDLE_BIN_PATH"]
        watch "#{included_file}", [%w[bundle exec itsi restart]]
      else
        watch "#{included_file}", [%w[itsi restart]]
      end
    end
  end

  code = IO.read(included_file)
  location.instance_eval(code, included_file, 1)
end