class Synx::Project

Constants

DEFAULT_EXCLUSIONS
SYNXRONIZE_DIR

Attributes

delayed_groups_set_path[RW]
group_exclusions[RW]
prune[RW]
sort_by_name[RW]

Public Instance Methods

group_exclusions=(new_exclusions) click to toggle source
# File lib/synx/project.rb, line 97
def group_exclusions=(new_exclusions)
  @group_exclusions = new_exclusions.map do |exclusion|
    # Group paths always start with a '/', so put one there if it isn't already.
    exclusion = "/" + exclusion unless exclusion[0] == "/"
    # Don't check our own default exclusions -- they may not have it in their project.
    unless DEFAULT_EXCLUSIONS.include?(exclusion)
      # remove leading '/' for this check
      exclusionCopy = exclusion.dup
      exclusionCopy[0] = ''
      unless self[exclusionCopy]
        raise IndexError, "No group #{exclusionCopy} exists"
      end
    end
    exclusion
  end
end
has_object_for_pathname?(pathname) click to toggle source
# File lib/synx/project.rb, line 114
def has_object_for_pathname?(pathname)
  @unmodified_project ||= Synx::Project.open(path)
  @unmodified_project.objects.any? do |o|
    begin
      o.real_path.cleanpath == pathname.cleanpath
    rescue
      false
    end
  end
end
pathname_is_inside_root_pathname?(grandchild_pathname) click to toggle source
# File lib/synx/project.rb, line 93
def pathname_is_inside_root_pathname?(grandchild_pathname)
  grandchild_pathname.realpath.to_s.start_with?(root_pathname.realpath.to_s)
end
pathname_to_work_pathname(pathname) click to toggle source

We build up the new project structure in a temporary workspace, so convert a file path in the project space to one in the temp workspace.

# File lib/synx/project.rb, line 85
def pathname_to_work_pathname(pathname)
  work_root_pathname + pathname.relative_path_from(root_pathname)
end
presync_check() click to toggle source
# File lib/synx/project.rb, line 30
def presync_check
  forward_slash_groups = main_group.groups_containing_forward_slash
  unless forward_slash_groups.empty?
    Synx::Tabber.puts "Synx cannot sync projects with groups that contain '/'. Please rename the following groups before running synx again:".yellow
    Synx::Tabber.increase
    forward_slash_groups.each do |group|
      Synx::Tabber.puts group.hierarchy_path
    end
    abort
  end
end
root_pathname() click to toggle source
# File lib/synx/project.rb, line 67
def root_pathname
  @root_pathname ||= Pathname(path).parent
end
sync(options={}) click to toggle source
# File lib/synx/project.rb, line 15
def sync(options={})
  set_options(options)
  presync_check
  Synx::Tabber.increase
  Synx::Tabber.puts "Syncing files that are included in Xcode project...".bold.white
  main_group.all_groups.each { |gr| gr.sync(main_group) }
  Synx::Tabber.puts "\n\n"
  Synx::Tabber.puts "Syncing files that are not included in Xcode project..".bold.white
  main_group.all_groups.each(&:move_entries_not_in_xcodeproj)
  main_group.sort_by_name if self.sort_by_name
  transplant_work_project
  Synx::Tabber.decrease
  save
end
work_pathname_to_pathname(work_pathname) click to toggle source
# File lib/synx/project.rb, line 89
def work_pathname_to_pathname(work_pathname)
  root_pathname + work_pathname.relative_path_from(work_root_pathname)
end
work_root_pathname() click to toggle source
# File lib/synx/project.rb, line 71
def work_root_pathname
  if @work_root_pathname
    @work_root_pathname
  else
    @work_root_pathname = Pathname(File.join(SYNXRONIZE_DIR, root_pathname.basename.to_s))
    # Clean up any previous synx and start fresh
    FileUtils.rm_rf(@work_root_pathname.to_s) if @work_root_pathname.exist?
    @work_root_pathname.mkpath
    @work_root_pathname
  end
end

Private Instance Methods

set_options(options) click to toggle source
# File lib/synx/project.rb, line 42
def set_options(options)
  self.prune = options[:prune]

  if options[:no_default_exclusions]
    self.group_exclusions = []
  else
    self.group_exclusions = DEFAULT_EXCLUSIONS
  end

  self.group_exclusions |= options[:group_exclusions] if options[:group_exclusions]
  self.sort_by_name = !options[:no_sort_by_name]

  Synx::Tabber.options = options
end
transplant_work_project() click to toggle source
# File lib/synx/project.rb, line 58
def transplant_work_project
  # Move the synced entries over
  Dir.glob(work_root_pathname + "*").each do |path|
    FileUtils.rm_rf(work_pathname_to_pathname(Pathname(path)))
    FileUtils.mv(path, root_pathname.to_s)
  end
end