Class: RailsLiveReload::Config
- Inherits:
-
Object
- Object
- RailsLiveReload::Config
- Defined in:
- lib/rails_live_reload/config.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#files ⇒ Object
Returns the value of attribute files.
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
-
#url ⇒ Object
Returns the value of attribute url.
-
#watcher ⇒ Object
Returns the value of attribute watcher.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #root_path ⇒ Object
- #socket_path ⇒ Object
- #watch(pattern, reload: :on_change) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rails_live_reload/config.rb', line 24 def initialize @url = "/rails/live/reload" @watcher = nil @files = {} @enabled = ::Rails.env.development? # These configs work for 95% apps, see README for more info @patterns = { %r{app/views/.+\.(erb|haml|slim)$} => :on_change, %r{(app|vendor)/(assets|javascript)/\w+/(.+\.(css|js|html|png|jpg|ts|jsx)).*} => :always } @default_patterns_changed = false end |
Instance Attribute Details
#enabled ⇒ Object
Returns the value of attribute enabled.
22 23 24 |
# File 'lib/rails_live_reload/config.rb', line 22 def enabled @enabled end |
#files ⇒ Object
Returns the value of attribute files.
22 23 24 |
# File 'lib/rails_live_reload/config.rb', line 22 def files @files end |
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
21 22 23 |
# File 'lib/rails_live_reload/config.rb', line 21 def patterns @patterns end |
#url ⇒ Object
Returns the value of attribute url.
22 23 24 |
# File 'lib/rails_live_reload/config.rb', line 22 def url @url end |
#watcher ⇒ Object
Returns the value of attribute watcher.
22 23 24 |
# File 'lib/rails_live_reload/config.rb', line 22 def watcher @watcher end |
Instance Method Details
#root_path ⇒ Object
38 39 40 |
# File 'lib/rails_live_reload/config.rb', line 38 def root_path @root_path ||= ::Rails.application.root end |
#socket_path ⇒ Object
51 52 53 54 55 56 57 58 59 |
# File 'lib/rails_live_reload/config.rb', line 51 def socket_path root_path.join('tmp/sockets/rails_live_reload.sock').then do |path| break path if path.to_s.size <= 104 # 104 is the max length of a socket path puts "Unable to create socket path inside the project, using /tmp instead" app_name = ::Rails.application.class.name.split('::').first.underscore Pathname.new("/tmp/rails_live_reload_#{app_name}.sock") end end |
#watch(pattern, reload: :on_change) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/rails_live_reload/config.rb', line 42 def watch(pattern, reload: :on_change) unless @default_patterns_changed @default_patterns_changed = true @patterns = {} end patterns[pattern] = reload end |