Class: RailsLiveReload::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_live_reload/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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

#enabledObject

Returns the value of attribute enabled.



22
23
24
# File 'lib/rails_live_reload/config.rb', line 22

def enabled
  @enabled
end

#filesObject

Returns the value of attribute files.



22
23
24
# File 'lib/rails_live_reload/config.rb', line 22

def files
  @files
end

#patternsObject (readonly)

Returns the value of attribute patterns.



21
22
23
# File 'lib/rails_live_reload/config.rb', line 21

def patterns
  @patterns
end

#urlObject

Returns the value of attribute url.



22
23
24
# File 'lib/rails_live_reload/config.rb', line 22

def url
  @url
end

#watcherObject

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_pathObject



38
39
40
# File 'lib/rails_live_reload/config.rb', line 38

def root_path
  @root_path ||= ::Rails.application.root
end

#socket_pathObject



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