Class: XcodeSnippets::SnippetManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest) ⇒ SnippetManager

Returns a new instance of SnippetManager.



9
10
11
# File 'lib/xcode_snippets/snippet_manager.rb', line 9

def initialize(manifest)
  @manifest = manifest
end

Instance Attribute Details

#manifestObject (readonly)

Returns the value of attribute manifest.



7
8
9
# File 'lib/xcode_snippets/snippet_manager.rb', line 7

def manifest
  @manifest
end

Instance Method Details

#install_snippet(snippet) ⇒ Object



24
25
26
27
28
# File 'lib/xcode_snippets/snippet_manager.rb', line 24

def install_snippet(snippet)
  snippet.activate(manifest)
  save_manifest
  snippet
end

#install_snippet_bundle(path_to_bundle) ⇒ Object



48
49
50
51
52
# File 'lib/xcode_snippets/snippet_manager.rb', line 48

def install_snippet_bundle(path_to_bundle)
  Bundle.new(path_to_bundle).copy_to(manifest.snippets_install_path).tap do |bundle|
    install_snippets(bundle.snippets)
  end
end

#install_snippet_from_path(path_to_snippet) ⇒ Object



13
14
15
# File 'lib/xcode_snippets/snippet_manager.rb', line 13

def install_snippet_from_path(path_to_snippet)
  install_snippet default_bundle.add_copy_of_snippet_from_file(path_to_snippet)
end

#install_snippets(snippets) ⇒ Object



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

def install_snippets(snippets)
  snippets.each { |snippet| snippet.activate(manifest) }
  save_manifest
  snippets
end

#install_snippets_from_paths(snippet_path_list) ⇒ Object



17
18
19
20
21
22
# File 'lib/xcode_snippets/snippet_manager.rb', line 17

def install_snippets_from_paths(snippet_path_list)
  snippets = snippet_path_list.map do |path_to_snippet|
    default_bundle.add_copy_of_snippet_from_file(path_to_snippet)
  end
  install_snippets snippets
end

#save_manifestObject



61
62
63
# File 'lib/xcode_snippets/snippet_manager.rb', line 61

def save_manifest
  manifest.save
end

#uninstall_snippet(snippet) ⇒ Object



42
43
44
45
46
# File 'lib/xcode_snippets/snippet_manager.rb', line 42

def uninstall_snippet(snippet)
  snippet.deactivate(manifest)
  snippet.delete
  save_manifest
end

#uninstall_snippet_bundle_named(bundle_name) ⇒ Object



54
55
56
57
58
59
# File 'lib/xcode_snippets/snippet_manager.rb', line 54

def uninstall_snippet_bundle_named(bundle_name)
  bundle = Bundle.bundle_named(bundle_name, manifest.snippets_install_path)
  bundle.snippets.each { |snippet| uninstall_snippet(snippet) }
  bundle.delete
  save_manifest
end

#uninstall_snippet_named(snippet_name) ⇒ Object



36
37
38
39
40
# File 'lib/xcode_snippets/snippet_manager.rb', line 36

def uninstall_snippet_named(snippet_name)
  if snippet = default_bundle.snippet_named(snippet_name)
    uninstall_snippet(snippet)
  end
end