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
-
#initialize(path, bundle = nil) ⇒ Snippet
constructor
A new instance of Snippet.
- #key ⇒ Object
- #metadata ⇒ Object
- #name ⇒ 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
15 16 17 18 19 |
# File 'lib/xcode_snippets/snippet.rb', line 15 def activate(manifest) @symlink = manifest.generate_new_symlink FileUtils.symlink(path, symlink) manifest.add_snippet(self) end |
#copy_to_bundle(bundle) ⇒ Object
10 11 12 13 |
# File 'lib/xcode_snippets/snippet.rb', line 10 def copy_to_bundle(bundle) FileUtils.cp(path, bundle.path) self.class.new(File.join(bundle.path, name), bundle) end |
#deactivate(manifest) ⇒ Object
21 22 23 |
# File 'lib/xcode_snippets/snippet.rb', line 21 def deactivate(manifest) manifest.remove_snippet(self) end |
#delete ⇒ Object
25 26 27 |
# File 'lib/xcode_snippets/snippet.rb', line 25 def delete FileUtils.rm_f(path) end |
#exists? ⇒ Boolean
41 42 43 |
# File 'lib/xcode_snippets/snippet.rb', line 41 def exists? File.exist?(path) end |
#key ⇒ Object
37 38 39 |
# File 'lib/xcode_snippets/snippet.rb', line 37 def key @bundle ? "#{@bundle.name}/#{name}" : name end |
#metadata ⇒ Object
33 34 35 |
# File 'lib/xcode_snippets/snippet.rb', line 33 def @metadata ||= MetaData.from_file(path) end |
#name ⇒ Object
29 30 31 |
# File 'lib/xcode_snippets/snippet.rb', line 29 def name File.basename(@path) end |
#symlinked? ⇒ Boolean
45 46 47 |
# File 'lib/xcode_snippets/snippet.rb', line 45 def symlinked? symlink && File.exist?(symlink) end |