Class: XcodeSnippets::Bundle
- Inherits:
-
Object
- Object
- XcodeSnippets::Bundle
- Defined in:
- lib/xcode_snippets/bundle.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#snippets ⇒ Object
readonly
Returns the value of attribute snippets.
Class Method Summary collapse
Instance Method Summary collapse
- #add_copy_of_snippet(snippet) ⇒ Object
- #add_copy_of_snippet_from_file(snippet_path) ⇒ Object
- #add_snippet(snippet) ⇒ Object
- #copy_to(directory) ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(path) ⇒ Bundle
constructor
A new instance of Bundle.
- #name ⇒ Object
- #snippet_named(name) ⇒ Object
Constructor Details
#initialize(path) ⇒ Bundle
Returns a new instance of Bundle.
7 8 9 10 11 |
# File 'lib/xcode_snippets/bundle.rb', line 7 def initialize(path) @path = path @snippets = [] load_snippets end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/xcode_snippets/bundle.rb', line 5 def path @path end |
#snippets ⇒ Object (readonly)
Returns the value of attribute snippets.
5 6 7 |
# File 'lib/xcode_snippets/bundle.rb', line 5 def snippets @snippets end |
Class Method Details
.bundle_named(name, install_directory) ⇒ Object
14 15 16 |
# File 'lib/xcode_snippets/bundle.rb', line 14 def bundle_named(name, install_directory) new(File.join(install_directory, "#{name}.snippetbundle")) end |
.default(directory) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/xcode_snippets/bundle.rb', line 18 def default(directory) bundle = bundle_named("Default", directory) if bundle.exists? bundle else bundle.copy_to(directory) end end |
Instance Method Details
#add_copy_of_snippet(snippet) ⇒ Object
57 58 59 60 |
# File 'lib/xcode_snippets/bundle.rb', line 57 def add_copy_of_snippet(snippet) @snippets << snippet.copy_to_bundle(self) @snippets.last end |
#add_copy_of_snippet_from_file(snippet_path) ⇒ Object
48 49 50 |
# File 'lib/xcode_snippets/bundle.rb', line 48 def add_copy_of_snippet_from_file(snippet_path) add_copy_of_snippet Snippet.new(snippet_path) end |
#add_snippet(snippet) ⇒ Object
52 53 54 55 |
# File 'lib/xcode_snippets/bundle.rb', line 52 def add_snippet(snippet) @snippets << snippet @snippets.last end |
#copy_to(directory) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/xcode_snippets/bundle.rb', line 29 def copy_to(directory) installation_path = File.join(directory, name) FileUtils.mkdir_p(installation_path) self.class.new(installation_path).tap do |copied_bundle| snippets.each do |snippet| copied_bundle.add_copy_of_snippet(snippet) end end end |
#delete ⇒ Object
62 63 64 |
# File 'lib/xcode_snippets/bundle.rb', line 62 def delete FileUtils.rm_rf(path) end |
#exists? ⇒ Boolean
44 45 46 |
# File 'lib/xcode_snippets/bundle.rb', line 44 def exists? File.exist?(path) end |
#name ⇒ Object
40 41 42 |
# File 'lib/xcode_snippets/bundle.rb', line 40 def name File.basename(path) end |