Class: SublimeTextKit::ProjectMetadata
- Inherits:
-
Object
- Object
- SublimeTextKit::ProjectMetadata
- Defined in:
- lib/sublime_text_kit/project_metadata.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
-
#project_file ⇒ Object
readonly
Returns the value of attribute project_file.
-
#workspace_dir ⇒ Object
readonly
Returns the value of attribute workspace_dir.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(project_dir, workspace_dir) ⇒ ProjectMetadata
constructor
A new instance of ProjectMetadata.
- #save ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(project_dir, workspace_dir) ⇒ ProjectMetadata
Returns a new instance of ProjectMetadata.
27 28 29 30 31 32 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 27 def initialize project_dir, workspace_dir @name = File.basename project_dir @project_dir = File. project_dir @workspace_dir = File. workspace_dir @project_file = File.join @workspace_dir, "#{name}.sublime-project" end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 6 def name @name end |
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
6 7 8 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 6 def project_dir @project_dir end |
#project_file ⇒ Object (readonly)
Returns the value of attribute project_file.
6 7 8 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 6 def project_file @project_file end |
#workspace_dir ⇒ Object (readonly)
Returns the value of attribute workspace_dir.
6 7 8 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 6 def workspace_dir @workspace_dir end |
Class Method Details
.create(projects_dir, workspace_dir) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 8 def self.create projects_dir, workspace_dir projects_dir = File. projects_dir workspace_dir = File. workspace_dir return unless valid_dir?(projects_dir, "Projects") return unless valid_dir?(workspace_dir, "Workspace") project_paths = ::Pathname.new(projects_dir).children.select {|child| child if child.directory? } project_paths.each { |project_dir| new(project_dir, workspace_dir).save } end |
.delete(workspace_dir) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 19 def self.delete workspace_dir workspace_dir = File. workspace_dir return unless valid_dir?(workspace_dir, "Workspace") ::Pathname.glob("#{workspace_dir}/*.sublime-*").each(&:delete) end |
Instance Method Details
#save ⇒ Object
42 43 44 45 46 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 42 def save unless File.exist? project_file File.open(project_file, 'w') { |file| file.write MultiJson.dump(to_h, pretty: true) } end end |
#to_h ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/sublime_text_kit/project_metadata.rb', line 34 def to_h { folders: [ {path: "#{project_dir}"} ] } end |