Module: Stealth

Defined in:
lib/stealth/cli.rb,
lib/stealth/base.rb,
lib/stealth/jobs.rb,
lib/stealth/reply.rb,
lib/stealth/errors.rb,
lib/stealth/logger.rb,
lib/stealth/server.rb,
lib/stealth/session.rb,
lib/stealth/version.rb,
lib/stealth/cli_base.rb,
lib/stealth/flow/base.rb,
lib/stealth/dispatcher.rb,
lib/stealth/flow/state.rb,
lib/stealth/configuration.rb,
lib/stealth/service_reply.rb,
lib/stealth/commands/server.rb,
lib/stealth/scheduled_reply.rb,
lib/stealth/service_message.rb,
lib/stealth/commands/command.rb,
lib/stealth/commands/console.rb,
lib/stealth/migrations/tasks.rb,
lib/stealth/controller/helpers.rb,
lib/stealth/controller/replies.rb,
lib/stealth/flow/specification.rb,
lib/stealth/generators/builder.rb,
lib/stealth/generators/generate.rb,
lib/stealth/controller/callbacks.rb,
lib/stealth/controller/catch_all.rb,
lib/stealth/services/base_client.rb,
lib/stealth/controller/controller.rb,
lib/stealth/migrations/generators.rb,
lib/stealth/migrations/configurator.rb,
lib/stealth/controller/dynamic_delay.rb,
lib/stealth/migrations/railtie_config.rb,
lib/stealth/services/base_reply_handler.rb,
lib/stealth/services/base_message_handler.rb,
lib/stealth/services/jobs/handle_message_job.rb

Defined Under Namespace

Modules: CliBase, Commands, Flow, Generators, Migrations, Services, Version Classes: Cli, Configuration, Controller, Dispatcher, Errors, Jobs, Logger, Reply, ScheduledReplyJob, Server, ServiceMessage, ServiceReply, Session

Constant Summary collapse

VERSION =
Version.version

Class Method Summary collapse

Class Method Details

.bootObject



32
33
34
# File 'lib/stealth/base.rb', line 32

def self.boot
  load_environment
end

.configObject



36
37
38
# File 'lib/stealth/base.rb', line 36

def self.config
  Thread.current[:configuration] ||= load_services_config
end

.configuration=(config) ⇒ Object



40
41
42
# File 'lib/stealth/base.rb', line 40

def self.configuration=(config)
  Thread.current[:configuration] = config
end

.envObject



24
25
26
# File 'lib/stealth/base.rb', line 24

def self.env
  @env ||= ActiveSupport::StringInquirer.new(ENV['STEALTH_ENV'] || 'development')
end

.load_environmentObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/stealth/base.rb', line 79

def self.load_environment
  require File.join(Stealth.root, 'config', 'boot')
  require_directory("config/initializers")

  # Require explicitly to ensure it loads first
  require_directory File.join(Stealth.root, 'bot', 'controllers', 'concerns')
  require_directory File.join(Stealth.root, 'bot', 'models', 'concerns')
  require File.join(Stealth.root, 'bot', 'controllers', 'bot_controller')
  require File.join(Stealth.root, 'bot', 'models', 'bot_record')

  require File.join(Stealth.root, 'config', 'flow_map')
  require_directory("bot")

  if defined?(ActiveRecord)
    if ENV['DATABASE_URL'].present?
      ActiveRecord::Base.establish_connection(ENV['DATABASE_URL'])
    else
      ActiveRecord::Base.establish_connection(YAML::load_file("config/database.yml")[Stealth.env])
    end
  end
end

.load_services_config(services_yaml = nil) ⇒ Object

Loads the services.yml configuration unless one has already been loaded



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/stealth/base.rb', line 50

def self.load_services_config(services_yaml=nil)
  @semaphore ||= Mutex.new
  services_yaml ||= Stealth.load_services_config(
    File.read(File.join(Stealth.root, 'config', 'services.yml'))
  )

  Thread.current[:configuration] ||= begin
    @semaphore.synchronize do
      services_config = YAML.load(ERB.new(services_yaml).result)

      unless services_config.has_key?(env)
        raise Stealth::Errors::ConfigurationError, "Could not find services.yml configuration for #{env} environment"
      end

      config = Stealth::Configuration.new(services_config[env])
      set_config_defaults(config)

      config
    end
  end
end

.load_services_config!(services_yaml = nil) ⇒ Object

Same as ‘load_services_config` but forces the loading even if one has already been loaded



74
75
76
77
# File 'lib/stealth/base.rb', line 74

def self.load_services_config!(services_yaml=nil)
  Thread.current[:configuration] = nil
  load_services_config(services_yaml)
end

.rootObject



28
29
30
# File 'lib/stealth/base.rb', line 28

def self.root
  @root ||= File.expand_path(Pathname.new(Dir.pwd))
end

.set_config_defaults(config) ⇒ Object



44
45
46
47
# File 'lib/stealth/base.rb', line 44

def self.set_config_defaults(config)
  config.dynamic_delay_muliplier = 1.0
  config.session_ttl = 0
end