Class: Allen::MetaData

Inherits:
Object
  • Object
show all
Defined in:
lib/allen/meta_data.rb

Defined Under Namespace

Classes: NullCommit

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(settings) ⇒ MetaData

Returns a new instance of MetaData.



7
8
9
10
# File 'lib/allen/meta_data.rb', line 7

def initialize(settings)
  @root_dir = settings.root_dir
  @webroot = settings.webroot
end

Instance Attribute Details

#root_dirObject (readonly)

Returns the value of attribute root_dir.



5
6
7
# File 'lib/allen/meta_data.rb', line 5

def root_dir
  @root_dir
end

#webrootObject (readonly)

Returns the value of attribute webroot.



5
6
7
# File 'lib/allen/meta_data.rb', line 5

def webroot
  @webroot
end

Instance Method Details

#allenObject



38
39
40
# File 'lib/allen/meta_data.rb', line 38

def allen
  { :version => Allen::VERSION }
end

#buildObject



24
25
26
# File 'lib/allen/meta_data.rb', line 24

def build
  { :date => Time.now.to_s }
end

#commitObject



28
29
30
31
32
33
34
35
36
# File 'lib/allen/meta_data.rb', line 28

def commit
  repo = Grit::Repo.new(@root_dir)
  commit = repo.commits.first || NullCommit.new

  { :id => commit.id,
    :date => commit.committed_date,
    :author => commit.author,
    :message => commit.message }
end

#save!Object



12
13
14
15
16
# File 'lib/allen/meta_data.rb', line 12

def save!
  file = File.open("#{@webroot}/meta.json","w")
  file.print(self.to_json)
  file.close
end

#to_jsonObject



18
19
20
21
22
# File 'lib/allen/meta_data.rb', line 18

def to_json
  { :build => build,
    :commit => commit,
    :allen => allen }.to_json
end