Class: Hippo::Configuration

Inherits:
Object
  • Object
show all
Includes:
Hippo::Concerns::AttrAccessorWithDefault
Defined in:
lib/hippo/configuration.rb

Direct Known Subclasses

DefaultConfiguration

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



35
36
37
38
# File 'lib/hippo/configuration.rb', line 35

def initialize
    @observers=Hash.new{ |hash,key| hash[key] = Array.new }
    @secrets = Hashie::Mash.new
end

Instance Attribute Details

#secretsObject (readonly)

Returns the value of attribute secrets.



16
17
18
# File 'lib/hippo/configuration.rb', line 16

def secrets
  @secrets
end

Class Method Details

.applyObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/hippo/configuration.rb', line 53

def self.apply
    Oj.default_options = { mode: :rails, time_format: :xmlschema }

    controlling_ext = Hippo::Extensions.bootstrap
    secrets = controlling_ext.root_path.join('config', 'secrets.yml')

    @@secrets = Hashie::Mash.new(
        secrets.exist? ? YAML.load(ERB.new(secrets.read).result) : {}
    )

    ActiveJob::Base.queue_adapter = Hippo.env.test? ? :test : :resque
    Hippo::Job::FailureLogger.configure

    DB.establish_connection

    Jobba.configure do |config|
        config.redis_options = Hippo.config.redis
        config.namespace = "#{controlling_ext.identifier}::jobba"
    end

    Resque.redis.namespace = "#{controlling_ext.identifier}::resque"
    Resque.redis = Hippo.config.redis
    Hippo::Concerns::AssetUploader.storages = {
        cache: Shrine::Storage::FileSystem.new(
            controlling_ext.root_path,
            prefix: "tmp/cache"
        ),
        store: Shrine::Storage::FileSystem.new(
            controlling_ext.root_path,
            prefix: "public/files"
        )
    }
    Hippo::Tenant.system.perform do
        Hippo::SystemSettings.for_ext('hippo').apply!
        Extensions.each{|ext| ext.apply_configuration }

        if Kernel.const_defined?(:Guard) && ::Guard.const_defined?(:Jest)
            ::Guard::Jest.logger = Hippo.logger
        end
    end
end

.config_option(name, default, options = {}) ⇒ Object

Since changing a config value inadvertently can have pretty drastic consequences that might not be discovered immediately, we log each time a value is changed



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/hippo/configuration.rb', line 21

def self.config_option( name, default, options={} )
    define_method( "#{name}=" ) do | value |
        old_value = self.send( name )
        if value != old_value && !options[:silent]
            Hippo.logger.info "Config option #{name} changed from '#{old_value.inspect}' to '#{value.inspect}'"
        end
        instance_variable_set("@#{name}", value)
        if @observers.has_key?(name)
            @observers[name].each{ |cb| cb.call(value, old_value) }
        end
    end
    attr_reader_with_default(name, default)
end

Instance Method Details

#get(config, &block) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/hippo/configuration.rb', line 44

def get(config, &block)
    value = self.send(config.to_sym)
    if block
        on_change(config,&block)
        block.call( value, value )
    end
    value
end

#on_change(config, &block) ⇒ Object



40
41
42
# File 'lib/hippo/configuration.rb', line 40

def on_change(config, &block)
    @observers[config.to_sym] << block
end