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
-
#initialize(config_root = nil) ⇒ Configuration
constructor
A new instance of Configuration.
- #remove_by_id(id) ⇒ true, false
- #remove_path(path) ⇒ Object
- #shares ⇒ Object
-
#start_web_frontend ⇒ Object
return [Boolean].
- #update_all(new_config) ⇒ Object
- #web_frontend_port ⇒ Integer
Constructor Details
#initialize(config_root = nil) ⇒ Configuration
Returns a new instance of Configuration.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/gitdocs/configuration.rb', line 9 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.
7 8 9 |
# File 'lib/gitdocs/configuration.rb', line 7 def config_root @config_root end |
Instance Method Details
#add_path(path, opts = nil) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/gitdocs/configuration.rb', line 40 def add_path(path, opts = nil) path = normalize_path(path) path_opts = { path: path } path_opts.merge!(opts) if opts Share.new(path_opts).save! end |
#clear ⇒ Object
82 83 84 |
# File 'lib/gitdocs/configuration.rb', line 82 def clear Share.destroy_all end |
#remove_by_id(id) ⇒ true, false
75 76 77 78 79 80 |
# File 'lib/gitdocs/configuration.rb', line 75 def remove_by_id(id) Share.find(id).destroy true rescue ActiveRecord::RecordNotFound false end |
#remove_path(path) ⇒ Object
66 67 68 69 |
# File 'lib/gitdocs/configuration.rb', line 66 def remove_path(path) path = normalize_path(path) Share.where(path: path).destroy_all end |
#shares ⇒ Object
86 87 88 |
# File 'lib/gitdocs/configuration.rb', line 86 def shares Share.all end |
#start_web_frontend ⇒ Object
return [Boolean]
29 30 31 |
# File 'lib/gitdocs/configuration.rb', line 29 def start_web_frontend global.start_web_frontend end |
#update_all(new_config) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/gitdocs/configuration.rb', line 50 def update_all(new_config) global.update_attributes(new_config['config']) new_config['share'].each do |index, share_config| # Skip the share update if there is no path specified. next unless share_config['path'] && !share_config['path'].empty? # Split the remote_branch into remote and branch remote_branch = share_config.delete('remote_branch') if remote_branch share_config['remote_name'], share_config['branch_name'] = remote_branch.split('/', 2) end shares[index.to_i].update_attributes(share_config) end end |
#web_frontend_port ⇒ Integer
34 35 36 |
# File 'lib/gitdocs/configuration.rb', line 34 def web_frontend_port global.web_frontend_port end |