Module: Camille::Loader
- Extended by:
- MonitorMixin
- Defined in:
- lib/camille/loader.rb
Class Method Summary collapse
- .check_and_raise_exception ⇒ Object
- .controller_name_to_schema_map ⇒ Object
- .initial_load ⇒ Object
- .loaded_schemas ⇒ Object
- .loaded_types ⇒ Object
- .register_routes(router_context) ⇒ Object
- .reload_types_and_schemas ⇒ Object
- .setup_zeitwerk_loader(app) ⇒ Object
Class Method Details
.check_and_raise_exception ⇒ Object
62 63 64 65 66 |
# File 'lib/camille/loader.rb', line 62 def check_and_raise_exception if @exception raise @exception end end |
.controller_name_to_schema_map ⇒ Object
88 89 90 91 92 |
# File 'lib/camille/loader.rb', line 88 def controller_name_to_schema_map synchronize do @controller_name_to_schema_map ||= {} end end |
.initial_load ⇒ Object
39 40 41 42 43 44 |
# File 'lib/camille/loader.rb', line 39 def initial_load synchronize do eager_load construct_controller_name_to_schema_map end end |
.loaded_schemas ⇒ Object
82 83 84 85 86 |
# File 'lib/camille/loader.rb', line 82 def loaded_schemas synchronize do @loaded_schemas ||= [] end end |
.loaded_types ⇒ Object
76 77 78 79 80 |
# File 'lib/camille/loader.rb', line 76 def loaded_types synchronize do @loaded_types ||= [] end end |
.register_routes(router_context) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/camille/loader.rb', line 68 def register_routes router_context Camille::Loader.loaded_schemas.each do |schema| schema.endpoints.each do |name, endpoint| router_context.public_send(endpoint.verb, endpoint.path, controller: schema.path.gsub(/^\//, ''), action: endpoint.name, as: false) end end end |
.reload_types_and_schemas ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/camille/loader.rb', line 46 def reload_types_and_schemas synchronize do begin @exception = nil Camille::Loader.loaded_types.clear Camille::Loader.loaded_schemas.clear @zeitwerk_loader.reload eager_load construct_controller_name_to_schema_map rescue Exception => e @exception = e raise e end end end |
.setup_zeitwerk_loader(app) ⇒ Object
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 |
# File 'lib/camille/loader.rb', line 9 def setup_zeitwerk_loader app synchronize do loader = Zeitwerk::Loader.new loader.enable_reloading if !app.config.cache_classes types_dir = "#{app.root}/config/camille/types" schemas_dir = "#{app.root}/config/camille/schemas" if Dir.exist? types_dir loader.push_dir types_dir, namespace: Camille::Types else unless inside_generator? puts "[Camille Warning] Expected folder `config/camille/types`. Run `rails g camille:install` to fix it." end end if Dir.exist? schemas_dir loader.push_dir schemas_dir, namespace: Camille::Schemas else unless inside_generator? puts "[Camille Warning] Expected folder `config/camille/schemas`. Run `rails g camille:install` to fix it." end end loader.setup @zeitwerk_loader = loader @configuration_location = "#{app.root}/config/camille/configuration.rb" end end |