Class: XcodeSnippets::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode_snippets/manifest.rb

Defined Under Namespace

Classes: UUIDGenerator

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(snippets_install_path, xcode_snippets_install_path, uuid_generator = UUIDGenerator) ⇒ Manifest

Returns a new instance of Manifest.



7
8
9
10
11
12
# File 'lib/xcode_snippets/manifest.rb', line 7

def initialize(snippets_install_path, xcode_snippets_install_path, uuid_generator = UUIDGenerator)
  @snippets_install_path = snippets_install_path
  @xcode_snippets_install_path = xcode_snippets_install_path
  @uuid_generator = uuid_generator
  @data = {}
end

Instance Attribute Details

#snippets_install_pathObject (readonly)

Returns the value of attribute snippets_install_path.



5
6
7
# File 'lib/xcode_snippets/manifest.rb', line 5

def snippets_install_path
  @snippets_install_path
end

Class Method Details

.load(snippets_install_path, xcode_snippets_install_path, uuid_generator = UUIDGenerator) ⇒ Object



14
15
16
# File 'lib/xcode_snippets/manifest.rb', line 14

def self.load(snippets_install_path, xcode_snippets_install_path, uuid_generator = UUIDGenerator)
  new(snippets_install_path, xcode_snippets_install_path, uuid_generator).tap { |manifest| manifest.load }
end

Instance Method Details

#add_snippet(snippet) ⇒ Object



18
19
20
# File 'lib/xcode_snippets/manifest.rb', line 18

def add_snippet(snippet)
  @data[snippet.key] = snippet.symlink
end

#add_snippet!(snippet) ⇒ Object



22
23
24
25
# File 'lib/xcode_snippets/manifest.rb', line 22

def add_snippet!(snippet)
  add_snippet(snippet)
  save
end

#generate_guidObject



59
60
61
# File 'lib/xcode_snippets/manifest.rb', line 59

def generate_guid
  @uuid_generator.generate
end


54
55
56
57
# File 'lib/xcode_snippets/manifest.rb', line 54

def generate_symlink_for_snippet(snippet)
  snippet.set_guid!(generate_guid)
  File.join(@xcode_snippets_install_path, "#{snippet.guid}.codesnippet")
end

#has_snippet?(snippet) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/xcode_snippets/manifest.rb', line 36

def has_snippet?(snippet)
  @data[snippet.key] && @data[snippet.key] == snippet.symlink
end

#loadObject



46
47
48
# File 'lib/xcode_snippets/manifest.rb', line 46

def load
  @data = Plist.parse_xml(path) || {}
end

#remove_snippet(snippet) ⇒ Object



27
28
29
# File 'lib/xcode_snippets/manifest.rb', line 27

def remove_snippet(snippet)
  @data.delete(snippet.key)
end

#remove_snippet!(snippet) ⇒ Object



31
32
33
34
# File 'lib/xcode_snippets/manifest.rb', line 31

def remove_snippet!(snippet)
  remove_snippet(snippet)
  save
end

#saveObject



40
41
42
43
44
# File 'lib/xcode_snippets/manifest.rb', line 40

def save
  File.open(path, "w") do |io|
    io.write @data.to_plist
  end
end


50
51
52
# File 'lib/xcode_snippets/manifest.rb', line 50

def symlink_for_snippet(snippet)
  @data[snippet.key]
end