Class: CiInACan::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/ci_in_a_can/repo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



12
13
14
# File 'lib/ci_in_a_can/repo.rb', line 12

def api_key
  @api_key
end

#build_commandsObject

Returns the value of attribute build_commands.



13
14
15
# File 'lib/ci_in_a_can/repo.rb', line 13

def build_commands
  @build_commands
end

#idObject

Returns the value of attribute id.



10
11
12
# File 'lib/ci_in_a_can/repo.rb', line 10

def id
  @id
end

#nameObject

Returns the value of attribute name.



11
12
13
# File 'lib/ci_in_a_can/repo.rb', line 11

def name
  @name
end

Class Method Details

.allObject



40
41
42
43
# File 'lib/ci_in_a_can/repo.rb', line 40

def self.all
  blah = CiInACan::Persistence.hash_for("repos")
  blah.sort_by { |x| x[0] }.reverse.map { |x| new x[1] }
end

.create(data) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/ci_in_a_can/repo.rb', line 15

def self.create data
  data[:api_key] ||= UUID.new.generate
  repo_data = { id:      data[:id],
                name:    data[:name],
                api_key: data[:api_key],
                build_commands: data[:build_commands] }
  CiInACan::Persistence.save('repos', data[:id], repo_data)
  find data[:id]
end

.find(id) ⇒ Object



25
26
27
28
29
# File 'lib/ci_in_a_can/repo.rb', line 25

def self.find id
  data = CiInACan::Persistence.find('repos', id)
  return nil unless data
  CiInACan::Repo.new(data)
end

.find_by_api_key(api_key) ⇒ Object



31
32
33
# File 'lib/ci_in_a_can/repo.rb', line 31

def self.find_by_api_key api_key
  all.select { |x| x.api_key == api_key }.first
end

Instance Method Details

#reset_api_keyObject



45
46
47
48
49
# File 'lib/ci_in_a_can/repo.rb', line 45

def reset_api_key
  data = CiInACan::Persistence.find('repos', id)
  data[:api_key] = UUID.new.generate
  CiInACan::Persistence.save('repos', data[:id], data)
end

#saveObject



35
36
37
38
# File 'lib/ci_in_a_can/repo.rb', line 35

def save
  data = { id: id, name: name, api_key: api_key, build_commands: build_commands }
  CiInACan::Persistence.save('repos', id, data)
end

#urlObject



51
52
53
# File 'lib/ci_in_a_can/repo.rb', line 51

def url
  "/push/#{id}/#{api_key}"
end