Class: Twin::Job

Inherits:
Struct
  • Object
show all
Defined in:
lib/twin/scanner.rb

Overview

One YAML block from a sync-file, enriched with live filesystem state.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#activeObject

Returns the value of attribute active

Returns:

  • (Object)

    the current value of active



8
9
10
# File 'lib/twin/scanner.rb', line 8

def active
  @active
end

#cmdObject

Returns the value of attribute cmd

Returns:

  • (Object)

    the current value of cmd



8
9
10
# File 'lib/twin/scanner.rb', line 8

def cmd
  @cmd
end

#conflictObject

Returns the value of attribute conflict

Returns:

  • (Object)

    the current value of conflict



8
9
10
# File 'lib/twin/scanner.rb', line 8

def conflict
  @conflict
end

#deleteObject

Returns the value of attribute delete

Returns:

  • (Object)

    the current value of delete



8
9
10
# File 'lib/twin/scanner.rb', line 8

def delete
  @delete
end

#descriptionObject

Returns the value of attribute description

Returns:

  • (Object)

    the current value of description



8
9
10
# File 'lib/twin/scanner.rb', line 8

def description
  @description
end

#excludesObject

Returns the value of attribute excludes

Returns:

  • (Object)

    the current value of excludes



8
9
10
# File 'lib/twin/scanner.rb', line 8

def excludes
  @excludes
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



8
9
10
# File 'lib/twin/scanner.rb', line 8

def label
  @label
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



8
9
10
# File 'lib/twin/scanner.rb', line 8

def path
  @path
end

#programObject

Returns the value of attribute program

Returns:

  • (Object)

    the current value of program



8
9
10
# File 'lib/twin/scanner.rb', line 8

def program
  @program
end

#renderObject

Returns the value of attribute render

Returns:

  • (Object)

    the current value of render



8
9
10
# File 'lib/twin/scanner.rb', line 8

def render
  @render
end

#render_outdatedObject

Returns the value of attribute render_outdated

Returns:

  • (Object)

    the current value of render_outdated



8
9
10
# File 'lib/twin/scanner.rb', line 8

def render_outdated
  @render_outdated
end

#sourceObject

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



8
9
10
# File 'lib/twin/scanner.rb', line 8

def source
  @source
end

#source_existsObject

Returns the value of attribute source_exists

Returns:

  • (Object)

    the current value of source_exists



8
9
10
# File 'lib/twin/scanner.rb', line 8

def source_exists
  @source_exists
end

#source_mtimeObject

Returns the value of attribute source_mtime

Returns:

  • (Object)

    the current value of source_mtime



8
9
10
# File 'lib/twin/scanner.rb', line 8

def source_mtime
  @source_mtime
end

#sync_fileObject

Returns the value of attribute sync_file

Returns:

  • (Object)

    the current value of sync_file



8
9
10
# File 'lib/twin/scanner.rb', line 8

def sync_file
  @sync_file
end

#targetObject

Returns the value of attribute target

Returns:

  • (Object)

    the current value of target



8
9
10
# File 'lib/twin/scanner.rb', line 8

def target
  @target
end

#target_existsObject

Returns the value of attribute target_exists

Returns:

  • (Object)

    the current value of target_exists



8
9
10
# File 'lib/twin/scanner.rb', line 8

def target_exists
  @target_exists
end

#target_mtimeObject

Returns the value of attribute target_mtime

Returns:

  • (Object)

    the current value of target_mtime



8
9
10
# File 'lib/twin/scanner.rb', line 8

def target_mtime
  @target_mtime
end

#target_path_fieldObject

Returns the value of attribute target_path_field

Returns:

  • (Object)

    the current value of target_path_field



8
9
10
# File 'lib/twin/scanner.rb', line 8

def target_path_field
  @target_path_field
end

#target_unreachableObject

Returns the value of attribute target_unreachable

Returns:

  • (Object)

    the current value of target_unreachable



8
9
10
# File 'lib/twin/scanner.rb', line 8

def target_unreachable
  @target_unreachable
end

Instance Method Details

#remote?Boolean

Returns:

  • (Boolean)


17
# File 'lib/twin/scanner.rb', line 17

def remote?     = Twin::Remote.remote?(target)

#source_pathObject



15
# File 'lib/twin/scanner.rb', line 15

def source_path = File.join(source, path)

#statusObject



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

def status
  return :disabled if active != 1
  return :unreachable if target_unreachable
  return :both_missing if !source_exists && !target_exists
  return :missing_source unless source_exists
  return :missing_target unless target_exists
  # Render jobs compare by content, not mtime — a rendered target's mtime
  # bears no relation to the template's.
  return render_outdated ? :source_newer : :in_sync if render
  return :target_newer if conflict
  return :in_sync if source_mtime.nil? || target_mtime.nil?
  delta = source_mtime - target_mtime
  return :in_sync if delta.abs < 60
  delta > 0 ? :source_newer : :target_newer
end

#target_pathObject



16
# File 'lib/twin/scanner.rb', line 16

def target_path = File.join(target, target_path_field || path)