class Gitdocs::Share

Public Class Methods

at(index) click to toggle source

@param [#to_i] index

@return [Share]

# File lib/gitdocs/share.rb, line 14
def self.at(index)
  all[index.to_i]
end
create_by_path!(path) click to toggle source

@param [String] path

# File lib/gitdocs/share.rb, line 26
def self.create_by_path!(path)
  new(path: File.expand_path(path)).save!
end
find_by_path(path) click to toggle source

@param [String] path

@return [Share]

# File lib/gitdocs/share.rb, line 21
def self.find_by_path(path)
  where(path: File.expand_path(path)).first
end
paths() click to toggle source

@return [Array<String>]

# File lib/gitdocs/share.rb, line 7
def self.paths
  all.map(&:path)
end
remove_by_id(id) click to toggle source

@param [Integer] id of the share to remove

@return [true] share was deleted @return [false] share does not exist

# File lib/gitdocs/share.rb, line 50
def self.remove_by_id(id)
  find(id).destroy
  true
rescue ActiveRecord::RecordNotFound
  false
end
remove_by_path(path) click to toggle source

@param [String] path of the share to remove @return [void]

# File lib/gitdocs/share.rb, line 59
def self.remove_by_path(path)
  where(path: File.expand_path(path)).destroy_all
end
update_all(updated_shares) click to toggle source

@param [Hash] updated_shares @return [void]

# File lib/gitdocs/share.rb, line 32
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