Class: SublimeTextKit::Metadata::Base
- Inherits:
-
Object
- Object
- SublimeTextKit::Metadata::Base
- Defined in:
- lib/sublime_text_kit/metadata/base.rb
Overview
Abstract class for processing metadata.
Instance Attribute Summary collapse
-
#metadata_dir ⇒ Object
readonly
Returns the value of attribute metadata_dir.
-
#metadata_file ⇒ Object
readonly
Returns the value of attribute metadata_file.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#project_dir ⇒ Object
readonly
Returns the value of attribute project_dir.
Class Method Summary collapse
Instance Method Summary collapse
- #file_extension ⇒ Object
-
#initialize(project_dir, metadata_dir) ⇒ Base
constructor
A new instance of Base.
- #save ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(project_dir, metadata_dir) ⇒ Base
Returns a new instance of Base.
28 29 30 31 32 33 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 28 def initialize project_dir, @name = File.basename project_dir @project_dir = File. project_dir @metadata_dir = File. @metadata_file = File.join @metadata_dir, "#{name}.#{file_extension}" end |
Instance Attribute Details
#metadata_dir ⇒ Object (readonly)
Returns the value of attribute metadata_dir.
10 11 12 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 10 def @metadata_dir end |
#metadata_file ⇒ Object (readonly)
Returns the value of attribute metadata_file.
10 11 12 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 10 def @metadata_file end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 10 def name @name end |
#project_dir ⇒ Object (readonly)
Returns the value of attribute project_dir.
10 11 12 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 10 def project_dir @project_dir end |
Class Method Details
.create(projects_dir, metadata_dir) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 12 def self.create projects_dir, instance = new projects_dir, return unless valid_dir?(instance.project_dir, "Projects") return unless valid_dir?(instance., "Metadata") project_paths = ::Pathname.new(instance.project_dir).children.select(&:directory?) project_paths.each { |project_dir| new(project_dir, ).save } end |
.delete(metadata_dir) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 21 def self.delete instance = new "", return unless valid_dir?(instance., "Metadata") ::Pathname.glob("#{instance.}/*.#{instance.file_extension}").each(&:delete) end |
Instance Method Details
#file_extension ⇒ Object
35 36 37 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 35 def file_extension "sublime-unknown" end |
#save ⇒ Object
43 44 45 46 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 43 def save return if File.exist? File.open(, "w") { |file| file.write JSON.dump(to_h) } end |
#to_h ⇒ Object
39 40 41 |
# File 'lib/sublime_text_kit/metadata/base.rb', line 39 def to_h {} end |