Class: Mate::Tmproj

Inherits:
Object
  • Object
show all
Defined in:
lib/mate/tmproj.rb

Defined Under Namespace

Classes: Ignores

Constant Summary collapse

TMPROJ_DIR =
Pathname('~').expand_path + '.tmprojs'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dirs) ⇒ Tmproj

Returns a new instance of Tmproj.



10
11
12
13
14
15
16
# File 'lib/mate/tmproj.rb', line 10

def initialize(dirs)
  @dirs = dirs.map{ |dir| Pathname(dir).expand_path }
  @file = TMPROJ_DIR + [
    Digest::SHA256.hexdigest(@dirs.join('-').downcase),
    "#{common_dir(@dirs).basename}.tmproj"
  ].join('/')
end

Instance Attribute Details

#dirsObject (readonly)

Returns the value of attribute dirs.



9
10
11
# File 'lib/mate/tmproj.rb', line 9

def dirs
  @dirs
end

#fileObject (readonly)

Returns the value of attribute file.



9
10
11
# File 'lib/mate/tmproj.rb', line 9

def file
  @file
end

Instance Method Details

#openObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/mate/tmproj.rb', line 18

def open
  data = Plist::parse_xml(file) rescue {}

  data['documents'] = dirs.map do |dir|
    ignores = Ignores.new(dir)
    {
      :expanded => true,
      :name => dir.basename.to_s,
      :regexFileFilter => "!#{ignores.file_r}",
      :regexFolderFilter => "!#{ignores.folder_r}",
      :sourceDirectory => dir.to_s
    }
  end
  data['fileHierarchyDrawerWidth'] ||= 269
  data['metaData'] ||= {}
  data['showFileHierarchyDrawer'] = true unless data.has_key?('showFileHierarchyDrawer')
  dimensions = IO.popen(%q{osascript -e 'tell application "Finder" to get bounds of window of desktop'}, &:read).scan(/\d+/).map(&:to_i)
  data['windowFrame'] ||= "{{#{dimensions[0] + 100}, #{dimensions[1] + 50}}, {#{dimensions[2] - 200}, #{dimensions[3] - 100}}}"

  file.dirname.mkpath
  file.open('w'){ |f| f.write(data.to_plist) }

  system 'open', file.to_s
end