Sha256: 633a18b86692d3934c0b8679ba5fe18216f8de63fe6138c90064ac40ac1312e5
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
require 'active_record' module Gitdocs class Configuration attr_reader :config_root def initialize(config_root = nil) @config_root = config_root || File.expand_path(".gitdocs", ENV["HOME"]) FileUtils.mkdir_p(@config_root) ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ENV["TEST"] ? ':memory:' : File.join(@config_root, 'config.db') ) ActiveRecord::Migrator.migrate(File.expand_path("../migration", __FILE__)) import_old_shares unless ENV["TEST"] end class Share < ActiveRecord::Base attr_accessible :polling_interval, :path, :notification, :branch_name, :remote_name end def add_path(path, opts = nil) path_opts = {:path => path} path_opts.merge!(opts) if opts Share.new(path_opts).save! end def remove_path(path) Share.where(:path => path).destroy_all end def shares Share.all end def normalize_path(path) File.expand_path(path, Dir.pwd) end private def import_old_shares full_path = File.expand_path('paths', config_root) if File.exist?(full_path) File.read(full_path).split("\n").each { |path| Share.find_or_create_by_path(path) } end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gitdocs-0.3.0 | lib/gitdocs/configuration.rb |