Class: Decant::File
- Inherits:
-
Object
- Object
- Decant::File
- Defined in:
- lib/decant/file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
- #path ⇒ Pathname readonly
Instance Method Summary collapse
-
#content ⇒ String
The “content” part of the file at #path - everything after the end of the frontmatter definition (see Decant::Frontmatter.load for more about frontmatter).
-
#frontmatter ⇒ Hash<Symbol, anything>?
The frontmatter data contained in the file at #path or
nilif there’s none (see Decant::Frontmatter.load for more about frontmatter). -
#frontmatter?(key = nil) ⇒ Boolean
When passing a
keythe return value indicates whether #frontmatter has thekey, when nokeyis passed it indicates whether the file has any frontmatter at all. -
#initialize(path) ⇒ File
constructor
A new instance of File.
-
#read ⇒ String
The full untouched contents of the file at #path.
Constructor Details
#initialize(path) ⇒ File
Returns a new instance of File.
10 11 12 |
# File 'lib/decant/file.rb', line 10 def initialize(path) @path = path end |
Instance Attribute Details
#path ⇒ Pathname (readonly)
7 8 9 |
# File 'lib/decant/file.rb', line 7 def path @path end |
Instance Method Details
#content ⇒ String
The “content” part of the file at #path - everything after the end of the frontmatter definition (see Decant::Frontmatter.load for more about frontmatter).
19 20 21 |
# File 'lib/decant/file.rb', line 19 def content frontmatter_content[1] end |
#frontmatter ⇒ Hash<Symbol, anything>?
The frontmatter data contained in the file at #path or nil if there’s none (see Decant::Frontmatter.load for more about frontmatter).
27 28 29 |
# File 'lib/decant/file.rb', line 27 def frontmatter frontmatter_content[0] end |
#frontmatter?(key = nil) ⇒ Boolean
When passing a key the return value indicates whether #frontmatter has the key, when no key is passed it indicates whether the file has any frontmatter at all.
38 39 40 41 |
# File 'lib/decant/file.rb', line 38 def frontmatter?(key = nil) return false if frontmatter.nil? key ? frontmatter.key?(key) : true end |
#read ⇒ String
The full untouched contents of the file at #path.
46 47 48 |
# File 'lib/decant/file.rb', line 46 def read path.read end |