Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor eskel initialization

  • Loading branch information...
commit ec901ff36cd0736582f70d70f446e4a028657b3f 1 parent 7dc43b2
@DamianCaruso authored
View
13 Rakefile
@@ -1,12 +1,7 @@
-require 'rubygems'
-require 'bundler'
-begin
- Bundler.setup(:default, :development)
-rescue Bundler::BundlerError => e
- $stderr.puts e.message
- $stderr.puts "Run `bundle install` to install missing gems"
- exit e.status_code
-end
+# Setup bundler
+require "rubygems"
+require "bundler"
+Bundler.setup(:default, :development)
require 'rake/testtask'
View
6 app/router.rb
@@ -3,15 +3,15 @@
Cuba.use Rack::CommonLogger
Cuba.use Rack::Session::Cookie
-Cuba.use Rack::Static, urls: ["/css", "/img", "/js"], root: root_path("public")
+Cuba.use Rack::Static, urls: ["/css", "/img", "/js"], root: Eskel.root("public")
Cuba.plugin Cuba::Prelude
Cuba.plugin Cuba::Mote
Cuba.plugin Eskel::Cuba
-Cuba.settings[:views] = root_path("app/views")
+Cuba.settings[:views] = Eskel.root("app","views")
-Dir[root_path('app/routes/*.rb')].each { |f| require f }
+Dir[Eskel.root("app","routes","*.rb")].each { |f| require f }
Cuba.define do
on "home" do
View
4 config.ru
@@ -1,3 +1,3 @@
-require File.expand_path("../init",__FILE__)
+require File.expand_path("init", File.dirname(__FILE__))
-run Cuba
+run Cuba
View
0  config/initializers/.gitkeep
No changes.
View
26 init.rb
@@ -1,20 +1,20 @@
-ROOT_DIR = File.expand_path("../", __FILE__) unless defined? ROOT_DIR
-RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
-
-module Kernel
- private
- def root_path(*args)
- File.join(ROOT_DIR, *args)
- end
-end
+ESKEL_ENV = ENV["RACK_ENV"] ||= "development" unless defined?(ESKEL_ENV)
+ESKEL_ROOT = File.expand_path("..", __FILE__) unless defined?(ESKEL_ROOT)
+# Setup bundler
require "rubygems"
require "bundler"
-Bundler.setup(:default, RACK_ENV.to_sym)
+Bundler.setup(:default, ESKEL_ENV.to_sym)
+
+# Set enconding to UTF_8
+Encoding.default_internal = Encoding.default_external = Encoding::UTF_8 if defined?(Encoding)
-$LOAD_PATH.unshift root_path("lib")
+# Require eskel
+$LOAD_PATH.unshift File.join(ESKEL_ROOT,"lib")
require "eskel"
-Encoding.default_internal = Encoding.default_external = Encoding::UTF_8 if defined? Encoding
+# Require initializers
+Dir[Eskel.root("config","initializers","**","*.rb")].each { |f| require f }
-require root_path("app/router")
+# Require router
+require Eskel.root("app","router")
View
12 lib/eskel.rb
@@ -5,13 +5,21 @@
module Eskel
extend self
+ def root(*args)
+ File.expand_path(File.join(ESKEL_ROOT, *args))
+ end
+
+ def env
+ @env ||= ESKEL_ENV.to_s.downcase.to_sym
+ end
+
def settings
- @settings ||= Hashie::Mash.new(YAML.load_file(root_path("config/settings.yml"))[RACK_ENV])
+ @settings ||= Hashie::Mash.new(YAML.load_file(root_path("config/settings.yml"))[env.to_s])
end
def logger
@logger ||= begin
- logger = ::Logger.new(root_path("log/#{RACK_ENV}.log"))
+ logger = ::Logger.new(root_path("log/#{env}.log"))
logger.level = ::Logger.const_get((settings.log_level || :warn).to_s.upcase)
logger.datetime_format = "%Y-%m-%d %H:%M:%S"
logger
View
4 spec/helper.rb
@@ -1,6 +1,6 @@
ENV["RACK_ENV"] = "test"
-require File.expand_path('../init', File.dirname(__FILE__))
+require File.expand_path('init', File.dirname(File.dirname(__FILE__)))
require 'minitest/autorun'
# Custom support files
-Dir[root_path('spec/support/**/*.rb')].each { |f| require f }
+Dir[Eskel.root('spec','support','**','*.rb')].each { |f| require f }
Please sign in to comment.
Something went wrong with that request. Please try again.