Module: Amiba::Source::InstanceMethods
- Includes:
- Repo
- Defined in:
- lib/amiba/source.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Repo
#add_and_commit, #init, #last_commit_date, #last_commit_dates, #pull, #push, #repo
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_sym, *args, &block) ⇒ Object
96
97
98
99
100
|
# File 'lib/amiba/source.rb', line 96
def method_missing(method_sym, *args, &block)
md = method_sym.to_s.gsub(/=$/,'')
self.class.define_metadata_accessor(md)
send(method_sym, *args, &block)
end
|
Instance Attribute Details
Returns the value of attribute format.
40
41
42
|
# File 'lib/amiba/source.rb', line 40
def format
@format
end
|
Instance Method Details
#content ⇒ Object
73
74
75
|
# File 'lib/amiba/source.rb', line 73
def content
@content
end
|
#content=(c) ⇒ Object
90
91
92
|
# File 'lib/amiba/source.rb', line 90
def content=(c)
@content = c ? c : documents.last
end
|
#filename ⇒ Object
54
55
56
|
# File 'lib/amiba/source.rb', line 54
def filename
@filename ||= File.join(self.class.pluralized_name, "#{name}.#{format}")
end
|
#initialize(name, format = 'haml', metadata = nil, content = nil) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/amiba/source.rb', line 42
def initialize(name, format='haml', metadata = nil, content = nil)
ext = File.extname name
fn = File.basename(name, ext)
dn = File.dirname name
f = dn == "." ? fn : File.join(dn, fn)
self.name = f
self.format = format
self.metadata = metadata
self.content = content
end
|
77
78
79
|
# File 'lib/amiba/source.rb', line 77
def metadata
@metadata ||= source_valid? ? documents.first : {}
end
|
85
86
87
88
|
# File 'lib/amiba/source.rb', line 85
def metadata=(meta)
m = meta ? metadata.merge(meta) : metadata
@metadata = HashWithIndifferentAccess.new(m)
end
|
#metadata_and_content ⇒ Object
63
64
65
|
# File 'lib/amiba/source.rb', line 63
def metadata_and_content
YAML.dump(metadata.to_hash) + YAML.dump(content)
end
|
#new? ⇒ Boolean
59
60
61
|
# File 'lib/amiba/source.rb', line 59
def new?
!File.exist?(filename)
end
|
#pubdate ⇒ Object
81
82
83
|
# File 'lib/amiba/source.rb', line 81
def pubdate
@metadata["pubdate"] ||= last_commit_date filename
end
|
#save {|filename, metadata_and_content| ... } ⇒ Object
67
68
69
70
71
|
# File 'lib/amiba/source.rb', line 67
def save(&block)
return false unless valid?
yield filename, metadata_and_content
true
end
|