Class: XcodeSnippets::Manifest
- Inherits:
-
Object
- Object
- XcodeSnippets::Manifest
- Defined in:
- lib/xcode_snippets/manifest.rb
Defined Under Namespace
Classes: UUIDGenerator
Instance Attribute Summary collapse
-
#snippets_install_path ⇒ Object
readonly
Returns the value of attribute snippets_install_path.
Class Method Summary collapse
Instance Method Summary collapse
- #add_snippet(snippet) ⇒ Object
- #add_snippet!(snippet) ⇒ Object
- #generate_guid ⇒ Object
- #generate_symlink_for_snippet(snippet) ⇒ Object
- #has_snippet?(snippet) ⇒ Boolean
-
#initialize(snippets_install_path, xcode_snippets_install_path, uuid_generator = UUIDGenerator) ⇒ Manifest
constructor
A new instance of Manifest.
- #load ⇒ Object
- #remove_snippet(snippet) ⇒ Object
- #remove_snippet!(snippet) ⇒ Object
- #save ⇒ Object
- #symlink_for_snippet(snippet) ⇒ Object
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_path ⇒ Object (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_guid ⇒ Object
59 60 61 |
# File 'lib/xcode_snippets/manifest.rb', line 59 def generate_guid @uuid_generator.generate end |
#generate_symlink_for_snippet(snippet) ⇒ Object
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
36 37 38 |
# File 'lib/xcode_snippets/manifest.rb', line 36 def has_snippet?(snippet) @data[snippet.key] && @data[snippet.key] == snippet.symlink end |
#load ⇒ Object
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 |
#save ⇒ Object
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 |
#symlink_for_snippet(snippet) ⇒ Object
50 51 52 |
# File 'lib/xcode_snippets/manifest.rb', line 50 def symlink_for_snippet(snippet) @data[snippet.key] end |