class Toolshed::Client

This is responsible for loading .toolshedrc file

Constants

GITHUB_BASE_API_URL
PIVOTAL_TRACKER_BASE_API_URL

Attributes

struct[R]

Public Class Methods

new() click to toggle source
# File lib/toolshed/client.rb, line 19
def initialize
  load_toolshedrc_configuration
  @struct = to_ostruct
end

Public Instance Methods

load_toolshedrc_configuration() click to toggle source
# File lib/toolshed/client.rb, line 24
def load_toolshedrc_configuration
  toolshedrc_configurations = YAML.load(ERB.new(File.read(toolshedrc_path)).result)
  raise CorruptFileException, 'Toolshedrc file is not configured properly.' unless toolshedrc_configurations.is_a?(Hash)
  self.merge!(toolshedrc_configurations)
end
method_missing(*args) click to toggle source
# File lib/toolshed/client.rb, line 30
def method_missing(*args)
  begin
    if args.first.to_s.end_with?('=')
      val = args.last
      my_h = self
      args.each_with_index do |arg, index|
        arg = arg.to_s.gsub('=', '')
        next_arg_val = args[index + 1].to_s.gsub('=', '')
        my_h = my_h[arg] unless next_arg_val == val.to_s
        my_h[arg] = val if next_arg_val == val.to_s && !my_h[arg].nil?
        my_h.merge!(arg => val) if next_arg_val == val.to_s && my_h[arg].nil?
      end
      @struct = to_ostruct
    else
      struct.send(args.first)
    end
  rescue NoMethodError => e
    Toolshed.die(e.message)
  end
end
toolshedrc_path() click to toggle source
# File lib/toolshed/client.rb, line 51
def toolshedrc_path
   @toolshedrc_path ||= begin
     dir = Dir.pwd
     while File.expand_path(dir) != '/'
       unless File.exist?("#{dir}/.toolshedrc")
         dir = File.join dir, '..'
         next
       end
       credentials_loaded_from = "#{dir}/.toolshedrc"
       break
     end
     credentials_loaded_from
   end
 end