From da6167d740be9050514c0652e3760ea3dfdfede4 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 26 Apr 2012 14:58:14 +0200 Subject: [PATCH] Add configuration support for repo and branch This helps in keeping the issues within the project repo vs. the gaskin app. --- .gitignore | 3 ++- config.yml.example | 2 ++ lib/gaskit.rb | 32 +++++++++++++++++++++++++++++++- lib/gaskit/story.rb | 2 +- lib/gaskit/user.rb | 2 +- 5 files changed, 37 insertions(+), 4 deletions(-) create mode 100644 config.yml.example diff --git a/.gitignore b/.gitignore index 0af65f9..44a307f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .sass-cache testrepo/ -chromedriver.log \ No newline at end of file +chromedriver.log +config.yml diff --git a/config.yml.example b/config.yml.example new file mode 100644 index 0000000..eb4304a --- /dev/null +++ b/config.yml.example @@ -0,0 +1,2 @@ +repo_path: ~/Code/my-project +branch: issues diff --git a/lib/gaskit.rb b/lib/gaskit.rb index 4ecedb1..9bf8ad5 100644 --- a/lib/gaskit.rb +++ b/lib/gaskit.rb @@ -8,14 +8,44 @@ def self.root @root ||= Pathname(File.expand_path('../..', __FILE__)) end + def self.repo_path + @root_path ||= root.to_s + end + + def self.repo_path= path + @root_path = File.expand_path(path) + end + def self.env @env ||= ActiveSupport::StringInquirer.new(ENV['RACK_ENV'] || 'development') end def self.repo - @repo ||= env.test? ? Grit::Repo.init(root.join('testrepo').to_s) : Grit::Repo.new(root.to_s) + @repo ||= env.test? ? Grit::Repo.init(Pathname(repo_path).join('testrepo').to_s) : Grit::Repo.new(repo_path.to_s) + end + + def self.branch + @branch ||= 'gaskit' + end + + def self.load_config! + file = File.expand_path('../../config.yml', __FILE__) + return false unless File.exist? file + + require 'yaml' + @config = YAML.load_file(file) + @config.each_pair do |key, value| + Gaskit.public_send "#{key}=", value + end + end + + class << self + attr_writer :root_path, :branch + end end +Gaskit.load_config! + require 'gaskit/story' require 'gaskit/user' diff --git a/lib/gaskit/story.rb b/lib/gaskit/story.rb index f8ea227..2a296b4 100644 --- a/lib/gaskit/story.rb +++ b/lib/gaskit/story.rb @@ -3,7 +3,7 @@ class Story include Toy::Store self.include_root_in_json = false - store :git, Gaskit.repo, :branch => 'gaskit', :path => 'stories' + store :git, Gaskit.repo, :branch => Gaskit.branch, :path => 'stories' attribute :description, String attribute :type, String, :default => 'feature' diff --git a/lib/gaskit/user.rb b/lib/gaskit/user.rb index 916f833..f73e425 100644 --- a/lib/gaskit/user.rb +++ b/lib/gaskit/user.rb @@ -8,7 +8,7 @@ def initialize(attrs = {}) end def self.adapter - Adapter[:git].new(Gaskit.repo, :branch => 'gaskit') + Adapter[:git].new(Gaskit.repo, :branch => Gaskit.branch) end def self.all