Class: Guard::HotReload

Inherits:
Plugin
  • Object
show all
Defined in:
lib/lanes/hot_reload_plugin.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HotReload

Returns a new instance of HotReload.



6
7
8
9
10
11
12
# File 'lib/lanes/hot_reload_plugin.rb', line 6

def initialize(options = {})
    super
    api = Lanes.config.api_path
    @uri = URI.parse(
        "http://localhost:#{options[:port]}#{api}/dev-file-change.json"
    )
end

Instance Method Details

#asset_to_json(file) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lanes/hot_reload_plugin.rb', line 17

def asset_to_json(file)
    file.gsub!(/client\//,'')
    if file.match(/\.(js|coffee|cjsx)$/)
        file.gsub!(/(.*)\.(js|coffee|cjsx)$/, '\1.js')
        comp = file.split('/')#[1..-1]
        comp[comp.length-1] = comp.last.gsub(/\.\w+$/,'')
        { "type" => "js", "path" => file, "components" => comp }
    else
        path = if file.match(%r{/screens/.*/\w+\.scss})
                   file.gsub(%r{/\w+.\w*css},'.css')
               else
                   file
               end
        { "type" => "css", "path" => path, "trigger" => file }
    end

end

#run_allObject



14
15
# File 'lib/lanes/hot_reload_plugin.rb', line 14

def run_all
end

#run_on_modifications(paths) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/lanes/hot_reload_plugin.rb', line 35

def run_on_modifications(paths)
    post = Net::HTTP::Post.new(@uri.request_uri)
    body = paths.map do | file |
        asset_to_json(file)
    end
    post.body = Oj.dump(body)
    http = Net::HTTP.new(@uri.host, @uri.port)
    http.request(post)
end