Module: Jackal::Utils::Config

Included in:
Carnivore::Http::PointBuilder::Endpoint, Callback
Defined in:
lib/jackal/utils/config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object

Load extra modules automatically



15
16
17
18
19
# File 'lib/jackal/utils/config.rb', line 15

def self.extended(klass)
  klass.class_eval do
    extend Bogo::AnimalStrings
  end
end

.included(klass) ⇒ Object

Load extra modules automatically



8
9
10
11
12
# File 'lib/jackal/utils/config.rb', line 8

def self.included(klass)
  klass.class_eval do
    include Bogo::AnimalStrings
  end
end

Instance Method Details

#app_configSmash

Returns application configuration.

Returns:

  • (Smash)

    application configuration



39
40
41
42
43
44
45
46
# File 'lib/jackal/utils/config.rb', line 39

def app_config
  Carnivore::Config.fetch(
    snake(
      self.class.name.split('::').first
    ),
    Smash.new
  )
end

#app_hostString

Returns name of the host running the application.

Returns:

  • (String)

    name of the host running the application



49
50
51
# File 'lib/jackal/utils/config.rb', line 49

def app_host
  app_config.fetch(:app_host, Socket.gethostname)
end

#configSmash

Returns configuration.

Returns:

  • (Smash)

    configuration



59
60
61
# File 'lib/jackal/utils/config.rb', line 59

def config
  service_config[:config] || Smash.new
end

#config_path(class_name = self.class.name) ⇒ Array

Returns key path in configuration.

Returns:

  • (Array)

    key path in configuration



27
28
29
30
31
# File 'lib/jackal/utils/config.rb', line 27

def config_path(class_name = self.class.name)
  class_name.split('::')[0,2].map do |string|
    snake(string)
  end
end

#destination(direction, payload) ⇒ Symbol

Generate destination key based on direction

Parameters:

  • direction (Symbol, String)
  • payload (Smash)

Returns:

  • (Symbol)


68
69
70
# File 'lib/jackal/utils/config.rb', line 68

def destination(direction, payload)
  [source_prefix, direction].map(&:to_s).join('_').to_sym
end

#service_configSmash

Returns service configuration.

Returns:

  • (Smash)

    service configuration



54
55
56
# File 'lib/jackal/utils/config.rb', line 54

def service_config
  Carnivore::Config.get(*config_path) || Smash.new
end

#service_name(class_name = self.class.name) ⇒ Symbol

Returns name of service.

Returns:

  • (Symbol)

    name of service



22
23
24
# File 'lib/jackal/utils/config.rb', line 22

def service_name(class_name = self.class.name)
  config_path(class_name).last.to_sym
end

#source_prefixString

Returns prefix of source for this callback.

Returns:

  • (String)

    prefix of source for this callback



34
35
36
# File 'lib/jackal/utils/config.rb', line 34

def source_prefix
  config_path.join('_')
end