Module: Rango

Defined in:
lib/rango/utils.rb,
lib/rango.rb,
lib/rango/gv.rb,
lib/rango/cli.rb,
lib/rango/mini.rb,
lib/rango/mailer.rb,
lib/rango/router.rb,
lib/rango/version.rb,
lib/rango/gv/router.rb,
lib/rango/gv/static.rb,
lib/rango/controller.rb,
lib/rango/exceptions.rb,
lib/rango/mini_render.rb,
lib/rango/environments.rb,
lib/rango/rack/request.rb,
lib/rango/mixins/logger.rb,
lib/rango/mixins/render.rb,
lib/rango/gv/scaffolding.rb,
lib/rango/mixins/filters.rb,
lib/rango/mixins/message.rb,
lib/rango/rest_controller.rb,
lib/rango/mixins/rendering.rb,
lib/rango/mixins/rack-flash.rb,
lib/rango/stacks/controller.rb,
lib/rango/mixins/action_args.rb,
lib/rango/router/adapters/usher.rb,
lib/rango/rack/middlewares/basic.rb,
lib/rango/rack/middlewares/basic.rb,
lib/rango/rack/middlewares/static.rb,
lib/rango/router/adapters/crudtree.rb,
lib/rango/rack/middlewares/encoding.rb,
lib/rango/contrib/pagination/helpers.rb,
lib/rango/router/adapters/rack_mount.rb,
lib/rango/router/adapters/http_router.rb,
lib/rango/contrib/pagination/strategies.rb,
lib/rango/mixins/conventional_rendering.rb,
lib/rango/contrib/pagination/adapters/sequel.rb,
lib/rango/contrib/pagination/adapters/datamapper.rb

Overview

Use with explicit or implicit rendering mixin

Defined Under Namespace

Modules: ActionArgsMixin, ConventionalRendering, Exceptions, ExplicitRendering, FiltersMixin, FormatMixin, GV, Helpers, ImplicitRendering, LoggerMixin, Mailing, MessageMixin, Middlewares, Mini, MiniRender, Pagination, RackDebug, RackFlashMixin, RenderMixin, Session, UrlHelper, Utils Classes: Controller, RESTController, Request, Router, StackController

Constant Summary collapse

VERSION =
"0.2.6"
@@bootloaders =
Hash.new

Class Method Summary collapse

Class Method Details

.after_boot(name, &block) ⇒ Object



106
107
108
# File 'lib/rango.rb', line 106

def self.after_boot(name, &block)
  self.bootloaders[name] = block
end

.boot(options = Hash.new, &block) ⇒ Boolean

Returns true if boot succeed or false if not. If ARGV includes “-i”, IRB interactive session will start.

Examples:

Rango.boot # require init.rb
Rango.boot { require_relative "config/init.rb" } # custom boot

Parameters:

  • options (Hash) (defaults to: Hash.new)

    You can specify flat: true for sinatra-like flat application.

Returns:

  • (Boolean)

    Returns true if boot succeed or false if not. If ARGV includes “-i”, IRB interactive session will start.

Since:

  • 0.0.1



86
87
88
89
90
91
92
93
# File 'lib/rango.rb', line 86

def self.boot(options = Hash.new, &block)
  self.environment = options[:environment] if options[:environment]
  block.call if block_given?
  self.bootloaders.each do |name, bootloader|
    # logger.debug "Calling bootloader #{name}"
    bootloader.call
  end
end

.bootloadersObject



100
101
102
# File 'lib/rango.rb', line 100

def self.bootloaders
  @@bootloaders
end

.development?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/rango/environments.rb', line 19

def self.development?
  self.environments[:development].include?(Rango.environment)
end

.environmentString

Basic environment support. Use rango/environments.rb for more advanced behaviour.

Returns:

  • (String)

    Returns current environment name.

Since:

  • 0.0.1



38
39
40
41
42
# File 'lib/rango.rb', line 38

def self.environment
  @@environment
rescue NameError
  self.set_environment
end

.environment=(environment) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/rango.rb', line 48

def self.environment=(environment)
  ENV["RACK_ENV"] = environment
  @@environment   = environment
  verbose, $VERBOSE = $VERBOSE, nil
  const_set(:RACK_ENV, environment)
  $VERBOSE = verbose
end

.environment?(environment) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/rango.rb', line 56

def self.environment?(environment)
  self.environment.eql?(environment.to_s)
end

.environmentsObject

clever environments support



7
8
9
10
11
12
13
# File 'lib/rango/environments.rb', line 7

def self.environments
  @@environments ||= {
    development: ["development"],
    testing:     ["test", "spec", "cucumber"],
    production:  ["stagging", "production"]
  }
end

.interactiveObject

Start IRB interactive session

Since:

  • 0.0.1



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rango/cli.rb', line 14

def self.interactive
  require "irb"
  require "rango/utils"

  begin
    require "racksh/boot"
  rescue LoadError
    Rango.logger.info("For more goodies install racksh gem")
  else
    Rango::Utils.load_rackup # so you can use Rango::Router.app etc
  end

  begin
    require "irb/completion"
  rescue LoadError
    # some people can have ruby compliled without readline
  end

  ARGV.delete("-i") # otherwise irb will read it
  IRB.start
end

.loaded?(relative_path) ⇒ Boolean

Rango.loaded?(“environments.rb”)

Returns:

  • (Boolean)


111
112
113
114
# File 'lib/rango.rb', line 111

def self.loaded?(relative_path) # would work just with Kernel#require, not with Kernel#load, I know that the name may be misleading, but better than required?
  full_path = File.expand_path(File.join(File.dirname(__FILE__), relative_path))
  $LOADED_FEATURES.any? { |file| file == full_path }
end

.loggerObject

logger



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

def self.logger
  @@logger ||= begin
    require "simple-logger"
    SimpleLogger::Logger.new(STDOUT).tap do |logger|
      logger.auto_flush = true # disable in your code for production!
    end
  rescue LoadError
    require "logger"
    Logger.new(STDOUT).tap do |logger|
      logger.warn("Using stdlib logger. If you want something more fancy with colors and #flush, install simple-logger.")
    end
  end
end

.logger=(logger) ⇒ Object



75
76
77
78
# File 'lib/rango.rb', line 75

def self.logger=(logger)
  require "rango/mixins/logger"
  @@logger = logger.extend(LoggerMixin)
end

.media_rootObject



30
31
32
# File 'lib/rango.rb', line 30

def self.media_root
  @@media_root ||= self.root.join("media")
end

.media_root=(media_root) ⇒ Object



26
27
28
# File 'lib/rango.rb', line 26

def self.media_root=(media_root)
  @@media_root = Pathname.new(media_root)
end

.parse(args = ARGV) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/rango/cli.rb', line 4

def self.parse(args = ARGV)
  return if args.empty?
  # if you will run this script with -i argument, interactive session will begin
  Rango.interactive if ARGV.delete("-i")
  # so it can work as a runner
  load ARGV.shift if ARGV.first && File.exist?(ARGV.first) && ARGV.first.end_with?(".rb")
end

.pathPath

Returns Rango root path.

Examples:

Rango.path
# => /usr/lib/ruby/lib/ruby/site_ruby/1.8/rango

Returns:

  • (Path)

    Rango root path

Since:

  • 0.0.2



16
17
18
# File 'lib/rango/path.rb', line 16

def Rango.path
  @path ||= MediaPath.new(self.root)
end

.production?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rango/environments.rb', line 23

def self.production?
  self.environments[:production].include?(Rango.environment)
end

.reboot(options = Hash.new) ⇒ Object

Since:

  • 0.0.2



96
97
98
# File 'lib/rango.rb', line 96

def self.reboot(options = Hash.new)
  self.boot(options.merge(force: true))
end

.rootObject



22
23
24
# File 'lib/rango.rb', line 22

def self.root
  @@root ||= Pathname.new(Dir.pwd)
end

.root=(root) ⇒ Object



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

def self.root=(root)
  @@root = Pathname.new(root)
end

.set_environmentObject



44
45
46
# File 'lib/rango.rb', line 44

def self.set_environment
  @@environment ||= ENV["RACK_ENV"] || (RACK_ENV if defined?(RACK_ENV)) || "development"
end

.testing?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/rango/environments.rb', line 15

def self.testing?
  self.environments[:testing].include?(Rango.environment)
end