Class: RailsWayback::Toggle
- Inherits:
-
Object
- Object
- RailsWayback::Toggle
- Defined in:
- lib/rails_wayback/toggle.rb
Overview
Persists whether the engine should be mounted in the host app.
The flag is a plain file inside tmp/rails_wayback/enabled (ignored by
git). We keep it as a file so the CLI, rake tasks and running Rails
process all agree on the same state without booting extra services.
Instance Method Summary collapse
- #disable! ⇒ Object
- #enable! ⇒ Object
- #enabled? ⇒ Boolean
-
#initialize(configuration = RailsWayback.configuration) ⇒ Toggle
constructor
A new instance of Toggle.
- #status ⇒ Object
Constructor Details
#initialize(configuration = RailsWayback.configuration) ⇒ Toggle
Returns a new instance of Toggle.
12 13 14 |
# File 'lib/rails_wayback/toggle.rb', line 12 def initialize(configuration = RailsWayback.configuration) @configuration = configuration end |
Instance Method Details
#disable! ⇒ Object
27 28 29 30 31 |
# File 'lib/rails_wayback/toggle.rb', line 27 def disable! FileUtils.rm_f(configuration.toggle_file_path) touch_routes_reload_marker true end |
#enable! ⇒ Object
20 21 22 23 24 25 |
# File 'lib/rails_wayback/toggle.rb', line 20 def enable! FileUtils.mkdir_p(configuration.toggle_file_path.dirname) FileUtils.touch(configuration.toggle_file_path) touch_routes_reload_marker true end |
#enabled? ⇒ Boolean
16 17 18 |
# File 'lib/rails_wayback/toggle.rb', line 16 def enabled? configuration.toggle_file_path.exist? end |
#status ⇒ Object
33 34 35 |
# File 'lib/rails_wayback/toggle.rb', line 33 def status enabled? ? :on : :off end |