Class: LiveReload::Config

Inherits:
Object show all
Defined in:
lib/livereload.rb

Overview

note that host and port options do not make sense in per-project config files

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Config

Returns a new instance of Config.



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/livereload.rb', line 55

def initialize &block
  @host           = nil
  @port           = nil
  @debug          = nil
  @exts           = []
  @exclusions     = []
  @apply_js_live  = nil
  @apply_css_live = nil
  @apply_images_live = nil
  @grace_period   = nil

  update!(&block) if block
end

Instance Attribute Details

#apply_css_liveObject

Returns the value of attribute apply_css_live.



53
54
55
# File 'lib/livereload.rb', line 53

def apply_css_live
  @apply_css_live
end

#apply_images_liveObject

Returns the value of attribute apply_images_live.



53
54
55
# File 'lib/livereload.rb', line 53

def apply_images_live
  @apply_images_live
end

#apply_js_liveObject

Returns the value of attribute apply_js_live.



53
54
55
# File 'lib/livereload.rb', line 53

def apply_js_live
  @apply_js_live
end

#debugObject

Returns the value of attribute debug.



53
54
55
# File 'lib/livereload.rb', line 53

def debug
  @debug
end

#exclusionsObject

Returns the value of attribute exclusions.



53
54
55
# File 'lib/livereload.rb', line 53

def exclusions
  @exclusions
end

#extsObject

Returns the value of attribute exts.



53
54
55
# File 'lib/livereload.rb', line 53

def exts
  @exts
end

#exts_overwriteObject

Returns the value of attribute exts_overwrite.



53
54
55
# File 'lib/livereload.rb', line 53

def exts_overwrite
  @exts_overwrite
end

#grace_periodObject

Returns the value of attribute grace_period.



53
54
55
# File 'lib/livereload.rb', line 53

def grace_period
  @grace_period
end

#hostObject

Returns the value of attribute host.



53
54
55
# File 'lib/livereload.rb', line 53

def host
  @host
end

#portObject

Returns the value of attribute port.



53
54
55
# File 'lib/livereload.rb', line 53

def port
  @port
end

Class Method Details

.load_from(file) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/livereload.rb', line 100

def load_from file
  Config.new do |config|
    if File.file? file
      Object.send(:instance_variable_set, '@livereload_config', config)
      Object.send(:alias_method, :method_missing_without_livereload, :method_missing)
      Object.send(:alias_method, :method_missing, :method_missing_with_livereload)
      load file, true
      Object.send(:alias_method, :method_missing, :method_missing_without_livereload)
      Object.send(:instance_variable_set, '@livereload_config', nil)
    end
  end
end

.merge(*configs) ⇒ Object



113
114
115
# File 'lib/livereload.rb', line 113

def merge *configs
  configs.inject(Config.new) { |merged, config| config && merged.merge!(config) || merged }
end

Instance Method Details

#merge!(other) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/livereload.rb', line 81

def merge! other
  @host           = other.host             if other.host
  @port           = other.port             if other.port
  if other.exts_overwrite
    @exts         = other.exts
  else
    @exts        += other.exts.compact
  end
  @exclusions     = other.exclusions + @exclusions
  @debug          = other.debug            if other.debug != nil
  @apply_js_live  = other.apply_js_live    if other.apply_js_live != nil
  @apply_css_live = other.apply_css_live   if other.apply_css_live != nil
  @apply_images_live = other.apply_images_live if other.apply_images_live != nil
  @grace_period   = other.grace_period     if other.grace_period != nil

  self
end

#update! {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/livereload.rb', line 69

def update!
  @exts = [nil] + @exts  # nil is used as a marker to detect if the array has been overwritten

  yield self

  @exts_overwrite = @exts.empty? || ! @exts.first.nil?
  @exts = @exts.compact

  # remove leading dots
  @exts = @exts.collect { |e| e.sub(/^\./, '') }
end