Class: Everything::Piece::Metadata
- Inherits:
-
Object
- Object
- Everything::Piece::Metadata
- Extended by:
- Forwardable
- Defined in:
- lib/everything/piece/metadata.rb
Instance Method Summary collapse
- #absolute_dir ⇒ Object
- #absolute_path ⇒ Object
- #dir ⇒ Object
- #file_path ⇒ Object
-
#initialize(piece_path) ⇒ Metadata
constructor
TODO: Need to add some ways in here to save the metadata file once it’s been edited.
- #path ⇒ Object
- #raw_yaml ⇒ Object
- #raw_yaml=(value) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(piece_path) ⇒ Metadata
TODO: Need to add some ways in here to save the metadata file once it’s been edited. TODO: Also add a #to_s or #inspect methods to render the raw_yaml TODO: Also add a #[]= here that delegates to raw_yaml as well.
14 15 16 |
# File 'lib/everything/piece/metadata.rb', line 14 def initialize(piece_path) @piece_path = piece_path end |
Instance Method Details
#absolute_dir ⇒ Object
18 19 20 |
# File 'lib/everything/piece/metadata.rb', line 18 def absolute_dir @absolute_dir ||= Everything.path.join(dir) end |
#absolute_path ⇒ Object
22 23 24 |
# File 'lib/everything/piece/metadata.rb', line 22 def absolute_path @absolute_path ||= absolute_dir.join(file_name) end |
#dir ⇒ Object
26 27 28 |
# File 'lib/everything/piece/metadata.rb', line 26 def dir @dir ||= calculated_dir end |
#file_path ⇒ Object
30 31 32 33 34 35 |
# File 'lib/everything/piece/metadata.rb', line 30 def file_path # TODO: Could try a deprecation approach like http://seejohncode.com/2012/01/09/deprecating-methods-in-ruby/ = "Piece Metadata's #file_path is deprecated and will be removed soon. Use #absolute_path instead." warn @file_path ||= File.join(piece_path, file_name) end |
#path ⇒ Object
37 38 39 |
# File 'lib/everything/piece/metadata.rb', line 37 def path @path ||= dir.join(file_name) end |
#raw_yaml ⇒ Object
41 42 43 |
# File 'lib/everything/piece/metadata.rb', line 41 def raw_yaml @raw_yaml ||= YAML.load_file(absolute_path) end |
#raw_yaml=(value) ⇒ Object
45 46 47 |
# File 'lib/everything/piece/metadata.rb', line 45 def raw_yaml=(value) @raw_yaml = value end |
#save ⇒ Object
49 50 51 52 53 |
# File 'lib/everything/piece/metadata.rb', line 49 def save FileUtils.mkdir_p(piece_path) absolute_path.write(@raw_yaml) end |