Module: Magis

Includes:
Mongo
Defined in:
lib/magis/base.rb,
lib/magis/version.rb

Constant Summary collapse

VERSION =
"0.0.1"
@@home_folder =
""

Class Method Summary collapse

Class Method Details

.applicationObject



38
39
40
# File 'lib/magis/base.rb', line 38

def self.application
  Api
end

.dbObject



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

def self.db
  @@db
end

.envObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/magis/base.rb', line 42

def self.env
  @@environment ||= ENV['RACK_ENV']
  setup ||= @@environment == "setup"
  production ||= @@environment == "production"
  development ||= @@environment == "development"
  test ||= @@environment == "test"
  @environments ||= OpenStruct.new({
    setup?: setup, 
    production?: production, 
    development?: development, 
    test?: test
  })
  @environments
end

.file(filename) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/magis/base.rb', line 21

def self.file(filename)
  local_path = self.framework_path
  project_path = File.expand_path(self.home_folder)

  file_contents = nil
  full_file_name = project_path + filename

  if File.file?(full_file_name)
    file_contents = File.new(full_file_name).readlines
  elsif File.file?(local_path + filename)
    full_file_name = local_path + filename
    file_contents = File.new(full_file_name).readlines
  end
  
  file_contents
end

.framework_pathObject



18
19
20
# File 'lib/magis/base.rb', line 18

def self.framework_path
  @@local_path ||= File.expand_path("../../", File.dirname(__FILE__))
end

.home_folderObject



57
58
59
# File 'lib/magis/base.rb', line 57

def self.home_folder
  Dir.pwd
end

.load_collection(file) ⇒ Object



79
80
81
82
83
84
85
# File 'lib/magis/base.rb', line 79

def self.load_collection(file)
  if File.exist?(home_folder + "/collections/" + file + ".yml")
    YAML.load_file(home_folder + "/collections/" + file + ".yml")
  else
    Hash.new
  end
end

.load_configuration(file) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/magis/base.rb', line 87

def self.load_configuration(file)
  @@files ||= Hash.new
  if File.exist?(home_folder + "/config/" + file + ".yml")
    @@files[file] ||= YAML.load_file(home_folder + "/config/" + file + ".yml")
  else
    Hash.new
  end
end

.omni_auth_config(type) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/magis/base.rb', line 96

def self.omni_auth_config(type)
  configuration = self.load_configuration(type)
  configuration[:id] ||= nil
  configuration[:secret] ||= nil
    
  configuration
end

.set_dbObject



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/magis/base.rb', line 61

def self.set_db
  uri = ENV["DB_URI"] || Magis.load_configuration("database")["uri"]

  if uri
    client = MongoClient.from_uri(uri)
  else
    client = MongoClient.new 
  end

  db_name = ENV["DB_NAME"] || Magis.load_configuration("database")["name"]

  @@db = client[db_name]
end

.startObject



104
105
106
107
# File 'lib/magis/base.rb', line 104

def self.start
  Dir["/api/*.rb"].each {|file| require file }
  self.set_db
end