Module: PUNK
- Extended by:
- SingleForwardable
- Includes:
- SemanticLogger::Loggable
- Defined in:
- lib/punk.rb,
lib/punk/core/app.rb,
lib/punk/core/env.rb,
lib/punk/core/exec.rb,
lib/punk/core/error.rb,
lib/punk/views/fail.rb,
lib/punk/views/info.rb,
lib/punk/core/logger.rb,
lib/punk/core/version.rb,
lib/punk/core/commands.rb,
lib/punk/core/settings.rb,
lib/punk/core/interface.rb,
lib/punk/framework/view.rb,
lib/punk/framework/model.rb,
lib/punk/framework/action.rb,
lib/punk/framework/worker.rb,
lib/punk/helpers/loggable.rb,
lib/punk/startup/database.rb,
lib/punk/framework/command.rb,
lib/punk/framework/service.rb,
lib/punk/framework/runnable.rb,
lib/punk/helpers/renderable.rb,
lib/punk/helpers/publishable.rb,
lib/punk/helpers/validatable.rb,
lib/punk/framework/plugins/validation.rb
Defined Under Namespace
Modules: Loggable, Plugins, Publishable, Renderable, Validatable
Classes: Action, App, BadRequest, Command, Env, Fail, Forbidden, Info, InternalServerError, Model, NotFound, NotImplemented, Runnable, Service, Settings, Unauthorized, View, Worker
Constant Summary
collapse
- ROUTES =
Tempfile.new("routes.json").path
- Interface =
Dim::Container.new
Class Method Summary
collapse
Class Method Details
.commands(target, scope = nil) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/punk/core/commands.rb', line 6
def self.commands(target, scope=nil)
path = File.expand_path(File.join(__dir__, '..', 'commands'))
PUNK.profile_debug("commands", path: path) do
Dir.glob(File.join(path, '**/*.rb')).sort.each { |file| require(file) }
end
path = File.expand_path(File.join(PUNK.get.app.path, 'commands'))
PUNK.profile_debug("commands", path: path) do
Dir.glob(File.join(path, '**/*.rb')).sort.each { |file| require(file) }
end
case target
when :commander
require_relative 'commander'
Command.commander
when :pry
require_relative 'pry'
Command.pry
when :spec
Command.spec(scope)
end
end
|
.env ⇒ Object
277
278
279
|
# File 'lib/punk/core/env.rb', line 277
def self.env
PUNK.get.env
end
|
.init(task: 'server', path: './app', config: {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/punk.rb', line 20
def self.init(task: 'server', path: './app', config: {})
require_relative 'punk/core/interface'
raise InternalServerError, 'Cannot call PUNK.init multiple times!' if state != :included
store.args = OpenStruct.new(
task: task,
path: path,
config: config
)
store.state = :initialised
Interface.bootstrap
self
end
|
.inject(*methods) ⇒ Object
22
23
24
|
# File 'lib/punk/core/interface.rb', line 22
def self.inject(*methods)
def_single_delegators :'PUNK::Interface', *methods
end
|
.migration(&block) ⇒ Object
43
44
45
|
# File 'lib/punk/startup/database.rb', line 43
def self.migration(&block)
Sequel::MigrationDSL.create(&block)
end
|
.profile_debug(name, **kwargs) ⇒ Object
13
14
15
16
|
# File 'lib/punk/core/logger.rb', line 13
def self.profile_debug(name, **kwargs)
logger.debug "Started #{name}", kwargs.sanitize.inspect
logger.measure_debug("Completed #{name}") { logger.tagged(name) { yield } }
end
|
.profile_info(name, **kwargs) ⇒ Object
8
9
10
11
|
# File 'lib/punk/core/logger.rb', line 8
def self.profile_info(name, **kwargs)
logger.info "Started #{name}", kwargs.sanitize.inspect
logger.measure_info("Completed #{name}") { logger.tagged(name) { yield } }
end
|
.profile_trace(name, **kwargs) ⇒ Object
18
19
20
21
|
# File 'lib/punk/core/logger.rb', line 18
def self.profile_trace(name, **kwargs)
logger.trace "Started #{name}", kwargs.sanitize.inspect
logger.measure_trace("Completed #{name}") { logger.tagged(name) { yield } }
end
|
.require_all(path) ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/punk/core/exec.rb', line 4
def self.require_all(path)
path = File.expand_path(path)
PUNK.profile_debug("require_all", path: path) do
if PUNK.get.app.reloadable?
PUNK.loader.require(path)
else
Dir.glob(File.join(path, '**/*.rb')).sort.each { |file| require(file) }
end
end
end
|
.route(name, &block) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/punk/core/app.rb', line 16
def self.route(name, &block)
PUNK.profile_info("route", path: name) do
PUNK::App.route(name) do |r|
r.scope.instance_exec(&block)
end
end
end
|
.task ⇒ Object
281
282
283
|
# File 'lib/punk/core/env.rb', line 281
def self.task
PUNK.get.task
end
|
.version ⇒ Object
4
5
6
|
# File 'lib/punk/core/version.rb', line 4
def self.version
File.read(File.join(__dir__, '..', '..', '..', 'VERSION'))
end
|