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.
10
11
12
|
# File 'lib/troy/meta.rb', line 10
def initialize(file)
@file = file
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
22
23
24
|
# File 'lib/troy/meta.rb', line 22
def method_missing(name, *args, &block)
data[name.to_s]
end
|
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
8
9
10
|
# File 'lib/troy/meta.rb', line 8
def file
@file
end
|
Instance Method Details
#content ⇒ Object
14
15
16
|
# File 'lib/troy/meta.rb', line 14
def content
@content ||= raw.gsub(REGEX, "")
end
|
#data ⇒ Object
18
19
20
|
# File 'lib/troy/meta.rb', line 18
def data
@data ||= (raw =~ REGEX ? YAML.load(raw[REGEX, 1]) : {})
end
|
#raw ⇒ Object
30
31
32
|
# File 'lib/troy/meta.rb', line 30
def raw
@raw ||= File.read(file)
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
26
27
28
|
# File 'lib/troy/meta.rb', line 26
def respond_to_missing?(method, include_private = false)
true
end
|