Module: Skynet

Extended by:
Skynet
Included in:
Skynet
Defined in:
lib/skynet-core.rb,
lib/skynet-core/harvest.rb,
lib/skynet-core/cyberdyne.rb,
lib/skynet-core/db/hippocampus.rb

Defined Under Namespace

Classes: ApplicationLoadError, Cyberdyne, Harvest, Queue

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#_app_configObject (readonly)

Returns the value of attribute _app_config.



16
17
18
# File 'lib/skynet-core.rb', line 16

def _app_config
  @_app_config
end

#_database_configObject (readonly)

Returns the value of attribute _database_config.



16
17
18
# File 'lib/skynet-core.rb', line 16

def _database_config
  @_database_config
end

#_queueObject (readonly)

Returns the value of attribute _queue.



16
17
18
# File 'lib/skynet-core.rb', line 16

def _queue
  @_queue
end

Class Method Details

.app_configObject



54
55
56
# File 'lib/skynet-core.rb', line 54

def app_config
  @_app_config ||= set_app_config
end

.database_configObject



58
59
60
# File 'lib/skynet-core.rb', line 58

def database_config
  @_database_config ||= set_database_config
end

.envObject



23
24
25
# File 'lib/skynet-core.rb', line 23

def env
  @_env ||= SKYNET_ENV.to_s.downcase.to_sym
end

.load_configObject

def bundle

  return :locked   if File.exist?(root('.bundle/environment.rb'))
  return :unlocked if File.exist?(root("Gemfile"))
end


46
47
48
49
50
51
52
# File 'lib/skynet-core.rb', line 46

def load_config
  app_config
  database_config

  raise "Config files not found" if @_app_config.nil? || @_database_config.nil?
  !@_app_config.nil?
end

.load_dependencies(*paths) ⇒ Object Also known as: load_dependency

Attempts to load all dependency libs that we need. If you use this method we can perform correctly a Padrino.reload!



99
100
101
102
103
# File 'lib/skynet-core.rb', line 99

def load_dependencies(*paths)
  paths.each do |path|
    Dir[path].each { |file| load(file) }
  end
end

.queueObject



62
63
64
# File 'lib/skynet-core.rb', line 62

def queue
  @_queue ||= load_queue_database
end

.require_dependencies(*paths) ⇒ Object Also known as: require_dependency



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
# File 'lib/skynet-core.rb', line 66

def require_dependencies(*paths)
  # Extract all files to load
  files = paths.map { |path| Dir[path] }.flatten

  while files.present?
    # We need a size to make sure things are loading
    size_at_start = files.size

    # List of errors and failed files
    errors, failed = [], []

    # Now we try to require our dependencies
    files.each do |file|
      begin
        require file
        files.delete(file)
      rescue Exception => e
        errors << e
        failed << files
      end
    end

    # Stop processing if nothing loads or if everything has loaded
    raise errors.last if files.size == size_at_start && files.present?
    break if files.empty?
  end
end

.root(*args) ⇒ Object



27
28
29
# File 'lib/skynet-core.rb', line 27

def root(*args)
  File.expand_path(File.join(SKYNET_ROOT, *args))
end

.set_encodingObject

Default encoding to UTF8 if it has not already been set to something else.



33
34
35
36
37
38
# File 'lib/skynet-core.rb', line 33

def set_encoding
  unless RUBY_VERSION >= '1.9'
    $KCODE = 'U' if $KCODE == 'NONE' || $KCODE.blank?
  end
  nil
end