Class: Gitdocs::Share
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gitdocs::Share
- Defined in:
- lib/gitdocs/share.rb
Class Method Summary collapse
- .at(index) ⇒ Share
- .create_by_path!(path) ⇒ Object
- .find_by_path(path) ⇒ Share
- .paths ⇒ Array<String>
- .remove_by_id(id) ⇒ true, false
- .remove_by_path(path) ⇒ void
- .update_all(updated_shares) ⇒ void
Class Method Details
.at(index) ⇒ Share
15 16 17 |
# File 'lib/gitdocs/share.rb', line 15 def self.at(index) all[index.to_i] end |
.create_by_path!(path) ⇒ Object
27 28 29 |
# File 'lib/gitdocs/share.rb', line 27 def self.create_by_path!(path) new(path: File.(path)).save! end |
.find_by_path(path) ⇒ Share
22 23 24 |
# File 'lib/gitdocs/share.rb', line 22 def self.find_by_path(path) where(path: File.(path)).first end |
.paths ⇒ Array<String>
8 9 10 |
# File 'lib/gitdocs/share.rb', line 8 def self.paths all.map(&:path) end |
.remove_by_id(id) ⇒ true, false
51 52 53 54 55 56 |
# File 'lib/gitdocs/share.rb', line 51 def self.remove_by_id(id) find(id).destroy true rescue ActiveRecord::RecordNotFound false end |
.remove_by_path(path) ⇒ void
This method returns an undefined value.
60 61 62 |
# File 'lib/gitdocs/share.rb', line 60 def self.remove_by_path(path) where(path: File.(path)).destroy_all end |
.update_all(updated_shares) ⇒ void
This method returns an undefined value.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gitdocs/share.rb', line 33 def self.update_all(updated_shares) updated_shares.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') share_config['remote_name'], share_config['branch_name'] = remote_branch.split('/', 2) if remote_branch at(index).update_attributes(share_config) end end |