Module: Magis
- Includes:
- Mongo
- Defined in:
- lib/magis/base.rb,
lib/magis/version.rb
Constant Summary collapse
- VERSION =
"0.0.2"
- @@home_folder =
""
Class Method Summary collapse
- .application ⇒ Object
- .db ⇒ Object
- .env ⇒ Object
- .file(filename) ⇒ Object
- .framework_path ⇒ Object
- .home_folder ⇒ Object
- .load_collection(file) ⇒ Object
- .load_configuration(file) ⇒ Object
- .omni_auth_config(type) ⇒ Object
- .set_db ⇒ Object
- .start ⇒ Object
Class Method Details
.application ⇒ Object
38 39 40 |
# File 'lib/magis/base.rb', line 38 def self.application Api end |
.db ⇒ Object
75 76 77 |
# File 'lib/magis/base.rb', line 75 def self.db @@db end |
.env ⇒ Object
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.(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_path ⇒ Object
18 19 20 |
# File 'lib/magis/base.rb', line 18 def self.framework_path @@local_path ||= File.("../../", File.dirname(__FILE__)) end |
.home_folder ⇒ Object
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_db ⇒ Object
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 |
.start ⇒ Object
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 |