Module: Dotsync::MappingsTransfer

Extended by:
Forwardable
Includes:
PathUtils
Included in:
PullAction, PushAction, WatchAction
Defined in:
lib/dotsync/actions/concerns/mappings_transfer.rb

Constant Summary collapse

MAPPINGS_LEGEND =
[
  [Icons.force, "The source will overwrite the destination"],
  [Icons.only, "Paths designated explicitly as source only"],
  [Icons.ignore, "Paths configured to be ignored in the destination"],
  [Icons.invalid, "Invalid paths detected in the source or destination"]
]
DIFFERENCES_LEGEND =
[
  [Icons.diff_created, "Created/added file"],
  [Icons.diff_updated, "Updated/modified file"],
  [Icons.diff_removed, "Removed/deleted file"]
]

Constants included from PathUtils

PathUtils::ENV_VARS_COLOR

Instance Method Summary collapse

Methods included from PathUtils

#colorize_env_vars, #expand_env_vars, #extract_env_vars, #path_is_parent_or_same?, #relative_to_absolute, #sanitize_path, #translate_tmp_path

Instance Method Details

#show_differencesObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/dotsync/actions/concerns/mappings_transfer.rb', line 65

def show_differences
  info("Differences:", icon: :diff)
  differs.flat_map(&:additions).sort.each do |path|
    logger.log("#{Icons.diff_created}#{path}", color: Colors.diff_additions)
  end
  differs.flat_map(&:modifications).sort.each do |path|
    logger.log("#{Icons.diff_updated}#{path}", color: Colors.diff_modifications)
  end
  differs.flat_map(&:removals).sort.each do |path|
    logger.log("#{Icons.diff_removed}#{path}", color: Colors.diff_removals)
  end
  logger.log("  No differences") unless has_differences?
  logger.log("")
end

#show_differences_legendObject



58
59
60
61
62
63
# File 'lib/dotsync/actions/concerns/mappings_transfer.rb', line 58

def show_differences_legend
  info("Differences Legend:", icon: :legend)
  table = Terminal::Table.new(rows: DIFFERENCES_LEGEND)
  logger.log(table)
  logger.log("")
end

#show_env_varsObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dotsync/actions/concerns/mappings_transfer.rb', line 24

def show_env_vars
  env_vars = mappings_env_vars
  return unless env_vars.any?

  info("Environment variables:", icon: :env_vars)

  rows = env_vars.map { |env_var| [env_var, ENV[env_var]] }.sort_by(&:first)
  table = Terminal::Table.new(rows: rows)
  logger.log(table)
  logger.log("")
end

#show_mappingsObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dotsync/actions/concerns/mappings_transfer.rb', line 43

def show_mappings
  info("Mappings:", icon: :config)

  rows = mappings.map do |mapping|
    [
      mapping.icons,
      colorize_env_vars(mapping.original_src),
      colorize_env_vars(mapping.original_dest)
    ]
  end
  table = Terminal::Table.new(headings: ["Flags", "Source", "Destination"], rows: rows)
  logger.log(table)
  logger.log("")
end

#show_mappings_legendObject



36
37
38
39
40
41
# File 'lib/dotsync/actions/concerns/mappings_transfer.rb', line 36

def show_mappings_legend
  info("Mappings Legend:", icon: :legend)
  table = Terminal::Table.new(rows: MAPPINGS_LEGEND)
  logger.log(table)
  logger.log("")
end

#transfer_mappingsObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/dotsync/actions/concerns/mappings_transfer.rb', line 80

def transfer_mappings
  valid_mappings.each do |mapping|
    Dotsync::FileTransfer.new(mapping).transfer
  rescue Dotsync::PermissionError => e
    logger.error("Permission denied: #{e.message}")
    logger.info("Try: chmod +w <path> or check file permissions")
  rescue Dotsync::DiskFullError => e
    logger.error("Disk full: #{e.message}")
    logger.info("Free up disk space and try again")
  rescue Dotsync::SymlinkError => e
    logger.error("Symlink error: #{e.message}")
    logger.info("Check that symlink target exists and is accessible")
  rescue Dotsync::TypeConflictError => e
    logger.error("Type conflict: #{e.message}")
    logger.info("Cannot overwrite directory with file or vice versa")
  rescue Dotsync::FileTransferError => e
    logger.error("File transfer failed: #{e.message}")
  end
end