class OctoMerge::Options

Constants

CONFIG_FILE
DEFAULT_OPTIONS
USER_CONFIG_PATH

Public Class Methods

option(key) click to toggle source
# File lib/octo_merge/options.rb, line 5
def self.option(key)
  define_method(key) { self[key] }
end

Public Instance Methods

[](key) click to toggle source
# File lib/octo_merge/options.rb, line 17
def [](key)
  data[key]
end
cli_options=(options) click to toggle source
# File lib/octo_merge/options.rb, line 21
def cli_options=(options)
  reset_cache
  @cli_options = options
end

Private Instance Methods

cli_options() click to toggle source
# File lib/octo_merge/options.rb, line 89
def cli_options
  @cli_options ||= {}
end
data() click to toggle source
# File lib/octo_merge/options.rb, line 35
def data
  @data ||= begin
    options = default_options
      .merge(user_options)
      .merge(project_options)
      .merge(cli_options)


    # Sanitize input
    options[:dir] = File.expand_path(options[:dir])
    options[:strategy] = Object.const_get("OctoMerge::Strategy::#{options[:strategy]}")
    options[:pull_requests] = get_interactive_pull_requests(options) if options[:interactive]
    options[:pull_requests] = options[:pull_requests].to_s.split(",")

    options
  end
end
default_options() click to toggle source
# File lib/octo_merge/options.rb, line 67
def default_options
  DEFAULT_OPTIONS
end
get_interactive_pull_requests(options) click to toggle source

This hotfix will configure the API credentials before doing the API call.

# File lib/octo_merge/options.rb, line 54
def get_interactive_pull_requests(options)
  OctoMerge.configure do |config|
    config.login = options[:login]
    config.password = options[:password]
  end

  OctoMerge::InteractivePullRequests.get(options)
end
project_options() click to toggle source
# File lib/octo_merge/options.rb, line 80
def project_options
  if File.exist?(CONFIG_FILE)
    body = File.read(CONFIG_FILE)
    symbolize_keys YAML.load(body)
  else
    {}
  end
end
reset_cache() click to toggle source
# File lib/octo_merge/options.rb, line 63
def reset_cache
  @data = nil
end
symbolize_keys(hash) click to toggle source
# File lib/octo_merge/options.rb, line 93
def symbolize_keys(hash)
  hash.inject({}){ |memo, (k, v)| memo[k.to_sym] = v; memo }
end
user_options() click to toggle source
# File lib/octo_merge/options.rb, line 71
def user_options
  if File.exist?(USER_CONFIG_PATH)
    body = File.read(USER_CONFIG_PATH)
    symbolize_keys YAML.load(body)
  else
    {}
  end
end