Class: Troy::Meta
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/troy/meta.rb
Constant Summary
collapse
- REGEX =
/^---\n(.*?)\n---\n+/m
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(file) ⇒ Meta
Returns a new instance of Meta.
12
13
14
|
# File 'lib/troy/meta.rb', line 12
def initialize(file)
@file = file
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *_args) ⇒ Object
25
26
27
|
# File 'lib/troy/meta.rb', line 25
def method_missing(name, *_args)
data[name.to_s]
end
|
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
10
11
12
|
# File 'lib/troy/meta.rb', line 10
def file
@file
end
|
Instance Method Details
#content ⇒ Object
16
17
18
|
# File 'lib/troy/meta.rb', line 16
def content
@content ||= raw.gsub(REGEX, "")
end
|
#data ⇒ Object
20
21
22
23
|
# File 'lib/troy/meta.rb', line 20
def data
@data ||=
REGEX.match?(raw) ? YAML.unsafe_load(raw[REGEX, 1]) : {}
end
|
#raw ⇒ Object
33
34
35
|
# File 'lib/troy/meta.rb', line 33
def raw
@raw ||= File.read(file)
end
|
#respond_to_missing?(_method, _include_private = false) ⇒ Boolean
29
30
31
|
# File 'lib/troy/meta.rb', line 29
def respond_to_missing?(_method, _include_private = false)
true
end
|