Class: Syntropy::Module
- Inherits:
-
Object
- Object
- Syntropy::Module
- Defined in:
- lib/syntropy/module.rb
Class Method Summary collapse
- .__export_value__ ⇒ Object
- .env=(env) ⇒ Object
- .export(ref) ⇒ Object
- .import(ref) ⇒ Object
- .loader=(loader) ⇒ Object
- .route_by_host ⇒ Object
- .template(&block) ⇒ Object
Instance Method Summary collapse
-
#initialize(env) ⇒ Module
constructor
A new instance of Module.
Constructor Details
#initialize(env) ⇒ Module
Returns a new instance of Module.
62 63 64 |
# File 'lib/syntropy/module.rb', line 62 def initialize(env) @env = env end |
Class Method Details
.__export_value__ ⇒ Object
102 103 104 |
# File 'lib/syntropy/module.rb', line 102 def self.__export_value__ @__export_value__ end |
.env=(env) ⇒ Object
70 71 72 |
# File 'lib/syntropy/module.rb', line 70 def self.env=(env) @env = env end |
.export(ref) ⇒ Object
78 79 80 |
# File 'lib/syntropy/module.rb', line 78 def self.export(ref) @__export_value__ = ref end |
.import(ref) ⇒ Object
74 75 76 |
# File 'lib/syntropy/module.rb', line 74 def self.import(ref) @loader.load(ref) end |
.loader=(loader) ⇒ Object
66 67 68 |
# File 'lib/syntropy/module.rb', line 66 def self.loader=(loader) @loader = loader end |
.route_by_host ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/syntropy/module.rb', line 86 def self.route_by_host root = @env[:location] sites = Dir[File.join(root, '*')] .select { File.directory?(it) } .inject({}) { |h, fn| name = File.basename(fn) opts = @env.merge(location: fn) h[name] = Syntropy::App.new(opts[:machine], opts[:location], opts[:mount_path], opts) h } ->(req) { site = sites[req.host] site ? site.call(req) : req.respond(nil, ':status' => Status::BAD_REQUEST) } end |
.template(&block) ⇒ Object
82 83 84 |
# File 'lib/syntropy/module.rb', line 82 def self.template(&block) Papercraft.html(&block) end |