Harbor Documentation

Constants

  • TEST
  • DEVELOPMENT
  • STAGE
  • PRODUCTION

Public Class Methods

instance()

     # File lib/harbor/configuration.rb, line 7
7:     def self.instance
8:       @instance ||= instance = self::new
9:     end

new()

      # File lib/harbor/configuration.rb, line 11
11:     def initialize
12:       super
13:       @debug = false
14:       register("hostname", `hostname`.strip)
15:       
16:       case ENV["ENVIRONMENT"]
17:       when "production"
18:         @environment = PRODUCTION
19:       when "stage"
20:         @environment = STAGE
21:       when "development" 
22:         @environment = DEVELOPMENT
23:       when "test"
24:         @environment = TEST
25:       else
26:         if ENV["ENVIRONMENT"].to_s.empty?
27:           @environment = DEVELOPMENT
28:         end
29:       end
30:     end

Public Instance Methods

debug!()

      # File lib/harbor/configuration.rb, line 75
75:     def debug!
76:       @debug = true
77:     end

debug?()

      # File lib/harbor/configuration.rb, line 79
79:     def debug?
80:       @debug
81:     end

development?()

      # File lib/harbor/configuration.rb, line 36
36:     def development?
37:       @environment == DEVELOPMENT
38:     end

load!(path)

      # File lib/harbor/configuration.rb, line 48
48:     def load!(path)
49:       env = Pathname(path)
50:       
51:       host_configs = if hostname =~ /\./
52:         # If the hostname is something like "stage.demo", then we want to load our
53:         # configs in order of least specific to most specific. So we want:
54:         # [ "stage", "demo", "stage.demo" ]
55:         [ *hostname.split(".").map { |part| "#{part}.rb" } << "#{hostname}.rb" ]
56:       else
57:         [ "#{hostname}.rb" ]
58:       end
59:       
60:       # It could be that the hostname split above duplicates an environment based config name.
61:       cascade = [ "default.rb", "#{ENV["ENVIRONMENT"]}.rb", *host_configs ].uniq
62:       
63:       if ENV["DEBUG"] then
64:         puts "env search cascade is #{cascade.inspect}"
65:       end
66:       
67:       cascade.each do |file|
68:         configuration_file = Pathname(path) + file
69:         if ::File.exists?(configuration_file.to_s)
70:           load configuration_file
71:         end
72:       end
73:     end

production?()

      # File lib/harbor/configuration.rb, line 44
44:     def production?
45:       @environment == PRODUCTION
46:     end

stage?()

      # File lib/harbor/configuration.rb, line 40
40:     def stage?
41:       @environment == STAGE
42:     end

test?()

      # File lib/harbor/configuration.rb, line 32
32:     def test?
33:       @environment == TEST
34:     end