Class: XcodeSnippets::Snippet
- Inherits:
-
Object
- Object
- XcodeSnippets::Snippet
- Defined in:
- lib/xcode_snippets/snippet.rb
Defined Under Namespace
Classes: MetaData
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#symlink ⇒ Object
readonly
Returns the value of attribute symlink.
Instance Method Summary collapse
- #activate(manifest) ⇒ Object
- #copy_to_bundle(bundle) ⇒ Object
- #deactivate(manifest) ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #guid ⇒ Object
-
#initialize(path, bundle = nil) ⇒ Snippet
constructor
A new instance of Snippet.
- #key ⇒ Object
- #metadata ⇒ Object
- #name ⇒ Object
- #set_guid!(new_guid) ⇒ Object
- #symlinked? ⇒ Boolean
Constructor Details
#initialize(path, bundle = nil) ⇒ Snippet
Returns a new instance of Snippet.
5 6 7 8 |
# File 'lib/xcode_snippets/snippet.rb', line 5 def initialize(path, bundle = nil) @path = path @bundle = bundle end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/xcode_snippets/snippet.rb', line 3 def path @path end |
#symlink ⇒ Object (readonly)
Returns the value of attribute symlink.
3 4 5 |
# File 'lib/xcode_snippets/snippet.rb', line 3 def symlink @symlink end |
Instance Method Details
#activate(manifest) ⇒ Object
20 21 22 23 24 |
# File 'lib/xcode_snippets/snippet.rb', line 20 def activate(manifest) @symlink = manifest.generate_symlink_for_snippet(self) FileUtils.symlink(path, symlink) manifest.add_snippet(self) end |
#copy_to_bundle(bundle) ⇒ Object
15 16 17 18 |
# File 'lib/xcode_snippets/snippet.rb', line 15 def copy_to_bundle(bundle) FileUtils.cp(path, bundle.path) self.class.new(File.join(bundle.path, name), bundle) end |
#deactivate(manifest) ⇒ Object
26 27 28 |
# File 'lib/xcode_snippets/snippet.rb', line 26 def deactivate(manifest) manifest.remove_snippet(self) end |
#delete ⇒ Object
30 31 32 |
# File 'lib/xcode_snippets/snippet.rb', line 30 def delete FileUtils.rm_f(path) end |
#exists? ⇒ Boolean
50 51 52 |
# File 'lib/xcode_snippets/snippet.rb', line 50 def exists? File.exist?(path) end |
#guid ⇒ Object
38 39 40 |
# File 'lib/xcode_snippets/snippet.rb', line 38 def guid .guid end |
#key ⇒ Object
46 47 48 |
# File 'lib/xcode_snippets/snippet.rb', line 46 def key @bundle ? "#{@bundle.name}/#{name}" : name end |
#metadata ⇒ Object
42 43 44 |
# File 'lib/xcode_snippets/snippet.rb', line 42 def @metadata ||= MetaData.from_file(path) end |
#name ⇒ Object
34 35 36 |
# File 'lib/xcode_snippets/snippet.rb', line 34 def name File.basename(@path) end |
#set_guid!(new_guid) ⇒ Object
10 11 12 13 |
# File 'lib/xcode_snippets/snippet.rb', line 10 def set_guid!(new_guid) .guid = new_guid .save_to(path) end |
#symlinked? ⇒ Boolean
54 55 56 |
# File 'lib/xcode_snippets/snippet.rb', line 54 def symlinked? symlink && File.exist?(symlink) end |