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 (protected)



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.(md)
  send(method_sym, *args, &block)
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



40
41
42
# File 'lib/amiba/source.rb', line 40

def format
  @format
end

Instance Method Details

#contentObject



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

#filenameObject



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',  = 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. = 
  self.content = content
end

#metadataObject



77
78
79
# File 'lib/amiba/source.rb', line 77

def 
  @metadata ||= source_valid? ? documents.first : {}
end

#metadata=(meta) ⇒ Object



85
86
87
88
# File 'lib/amiba/source.rb', line 85

def metadata=(meta)
  m = meta ? .merge(meta) : 
  @metadata = HashWithIndifferentAccess.new(m)
end

#metadata_and_contentObject



63
64
65
# File 'lib/amiba/source.rb', line 63

def 
  YAML.dump(.to_hash) + YAML.dump(content)
end

#new?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/amiba/source.rb', line 59

def new?
  !File.exist?(filename)
end

#pubdateObject



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, 
  true
end