Class: Namaste::Tag
- Inherits:
-
Object
- Object
- Namaste::Tag
- Defined in:
- lib/namaste/tag.rb
Defined Under Namespace
Modules: Dirtype
Class Method Summary collapse
-
.filename(tag, value) ⇒ String
Create a filename for a namaste key/value pair.
Instance Method Summary collapse
-
#delete ⇒ Object
Delete this tag.
-
#initialize(directory_or_file, tag = nil, value = nil) ⇒ Tag
constructor
A new instance of Tag.
-
#tag ⇒ String
Namaste tag.
- #tag=(tag) ⇒ Object
-
#value ⇒ String
Namaste value.
- #value=(value) ⇒ Object
Constructor Details
#initialize(directory_or_file, tag = nil, value = nil) ⇒ Tag
Returns a new instance of Tag.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/namaste/tag.rb', line 14 def initialize(directory_or_file, tag = nil, value = nil) directory_or_file = File.(directory_or_file) tag = Namaste::DUBLIN_KERNEL[tag] if tag.is_a? Symbol if File.directory?(directory_or_file) @dir = directory_or_file @tag = tag.to_s @value = value.to_s write! elsif File.file?(directory_or_file) @file = File.new(directory_or_file, "a+") @dir = File.dirname(@file.path) else raise "Unknown directory or file (#{directory_or_file.to_s})" end load_tag_extensions end |
Class Method Details
.filename(tag, value) ⇒ String
Create a filename for a namaste key/value pair
5 6 7 8 9 |
# File 'lib/namaste/tag.rb', line 5 def self.filename tag, value n = "%s=%s" % [tag, self.elide(value)] n = n.slice(0...252) + "..." if n.length > 255 n end |
Instance Method Details
#delete ⇒ Object
Delete this tag
60 61 62 63 64 |
# File 'lib/namaste/tag.rb', line 60 def delete @value = value # make sure to preserve the value after the tag is deleted File.delete(file.path) @file = nil end |
#tag ⇒ String
Returns namaste tag.
48 49 50 |
# File 'lib/namaste/tag.rb', line 48 def tag @tag ||= File.basename(file.path).split("=").first end |
#tag=(tag) ⇒ Object
53 54 55 56 57 |
# File 'lib/namaste/tag.rb', line 53 def tag=(tag) delete @tag = tag.to_s write! end |
#value ⇒ String
Returns namaste value.
35 36 37 38 |
# File 'lib/namaste/tag.rb', line 35 def value file.rewind @value ||= file.read end |
#value=(value) ⇒ Object
41 42 43 44 45 |
# File 'lib/namaste/tag.rb', line 41 def value=(value) delete @value = value.to_s write! end |