Class: Middleman::BuildReporter::Reporter
- Inherits:
-
Object
- Object
- Middleman::BuildReporter::Reporter
- Defined in:
- lib/middleman-build-reporter/reporter.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#repo ⇒ Object
readonly
Returns the value of attribute repo.
Instance Method Summary collapse
- #build_time ⇒ Object
- #details ⇒ Object
- #details_extension ⇒ Object
- #details_extension_exist? ⇒ Boolean
-
#initialize(app_instance, opts = nil) ⇒ Reporter
constructor
A new instance of Reporter.
- #reporter_extension_file_path ⇒ Object
- #reporter_file_path ⇒ Object
- #serialize(format) ⇒ Object
- #write ⇒ Object
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
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/middleman-build-reporter/reporter.rb', line 8 def app @app end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/middleman-build-reporter/reporter.rb', line 8 def @options end |
#repo ⇒ Object (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_time ⇒ Object
54 55 56 |
# File 'lib/middleman-build-reporter/reporter.rb', line 54 def build_time Time.now end |
#details ⇒ Object
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' => .version }.merge(details_extension) end |
#details_extension ⇒ Object
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
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_path ⇒ Object
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_path ⇒ Object
27 28 29 |
# File 'lib/middleman-build-reporter/reporter.rb', line 27 def reporter_file_path "#{app.build_dir}/#{.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 |
#write ⇒ Object
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 |