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



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

#deleteObject



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

def delete
  FileUtils.rm_f(path)
end

#exists?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/xcode_snippets/snippet.rb', line 50

def exists?
  File.exist?(path)
end

#guidObject



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

def guid
  .guid
end

#keyObject



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

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

#metadataObject



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

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

#nameObject



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

Returns:

  • (Boolean)


54
55
56
# File 'lib/xcode_snippets/snippet.rb', line 54

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