class GitCommands::Aggregator

Constants

NAME
PATTERN

Public Class Methods

new(name: NAME, pattern: PATTERN) click to toggle source
# File lib/git_commands/aggregator.rb, line 8
def initialize(name: NAME, pattern: PATTERN)
  @name = name
  @pattern = check_pattern(pattern)
  define_methods
end

Public Instance Methods

call() click to toggle source
# File lib/git_commands/aggregator.rb, line 18
def call
  return @name if @name
  @pattern.gsub(/<[\w_]+>/) do |part|
    msg = part.gsub(/<|>/, "")
    send(msg)
  end
end
define_methods() click to toggle source
# File lib/git_commands/aggregator.rb, line 35
def define_methods
  pattern_methods.each do |name|
    define_singleton_method(name) do
      ENV.fetch(name.upcase) { "" }
    end
  end
end
timestamp() click to toggle source
# File lib/git_commands/aggregator.rb, line 14
def timestamp
  @timestamp ||= Time.new.strftime("%Y%m%d")
end

Private Instance Methods

check_pattern(pattern) click to toggle source
# File lib/git_commands/aggregator.rb, line 26
        def check_pattern(pattern)
  fail InvalidPatternError unless pattern.match(/<\w+>/) 
  pattern
end
pattern_methods() click to toggle source
# File lib/git_commands/aggregator.rb, line 31
        def pattern_methods
  @methods ||= @pattern.scan(/<(\w+)>/).flatten - ["timestamp"]
end