Class: Gitdocs::Share

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/gitdocs/share.rb

Class Method Summary collapse

Class Method Details

.at(index) ⇒ Share

Parameters:

  • index (#to_i)

Returns:



15
16
17
# File 'lib/gitdocs/share.rb', line 15

def self.at(index)
  all[index.to_i]
end

.create_by_path!(path) ⇒ Object

Parameters:

  • path (String)


27
28
29
# File 'lib/gitdocs/share.rb', line 27

def self.create_by_path!(path)
  new(path: File.expand_path(path)).save!
end

.find_by_path(path) ⇒ Share

Parameters:

  • path (String)

Returns:



22
23
24
# File 'lib/gitdocs/share.rb', line 22

def self.find_by_path(path)
  where(path: File.expand_path(path)).first
end

.pathsArray<String>

Returns:

  • (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

Parameters:

  • id (Integer)

    of the share to remove

Returns:

  • (true)

    share was deleted

  • (false)

    share does not exist



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.

Parameters:

  • path (String)

    of the share to remove



60
61
62
# File 'lib/gitdocs/share.rb', line 60

def self.remove_by_path(path)
  where(path: File.expand_path(path)).destroy_all
end

.update_all(updated_shares) ⇒ void

This method returns an undefined value.

Parameters:

  • updated_shares (Hash)


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