Class: OpenehrRails::RuntimeScaffolder
- Inherits:
-
Object
- Object
- OpenehrRails::RuntimeScaffolder
- Defined in:
- lib/openehr_rails/runtime_scaffolder.rb
Overview
Runs the openehr:scaffold generator from inside a running Rails app (admin engine "Generate UI" action): writes the OPT to its canonical location, invokes the generator, migrates and reloads the routes so the new resource is usable without restarting the server.
Intended for development; gate access with OpenehrRails.runtime_scaffolding_allowed?.
Defined Under Namespace
Classes: Result
Class Method Summary collapse
Instance Method Summary collapse
- #call(migrate: true, reload: true) ⇒ Object
-
#initialize(template, root:) ⇒ RuntimeScaffolder
constructor
A new instance of RuntimeScaffolder.
- #model_name ⇒ Object
- #scaffolded? ⇒ Boolean
Constructor Details
#initialize(template, root:) ⇒ RuntimeScaffolder
Returns a new instance of RuntimeScaffolder.
18 19 20 21 |
# File 'lib/openehr_rails/runtime_scaffolder.rb', line 18 def initialize(template, root:) @template = template @root = Pathname.new(root) end |
Class Method Details
.call(template, root: ::Rails.root) ⇒ Object
14 15 16 |
# File 'lib/openehr_rails/runtime_scaffolder.rb', line 14 def self.call(template, root: ::Rails.root) new(template, root: root).call end |
Instance Method Details
#call(migrate: true, reload: true) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/openehr_rails/runtime_scaffolder.rb', line 23 def call(migrate: true, reload: true) ensure_opt_file run_generator run_migrations if migrate reload_routes if reload Result.new(model_name: model_name, route_path: model_name.pluralize) end |
#model_name ⇒ Object
31 32 33 |
# File 'lib/openehr_rails/runtime_scaffolder.rb', line 31 def model_name OpenehrRails::Naming.model_name(@template.template_id) end |
#scaffolded? ⇒ Boolean
35 36 37 |
# File 'lib/openehr_rails/runtime_scaffolder.rb', line 35 def scaffolded? @root.join("app/models/#{model_name}.rb").exist? end |