class GTM::Bootstrap

Attributes

client[RW]

Public Class Methods

extract_scope(s) click to toggle source
# File lib/gtm/bootstrap.rb, line 7
def self.extract_scope(s)
  full_regex = /^(?<path>.+\/|\/?)(?<account_id>\d+)\/(?<container_name>.+)\/tags\/(?<tag_file>.+)$/
  container_regex = /^(?<path>.+\/|\/?)(?<account_id>\d+)\/(?<container_name>\w+)\/?$/
  account_regex = /^(?<path>.+\/|\/?)(?<account_id>\d+)\/?$/
  [full_regex, container_regex, account_regex].each do |r|
    match = r.match s
    if match
      result = (match.names.zip(match.captures)).to_h.with_indifferent_access
      return result.deep_symbolize_keys
    end
  end
  result = {path: s.to_s}
  result[:path] += '/' if !result[:path].blank? && !result[:path][-1].eql?('/')
  result
end
pull(arg) click to toggle source
# File lib/gtm/bootstrap.rb, line 23
def self.pull(arg)
  @client ||= GTM::Client.new
  @client.scope = extract_scope(arg.first)
  pull = GTM::Pull.new @client
  pull.run
end
push(arg) click to toggle source
# File lib/gtm/bootstrap.rb, line 30
def self.push(arg)
  @client ||= GTM::Client.new
  @client.scope = extract_scope(arg.first)
  if @client.scope[:tag_file]
    push = GTM::Push.new @client
    push.run
  else
    print 'pleas specify a single tag file, directory push is not supported (yet)'
  end
end