Commit 646c3e63 authored by Eloy Duran's avatar Eloy Duran

Add a global config.

parent 4c8530b1
module Pod
autoload :Command, 'cocoa_pods/command'
autoload :Config, 'cocoa_pods/config'
end
module Pod
class Command
include Config::Mixin
autoload :Help, 'cocoa_pods/command/help'
autoload :Setup, 'cocoa_pods/command/setup'
autoload :Spec, 'cocoa_pods/command/spec'
......@@ -19,9 +21,5 @@ module Pod
def initialize(*argv)
raise ArgumentError, "unknown argument(s): #{argv.join(', ')}" unless argv.empty?
end
def repos_dir
File.expand_path('~/.cocoa-pods')
end
end
end
......@@ -25,7 +25,7 @@ module Pod
end
def dir
File.join(repos_dir, @name)
File.join(config.repos_dir, @name)
end
def run
......@@ -33,14 +33,14 @@ module Pod
end
def add
FileUtils.mkdir_p(repos_dir)
Dir.chdir(repos_dir) { git("clone #{@url} #{@name}") }
FileUtils.mkdir_p(config.repos_dir)
Dir.chdir(config.repos_dir) { git("clone #{@url} #{@name}") }
end
def update
names = @name ? [@name] : Dir.entries(repos_dir)[2..-1]
names = @name ? [@name] : Dir.entries(config.repos_dir)[2..-1]
names.each do |name|
Dir.chdir(File.join(repos_dir, name)) { git("pull") }
Dir.chdir(File.join(config.repos_dir, name)) { git("pull") }
end
end
end
......
module Pod
class Config
def self.instance
@instance ||= new
end
def self.instance=(instance)
@instance = instance
end
attr_accessor :repos_dir
def initialize
@repos_dir = File.expand_path("~/.cocoa-pods")
end
module Mixin
def config
Config.instance
end
end
end
end
......@@ -14,3 +14,9 @@ require 'spec_helper/temporary_directory'
#TMP_DIR = SpecHelper::TemporaryDirectory.temporary_directory
#TMP_COCOA_PODS_DIR = File.join(TMP_DIR, 'cocoa-pods')
class Bacon::Context
include Pod::Config::Mixin
end
Pod::Config.instance.repos_dir = SpecHelper.tmp_repos_path
......@@ -21,10 +21,6 @@ describe "Pod::Command::Setup" do
it "returns the URL of the `master' spec-repo" do
@command.master_repo_url.should == 'git://github.com/alloy/cocoa-pod-specs.git'
end
it "returns the path of the directory where the local spec-repos will be stored" do
@command.repos_dir.should == File.expand_path("~/.cocoa-pods")
end
end
describe "Pod::Command::Repo" do
......@@ -34,6 +30,6 @@ describe "Pod::Command::Repo" do
it "returns the path of the spec-repo directory" do
repo = Pod::Command::Repo.new('cd', 'private')
repo.dir.should == File.expand_path("~/.cocoa-pods/private")
repo.dir.should == File.join(config.repos_dir, 'private')
end
end
require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::Config" do
before do
@original_config = config
Pod::Config.instance = nil
end
after do
Pod::Config.instance = @original_config
end
it "returns the singleton config instance" do
config.should.be.instance_of Pod::Config
end
it "returns the path to the spec-repos dir" do
config.repos_dir.should == File.expand_path("~/.cocoa-pods")
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment