-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiny_admin.rb
More file actions
39 lines (31 loc) · 886 Bytes
/
tiny_admin.rb
File metadata and controls
39 lines (31 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true
require "phlex"
require "roda"
require "zeitwerk"
require "forwardable"
require "singleton"
require "yaml"
loader = Zeitwerk::Loader.for_gem
loader.setup
module TinyAdmin
def configure(&block)
block&.call(settings) || settings
end
def configure_from_file(file)
settings.reset!
config = YAML.load_file(file, symbolize_names: true)
config.each do |key, value|
settings[key] = value
end
end
def route_for(section, reference: nil, action: nil, query: nil)
root_path = settings.root_path == "/" ? nil : settings.root_path
route = [root_path, section, reference, action].compact.join("/")
route << "?#{query}" if query
route[0] == "/" ? route : route.prepend("/")
end
def settings
TinyAdmin::Settings.instance
end
module_function :configure, :configure_from_file, :route_for, :settings
end