Class: Gitdocs::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gitdocs/configuration.rb

Defined Under Namespace

Classes: Config, Share

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_root = nil) ⇒ Configuration

Returns a new instance of Configuration.



8
9
10
11
12
13
14
15
16
17
# File 'lib/gitdocs/configuration.rb', line 8

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

Instance Attribute Details

#config_rootObject (readonly)

Returns the value of attribute config_root.



6
7
8
# File 'lib/gitdocs/configuration.rb', line 6

def config_root
  @config_root
end

Instance Method Details

#add_path(path, opts = nil) ⇒ Object



41
42
43
44
45
46
# File 'lib/gitdocs/configuration.rb', line 41

def add_path(path, opts = nil)
  path = self.normalize_path(path)
  path_opts = {:path => path}
  path_opts.merge!(opts) if opts
  Share.new(path_opts).save!
end

#clearObject



53
54
55
# File 'lib/gitdocs/configuration.rb', line 53

def clear
  Share.destroy_all
end

#globalObject



61
62
63
64
65
# File 'lib/gitdocs/configuration.rb', line 61

def global
  raise if Config.all.size > 1
  Config.create! if Config.all.empty?
  Config.all.first
end

#normalize_path(path) ⇒ Object



67
68
69
# File 'lib/gitdocs/configuration.rb', line 67

def normalize_path(path)
  File.expand_path(path, Dir.pwd)
end

#remove_path(path) ⇒ Object



48
49
50
51
# File 'lib/gitdocs/configuration.rb', line 48

def remove_path(path)
  path = self.normalize_path(path)
  Share.where(:path => path).destroy_all
end

#sharesObject



57
58
59
# File 'lib/gitdocs/configuration.rb', line 57

def shares
  Share.all
end