Class: Gitdocs::Configuration
- Inherits:
-
Object
- Object
- Gitdocs::Configuration
- Defined in:
- lib/gitdocs/configuration.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#config_root ⇒ Object
readonly
Returns the value of attribute config_root.
Instance Method Summary collapse
- #add_path(path, opts = nil) ⇒ Object
- #clear ⇒ Object
- #global ⇒ Object
-
#initialize(config_root = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #normalize_path(path) ⇒ Object
- #remove_path(path) ⇒ Object
- #shares ⇒ Object
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.(".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.("../migration", __FILE__)) import_old_shares unless ENV["TEST"] end |
Instance Attribute Details
#config_root ⇒ Object (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 |
#clear ⇒ Object
53 54 55 |
# File 'lib/gitdocs/configuration.rb', line 53 def clear Share.destroy_all end |
#global ⇒ Object
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.(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 |
#shares ⇒ Object
57 58 59 |
# File 'lib/gitdocs/configuration.rb', line 57 def shares Share.all end |