Class: Sandals::CodeReloader

Inherits:
Object
  • Object
show all
Defined in:
lib/sandals/code_reloader.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ CodeReloader

Returns a new instance of CodeReloader.



9
10
11
12
13
14
15
# File 'lib/sandals/code_reloader.rb', line 9

def initialize(path)
  @path = File.expand_path(path)
  @signature = signature
  @version = 1
  @error = nil
  @mutex = Mutex.new
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/sandals/code_reloader.rb', line 7

def path
  @path
end

Instance Method Details

#checkObject



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

def check
  @mutex.synchronize do
    current_signature = signature
    return result unless current_signature != @signature

    @signature = current_signature
    application = Sandals.load(path)
    @version += 1
    @error = nil
    Result.new(@version, application, nil, true)
  rescue SyntaxError, LoadError, StandardError => error
    @error = error_details(error)
    result(changed: true)
  end
end