Class: Middleman::BuildReporter::Reporter

Inherits:
Object
  • Object
show all
Defined in:
lib/middleman-build-reporter/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_instance, opts = nil) ⇒ Reporter

Returns a new instance of Reporter.



10
11
12
13
14
15
# File 'lib/middleman-build-reporter/reporter.rb', line 10

def initialize(app_instance, opts = nil)
  @app = app_instance

  @options = opts
  @repo = Git.open(opts.repo_root ? opts.repo_root : @app.root)
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



8
9
10
# File 'lib/middleman-build-reporter/reporter.rb', line 8

def app
  @app
end

#optionsObject (readonly)

Returns the value of attribute options.



8
9
10
# File 'lib/middleman-build-reporter/reporter.rb', line 8

def options
  @options
end

#repoObject (readonly)

Returns the value of attribute repo.



8
9
10
# File 'lib/middleman-build-reporter/reporter.rb', line 8

def repo
  @repo
end

Instance Method Details

#build_timeObject



54
55
56
# File 'lib/middleman-build-reporter/reporter.rb', line 54

def build_time
  Time.now
end

#detailsObject



35
36
37
38
39
40
41
42
# File 'lib/middleman-build-reporter/reporter.rb', line 35

def details
  {
    'branch' => repo.current_branch,
    'revision' => repo.log.first.to_s,
    'build_time' => build_time.to_s,
    'version' => options.version
  }.merge(details_extension)
end

#details_extensionObject



44
45
46
47
48
# File 'lib/middleman-build-reporter/reporter.rb', line 44

def details_extension
  return {} unless details_extension_exist?

  YAML.load(File.read(reporter_extension_file_path))
end

#details_extension_exist?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/middleman-build-reporter/reporter.rb', line 50

def details_extension_exist?
  File.exist?(reporter_extension_file_path)
end

#reporter_extension_file_pathObject



31
32
33
# File 'lib/middleman-build-reporter/reporter.rb', line 31

def reporter_extension_file_path
  "#{app.root}/.build_reporter.yml"
end

#reporter_file_pathObject



27
28
29
# File 'lib/middleman-build-reporter/reporter.rb', line 27

def reporter_file_path
  "#{app.build_dir}/#{options.reporter_file}"
end

#serialize(format) ⇒ Object



58
59
60
61
62
# File 'lib/middleman-build-reporter/reporter.rb', line 58

def serialize(format)
  method = "to_#{format}".to_sym

  details.send(method)
end

#writeObject



17
18
19
20
21
22
23
24
25
# File 'lib/middleman-build-reporter/reporter.rb', line 17

def write
  @options.reporter_file_formats.each do |format|
    file = "#{reporter_file_path}.#{format}"

    File.write(file, serialize(format))

    yield(file) if block_given?
  end
end