Class: Sharp::Application

Inherits:
Object
  • Object
show all
Includes:
Logging, Rack
Defined in:
lib/sharp.rb

Constant Summary

Constants included from Rack

Rack::DEFAULT_ENV

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Rack

#delete, #get, #head, included, #post, #put, #route, #router

Methods included from Logging

#attach_logger, #log_file, #log_io, #log_level, #logger, #logger=, #logger_formatter, #objects_logger_is_attached_to

Constructor Details

#initialize(root) ⇒ Application

Returns a new instance of Application.



43
44
45
# File 'lib/sharp.rb', line 43

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

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



41
42
43
# File 'lib/sharp.rb', line 41

def root
  @root
end

Instance Method Details

#bootObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/sharp.rb', line 47

def boot
  unless booted?
    logger.info "Booting Sharp #{VERSION} #{env} #{command}..."
    ms = Benchmark.ms do
      pre_initialization
      load_i18n
      load_load_path
      load_routes
      post_initialization
      finish_boot
    end
    logger.info("Booted in %0.1fms" % ms)
  end
  self
end

#commandSymbol|nil

The command represents what external command is running Sharp. Typical values are:

  • server - A rack server like WEBrick, Thin, Unicorn, Puma, etc.

  • console - An IRB session

If Sharp is just being run in a script or something, this will be nil. You can set this to any value you like using the SHARP_COMMAND environment variable.

Returns:

  • (Symbol|nil)

    The command running sharp



80
81
82
83
84
85
86
# File 'lib/sharp.rb', line 80

def command
  if defined? @command
    @command
  else
    @command = ENV['SHARP_COMMAND'].downcase.to_sym if ENV['SHARP_COMMAND'].present?
  end
end

#configObject



88
89
90
# File 'lib/sharp.rb', line 88

def config
  @config ||= Sharp::Config.new(env, Dir[root.join("config/*.yml")])
end

#envSymbol

This represents which environment is being used. This is controlled via the RACK_ENV environment variable.

Returns:

  • (Symbol)

    The environment



67
68
69
# File 'lib/sharp.rb', line 67

def env
  @env ||= ENV['RACK_ENV'].present? ? ENV['RACK_ENV'].to_sym : :development
end

#load_pathObject



92
93
94
# File 'lib/sharp.rb', line 92

def load_path
  @load_path ||= %w[app/lib app/models app/actions app/views]
end