Class: XcodeSnippets::Snippet

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

Defined Under Namespace

Classes: MetaData

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/xcode_snippets/snippet.rb', line 3

def path
  @path
end

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

#deleteObject



25
26
27
# File 'lib/xcode_snippets/snippet.rb', line 25

def delete
  FileUtils.rm_f(path)
end

#exists?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/xcode_snippets/snippet.rb', line 41

def exists?
  File.exist?(path)
end

#keyObject



37
38
39
# File 'lib/xcode_snippets/snippet.rb', line 37

def key
  @bundle ? "#{@bundle.name}/#{name}" : name
end

#metadataObject



33
34
35
# File 'lib/xcode_snippets/snippet.rb', line 33

def 
  @metadata ||= MetaData.from_file(path)
end

#nameObject



29
30
31
# File 'lib/xcode_snippets/snippet.rb', line 29

def name
  File.basename(@path)
end

#symlinked?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/xcode_snippets/snippet.rb', line 45

def symlinked?
  symlink && File.exist?(symlink)
end