rango 0.1.1.3 → 0.2.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +17 -1
- data/Rakefile +8 -3
- data/bin/rango +0 -13
- data/lib/rango.rb +23 -12
- data/lib/rango/controller.rb +70 -57
- data/lib/rango/core_ext.rb +100 -17
- data/lib/rango/environments.rb +33 -19
- data/lib/rango/exceptions.rb +1 -1
- data/lib/rango/forms/form.rb +2 -1
- data/lib/rango/helpers/assets.rb +6 -1
- data/lib/rango/helpers/general.rb +1 -1
- data/lib/rango/mixins/action_args.rb +48 -0
- data/lib/rango/mixins/chainable.rb +66 -0
- data/lib/rango/mixins/filters.rb +12 -20
- data/lib/rango/mixins/logger.rb +1 -0
- data/lib/rango/mixins/message.rb +5 -6
- data/lib/rango/mixins/render.rb +1 -1
- data/lib/rango/orm/tasks/datamapper.rake +4 -4
- data/lib/rango/path.rb +6 -1
- data/lib/rango/rack/request.rb +18 -29
- data/lib/rango/router.rb +1 -1
- data/lib/rango/stacks/controller.rb +0 -1
- data/lib/rango/templates/exts/tilt.rb +3 -3
- data/lib/rango/templates/helpers.rb +55 -27
- data/lib/rango/templates/template.rb +11 -9
- data/spec/rango/controller_spec.rb +0 -1
- data/spec/rango/{loggers/fireruby_spec.rb → core_ext_spec.rb} +0 -0
- data/spec/rango/environments_spec.rb +6 -6
- data/spec/rango/{mixins/application_spec.rb → gv/router_spec.rb} +0 -0
- data/spec/rango/{orm/adapter_spec.rb → gv/scaffolding_spec.rb} +0 -0
- data/spec/rango/{orm/adapters/datamapper_spec.rb → mini_render_spec.rb} +0 -0
- data/spec/rango/mixins/action_args_spec.rb +78 -0
- data/spec/rango/{orm/adapters/sequel_spec.rb → mixins/chainable_spec.rb} +0 -0
- data/spec/rango/{orm/support/datamapper/support_spec.rb → mixins/logger_spec.rb} +0 -0
- data/spec/rango/mixins/message_spec.rb +4 -1
- data/spec/rango/mixins/render_spec.rb +1 -1
- data/spec/rango/{settings/erubis_spec.rb → path_spec.rb} +0 -0
- data/spec/rango/{settings/framework_spec.rb → stacks/controller_spec.rb} +0 -0
- data/spec/rango/{settings/haml_spec.rb → stacks/mini_spec.rb} +0 -0
- data/spec/rango/templates/helpers_spec.rb +125 -0
- data/spec/rango/templates/template_spec.rb +1 -2
- data/spec/rango/{settings/template_spec.rb → version_spec.rb} +0 -0
- data/spec/rango_spec.rb +6 -1
- data/spec/spec_helper.rb +8 -2
- data/spec/stubs/templates/_basic.html.erb +6 -0
- data/spec/stubs/templates/block/block.html.haml +2 -0
- data/spec/stubs/templates/block/blocks.html.haml +5 -0
- data/spec/stubs/templates/block/error.html.haml +2 -0
- data/spec/stubs/templates/block/getter.html.haml +3 -0
- data/spec/stubs/templates/block/value.html.haml +1 -0
- data/spec/stubs/templates/enhance_block/basic.html.haml +5 -0
- data/spec/stubs/templates/enhance_block/error.html.haml +3 -0
- data/spec/stubs/templates/enhance_block/name_error.html.haml +1 -0
- data/spec/stubs/templates/enhance_block/nil.html.haml +3 -0
- data/spec/stubs/templates/enhance_block/standalone.html.haml +2 -0
- data/spec/stubs/templates/extend_block/basic.html.haml +5 -0
- data/spec/stubs/templates/extend_block/error.html.haml +5 -0
- data/spec/stubs/templates/extend_block/error2.html.haml +1 -0
- data/spec/stubs/templates/extend_block/name_error.html.haml +1 -0
- data/spec/stubs/templates/extend_block/nil.html.haml +4 -0
- data/spec/stubs/templates/includes/base.html.haml +1 -0
- data/spec/stubs/templates/includes/basic.html.haml +1 -0
- data/spec/stubs/templates/includes/includes.html.haml +7 -0
- data/spec/stubs/templates/includes/integration.html.haml +4 -0
- data/spec/stubs/templates/includes/integration2.html.haml +4 -0
- data/spec/stubs/templates/library.html.haml +3 -0
- data/stubs/features/content/shared/.gitignore +0 -0
- data/stubs/stack/content/.gitignore +18 -0
- data/stubs/stack/content/.rvmrc.rbt +2 -0
- data/stubs/stack/content/Gemfile.rbt +8 -1
- data/stubs/stack/content/{settings_local.rb.rbt → environments.rb.rbt} +11 -0
- data/stubs/stack/content/init.rb.rbt +8 -4
- data/stubs/stack/content/media/.gitignore +0 -0
- data/stubs/stack/content/spec/spec_helper.rb +1 -1
- data/stubs/stack/content/views.rb.rbt +13 -5
- data/stubs/stack/postprocess.rb +2 -9
- metadata +62 -29
- data/lib/rango/logger.rb +0 -19
- data/lib/rango/loggers/fireruby.rb +0 -1
- data/lib/rango/mixins/application.rb +0 -27
data/CHANGELOG
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
* ImplicitRendering and ExplicitRendering mixins for using locals
|
35
35
|
vs. rendering in context of current controller instance
|
36
36
|
|
37
|
-
= Version 0.1.2, 13/12/2009
|
37
|
+
= Version 0.1.2, 13/12/2009
|
38
38
|
* Sequel support
|
39
39
|
* Project generator renamed to stack generator
|
40
40
|
* Removed app and bigapp generators
|
@@ -44,3 +44,19 @@
|
|
44
44
|
* Much more modular design
|
45
45
|
* Removed dependencies, since you can use whichever subset of Rango
|
46
46
|
* There is Rango::Router.app instead of Project.router
|
47
|
+
|
48
|
+
= Version 0.2.0, 24/12/2009
|
49
|
+
* Sequel support
|
50
|
+
* Logger is now configurable, you don't have to use any particular one
|
51
|
+
* Rango doesn't depend on RubyExts anymore
|
52
|
+
* Fixed status and headers settings in controller
|
53
|
+
* Fixed partial, extend_block and created includes for required-like functionality for templates
|
54
|
+
* Generators refactored, better env support
|
55
|
+
* Rango::Controller#redirect returns escaped location URL
|
56
|
+
* More modularity and granularity, Rango now plays nicely with other frameworks
|
57
|
+
* Refactored controller and it's now possible to write strategies for arguments passed to views
|
58
|
+
* ActionArgs for passing data from params to views (default behaviour in stack application)
|
59
|
+
* Rango itself use bundler rather than git submodules
|
60
|
+
* rake hooks will install task for removing whitespace in pre-commit hook, contributors should use it!
|
61
|
+
* Template helpers can work with paths relative to current template via ./path.html resp. ../path.html. All other paths are relative to the template paths.
|
62
|
+
* Use simple-logger as a default logger or standar logger if the simple-logger isn't installed.
|
data/Rakefile
CHANGED
@@ -3,14 +3,19 @@
|
|
3
3
|
require_relative "lib/rango/version"
|
4
4
|
|
5
5
|
# ENV setup for external commands
|
6
|
-
ENV["RUBYLIB"] = Dir["
|
7
|
-
$LOAD_PATH.clear.push(*Dir["
|
6
|
+
ENV["RUBYLIB"] = Dir["gems/gems/*/lib"].join(":")
|
7
|
+
$LOAD_PATH.clear.push(*Dir["gems/gems/*/lib"])
|
8
8
|
|
9
9
|
# http://support.runcoderun.com/faqs/builds/how-do-i-run-rake-with-trace-enabled
|
10
10
|
Rake.application.options.trace = true
|
11
11
|
|
12
|
+
task :bundle do
|
13
|
+
# NOTE: the sense of the checkout is to avoid overwriting our changes in scripts
|
14
|
+
exec "gem bundle --cached && git checkout script"
|
15
|
+
end
|
16
|
+
|
12
17
|
# default task for RunCodeRun.com
|
13
|
-
task :default => [
|
18
|
+
task :default => [:bundle, :spec]
|
14
19
|
|
15
20
|
# load tasks
|
16
21
|
Dir["tasks/*.rake"].each do |taskfile|
|
data/bin/rango
CHANGED
@@ -8,17 +8,6 @@ end
|
|
8
8
|
base = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
|
9
9
|
libdir = File.expand_path(File.join(File.dirname(base), "..", "lib"))
|
10
10
|
|
11
|
-
vendor = File.join(File.dirname(__FILE__), "..", "vendor")
|
12
|
-
if File.directory?(vendor)
|
13
|
-
Dir["#{vendor}/*"].each do |path|
|
14
|
-
if File.directory?(path) && Dir["#{path}/*"].empty?
|
15
|
-
warn "Dependency #{File.basename(path)} in vendor seems to be empty. Run git submodule init && git submodule update to checkout it."
|
16
|
-
elsif File.directory?(path) && File.directory?(File.join(path, "lib"))
|
17
|
-
$:.unshift(File.join(path, "lib"))
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
11
|
# because of system installation, there is bin/../lib, but not bin/../lib/rango
|
23
12
|
if File.directory?(File.join(libdir, "rango"))
|
24
13
|
$:.unshift(libdir) unless $:.include?(libdir)
|
@@ -31,7 +20,6 @@ rescue LoadError
|
|
31
20
|
end
|
32
21
|
|
33
22
|
require "rango"
|
34
|
-
require "rango/logger"
|
35
23
|
|
36
24
|
# === Helpers === #
|
37
25
|
# TODO: Generators.each { |generator| puts generator.help }
|
@@ -45,7 +33,6 @@ end
|
|
45
33
|
begin
|
46
34
|
ARGV.shift || usage # create
|
47
35
|
generator_name = ARGV.shift
|
48
|
-
SimpleTemplater.logger = Rango.logger
|
49
36
|
templater = SimpleTemplater.new(:rango)
|
50
37
|
# This enables you to create custom generators for Rango
|
51
38
|
load File.join(File.dirname(base), "..", "simple-templater.scope") # neccesary if we run rango locally and not from RubyGems
|
data/lib/rango.rb
CHANGED
@@ -4,16 +4,11 @@ if RUBY_VERSION < "1.9.1"
|
|
4
4
|
raise "Rango requires at least Ruby 1.9.1. If you run JRuby, please ensure you used the --1.9 switch for JRuby command."
|
5
5
|
end
|
6
6
|
|
7
|
-
require "rango/core_ext"
|
8
|
-
|
9
7
|
rango_lib = File.dirname(__FILE__)
|
10
8
|
unless $:.include?(rango_lib) || $:.include?(File.expand_path(rango_lib))
|
11
9
|
$:.unshift(rango_lib)
|
12
10
|
end
|
13
11
|
|
14
|
-
# It should solve problems with encoding in URL (flash messages) and templates
|
15
|
-
Encoding.default_internal = "utf-8"
|
16
|
-
|
17
12
|
module Rango
|
18
13
|
# all the helpers are in Rango::Helpers
|
19
14
|
# so if you want to register your own, just
|
@@ -37,9 +32,17 @@ module Rango
|
|
37
32
|
end
|
38
33
|
|
39
34
|
def self.logger
|
40
|
-
@@logger
|
41
|
-
|
42
|
-
|
35
|
+
@@logger ||= begin
|
36
|
+
require "simple-logger"
|
37
|
+
SimpleLogger::Logger.new(STDOUT).tap do |logger|
|
38
|
+
logger.auto_flush = true # disable in your code for production!
|
39
|
+
end
|
40
|
+
rescue LoadError
|
41
|
+
require "logger"
|
42
|
+
Logger.new(STDOUT).tap do |logger|
|
43
|
+
logger.warn("Using stdlib logger. If you want something more fancy with colors and #flush, install simple-logger.")
|
44
|
+
end
|
45
|
+
end
|
43
46
|
end
|
44
47
|
|
45
48
|
def self.logger=(logger)
|
@@ -89,13 +92,21 @@ module Rango
|
|
89
92
|
require "irb"
|
90
93
|
require "rango/utils"
|
91
94
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
+
begin
|
96
|
+
require "racksh/boot"
|
97
|
+
rescue LoadError
|
95
98
|
Rango.logger.info("For more goodies install racksh gem")
|
96
|
-
|
99
|
+
else
|
97
100
|
Rango::Utils.load_rackup # so you can use Rango::Router.app etc
|
98
101
|
end
|
102
|
+
|
103
|
+
begin
|
104
|
+
require "irb/completion"
|
105
|
+
rescue LoadError
|
106
|
+
# some people can have ruby compliled without readline
|
107
|
+
end
|
108
|
+
|
109
|
+
ARGV.delete("-i") # otherwise irb will read it
|
99
110
|
IRB.start
|
100
111
|
end
|
101
112
|
end
|
data/lib/rango/controller.rb
CHANGED
@@ -2,100 +2,113 @@
|
|
2
2
|
|
3
3
|
# http://wiki.github.com/botanicus/rango/controllers
|
4
4
|
|
5
|
+
require "forwardable"
|
5
6
|
require "rango/router"
|
6
7
|
require "rango/exceptions"
|
7
8
|
require "rango/rack/request"
|
8
|
-
require "rubyexts/attribute"
|
9
9
|
|
10
10
|
module Rango
|
11
11
|
class Controller
|
12
12
|
include Rango::UrlHelper
|
13
|
+
extend Forwardable
|
14
|
+
# for routers
|
15
|
+
def self.dispatcher(action)
|
16
|
+
lambda do |env|
|
17
|
+
Rango.logger.info("Dispatching to #{self}##{action} [#{env["REQUEST_METHOD"]} #{env["PATH_INFO"]}]")
|
18
|
+
env["rango.controller.action"] = action
|
19
|
+
return self.call(env)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
13
23
|
# [master] Change Merb::Controller to respond to #call and return a Rack Array. (wycats)http://rubyurl.com/BhoY
|
14
24
|
# @since 0.0.2
|
15
25
|
def self.call(env)
|
16
|
-
Rango::Router.set_rack_env(env)
|
17
|
-
|
18
|
-
options = env["rango.router.params"] || raise("rango.router.params property has to be setup at least to empty hash")
|
19
|
-
controller = self.new(env, options.merge(request.params))
|
26
|
+
Rango::Router.set_rack_env(env) # TODO: this shouldn't require router stuff, it might emit an event
|
27
|
+
controller = self.new(env)
|
20
28
|
controller.to_response
|
21
29
|
end
|
22
30
|
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
self.process_action(method)
|
31
|
+
def run_action
|
32
|
+
if self.respond_to?(self.action)
|
33
|
+
self.invoke_action(self.action)
|
27
34
|
else
|
28
|
-
raise NotFound, "Controller #{self.class.name} doesn't have method #{
|
35
|
+
raise NotFound, "Controller #{self.class.name} doesn't have method #{self.action}"
|
29
36
|
end
|
30
|
-
return self.response.finish
|
31
|
-
rescue HttpError => exception
|
32
|
-
self.rescue_http_error(exception)
|
33
37
|
end
|
34
38
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
self.response.body = self.method(method).call
|
40
|
-
else
|
41
|
-
args = self.params.values
|
42
|
-
Rango.logger.debug("Calling method #{self.class.name}##{method} with arguments #{args.inspect}")
|
43
|
-
self.response.body = self.method(method).call(*args)
|
44
|
-
end
|
39
|
+
# default, redefine in plugin if you need to
|
40
|
+
def invoke_action(action)
|
41
|
+
Rango.logger.debug("Calling method #{self.class.name}##{action} without arguments")
|
42
|
+
self.response.body = self.send(action)
|
45
43
|
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
env["rango.controller.action"] = action
|
52
|
-
return self.call(env)
|
53
|
-
end
|
45
|
+
def action
|
46
|
+
env["rango.controller.action"].to_sym
|
47
|
+
rescue NoMethodError
|
48
|
+
raise "You have to setup env['rango.controller.action'] to name of action you want to call"
|
54
49
|
end
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
51
|
+
def to_response
|
52
|
+
self.run_action
|
53
|
+
#self.response.finish # do we need this?
|
54
|
+
[response.status, response.headers, [response.body]] # this way we got real body rather than response object
|
55
|
+
rescue HttpError => exception
|
56
|
+
self.rescue_http_error(exception)
|
57
|
+
end
|
62
58
|
|
63
59
|
# @since 0.0.1
|
64
|
-
# @return [
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
60
|
+
# @return [#debug, #info, #error, #fatal, #flush, #close] Logger for logging project related stuff.
|
61
|
+
def logger
|
62
|
+
Rango.logger
|
63
|
+
end
|
64
|
+
|
65
|
+
def_delegators :response, :status, :status=
|
66
|
+
def_delegators :response, :headers, :headers=
|
70
67
|
|
71
68
|
# @since 0.0.2
|
69
|
+
# @return [String] Escaped URL (which is RFC recommendation)
|
72
70
|
def redirect(url, options = Hash.new)
|
73
71
|
self.status = 302
|
74
72
|
self.headers["Location"] = URI.escape(url)
|
75
|
-
return String.new
|
76
73
|
end
|
77
74
|
|
78
|
-
|
79
|
-
|
80
|
-
@
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
Rango.
|
75
|
+
attr_reader :env
|
76
|
+
def initialize(env)
|
77
|
+
@env = env
|
78
|
+
end
|
79
|
+
|
80
|
+
def request
|
81
|
+
@request ||= Rango::Request.new(env)
|
82
|
+
end
|
83
|
+
|
84
|
+
def response
|
85
|
+
@response ||= Rack::Response.new
|
86
|
+
end
|
87
|
+
|
88
|
+
def_delegators :request, :cookies, :session
|
89
|
+
|
90
|
+
def router_params
|
91
|
+
@router_params ||= begin
|
92
|
+
self.env["rango.router.params"].symbolize_keys || raise("rango.router.params property has to be setup at least to empty hash")
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def params
|
97
|
+
@params ||= self.request.params.merge(self.router_params).symbolize_keys
|
85
98
|
end
|
86
|
-
attr_reader :session
|
87
99
|
|
88
100
|
# redefine this method for your controller if you want to provide custom error pages
|
89
101
|
# returns response array for rack
|
90
102
|
# if you need to change just body of error message, define render_http_error method
|
91
103
|
# @api plugin
|
92
104
|
def rescue_http_error(exception)
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
105
|
+
# we need to call it before we assign the variables
|
106
|
+
body = self.render_http_error(exception)
|
107
|
+
[exception.status, exception.headers, body]
|
108
|
+
end
|
109
|
+
|
110
|
+
def render_http_error(exception)
|
111
|
+
"EXCEPTION"
|
99
112
|
end
|
100
113
|
end
|
101
114
|
end
|
data/lib/rango/core_ext.rb
CHANGED
@@ -1,21 +1,104 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
module
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
3
|
+
module Enumerable
|
4
|
+
# similar to
|
5
|
+
def inject!(&block)
|
6
|
+
self.inject(self.class.new, &block)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class String
|
11
|
+
##
|
12
|
+
# Convert to snake case.
|
13
|
+
#
|
14
|
+
# "FooBar".snake_case #=> "foo_bar"
|
15
|
+
# "HeadlineCNNNews".snake_case #=> "headline_cnn_news"
|
16
|
+
# "CNN".snake_case #=> "cnn"
|
17
|
+
#
|
18
|
+
# @return [String] Receiver converted to snake case.
|
19
|
+
#
|
20
|
+
# @api public
|
21
|
+
def snake_case
|
22
|
+
return self.downcase if self =~ /^[A-Z]+$/
|
23
|
+
self.gsub(/([A-Z]+)(?=[A-Z][a-z]?)|\B[A-Z]/, '_\&') =~ /_*(.*)/
|
24
|
+
return $+.downcase
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
# Convert to camel case.
|
29
|
+
#
|
30
|
+
# "foo_bar".camel_case #=> "FooBar"
|
31
|
+
#
|
32
|
+
# @return [String] Receiver converted to camel case.
|
33
|
+
#
|
34
|
+
# @api public
|
35
|
+
def camel_case
|
36
|
+
return self if self !~ /_/ && self =~ /[A-Z]+.*/
|
37
|
+
split('_').map{|e| e.capitalize}.join
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Convert a path string to a constant name.
|
42
|
+
#
|
43
|
+
# "merb/core_ext/string".to_const_string #=> "Merb::CoreExt::String"
|
44
|
+
#
|
45
|
+
# @return [String] Receiver converted to a constant name.
|
46
|
+
#
|
47
|
+
# @api public
|
48
|
+
def to_const_string
|
49
|
+
gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
50
|
+
end
|
51
|
+
|
52
|
+
##
|
53
|
+
# Convert a constant name to a path, assuming a conventional structure.
|
54
|
+
#
|
55
|
+
# "FooBar::Baz".to_const_path # => "foo_bar/baz"
|
56
|
+
#
|
57
|
+
# @return [String] Path to the file containing the constant named by receiver
|
58
|
+
# (constantized string), assuming a conventional structure.
|
59
|
+
#
|
60
|
+
# @api public
|
61
|
+
def to_const_path
|
62
|
+
snake_case.gsub(/::/, "/")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class Hash
|
67
|
+
# Return duplication of self with all keys non-recursively converted to symbols
|
68
|
+
#
|
69
|
+
# @author Botanicus
|
70
|
+
# @since 0.0.2
|
71
|
+
# @return [Hash] A hash with all keys transformed into symbols
|
72
|
+
def symbolize_keys
|
73
|
+
self.inject(Hash.new) do |result, array|
|
74
|
+
result[array.first.to_sym] = array.last
|
75
|
+
result
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# Replace keys in self by coresponding symbols
|
80
|
+
#
|
81
|
+
# @author Botanicus
|
82
|
+
# @since 0.0.2
|
83
|
+
# @return [Hash] A hash with all keys transformed into symbols
|
84
|
+
def symbolize_keys!
|
85
|
+
self.replace(self.symbolize_keys)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Return duplication of self with all keys recursively converted to symbols
|
89
|
+
#
|
90
|
+
# @author Botanicus
|
91
|
+
# @since 0.0.2
|
92
|
+
# @return [Hash] A hash with all keys transformed into symbols even in inner hashes
|
93
|
+
def deep_symbolize_keys
|
94
|
+
self.inject(Hash.new) do |result, array|
|
95
|
+
key, value = array.first, array.last
|
96
|
+
if value.respond_to?(:symbolize_keys)
|
97
|
+
result[key.to_sym] = value.symbolize_keys
|
98
|
+
else
|
99
|
+
result[key.to_sym] = value
|
100
|
+
end
|
101
|
+
result
|
102
|
+
end
|
20
103
|
end
|
21
104
|
end
|
data/lib/rango/environments.rb
CHANGED
@@ -2,25 +2,39 @@
|
|
2
2
|
|
3
3
|
# http://wiki.github.com/botanicus/rango/environments-support
|
4
4
|
|
5
|
-
require "rubyexts/attribute"
|
6
|
-
|
7
5
|
module Rango
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
6
|
+
# @since 0.0.1
|
7
|
+
# @return [String] Returns current environment name.
|
8
|
+
def self.environment
|
9
|
+
@@environment ||= "development"
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.environment=(environment)
|
13
|
+
@@environment = environment
|
14
|
+
end
|
15
|
+
|
16
|
+
# clever environments support
|
17
|
+
def self.environments
|
18
|
+
@@environments ||= {
|
19
|
+
development: ["development"],
|
20
|
+
testing: ["test", "spec", "cucumber"],
|
21
|
+
production: ["stage", "production"]
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.testing?
|
26
|
+
self.environments[:testing].include?(Rango.environment)
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.development?
|
30
|
+
self.environments[:development].include?(Rango.environment)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.production?
|
34
|
+
self.environments[:production].include?(Rango.environment)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.environment?(environment)
|
38
|
+
self.environment.eql?(environment.to_s)
|
25
39
|
end
|
26
40
|
end
|