Class: Octopi::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/octopi/base.rb

Direct Known Subclasses

Blob, Branch, Comment, Commit, FileObject, Gist, Issue, IssueComment, Key, Plan, Repository, Tag, Tree, User

Constant Summary

VALID =
{
  :repo => {
    # FIXME: API currently chokes on repository names containing periods,
    # but presumably this will be fixed.
    :pat => /^[A-Za-z0-9_\.-]+$/,
    :msg => "%s is an invalid repository name"},
  :user => {
    :pat => /^[A-Za-z0-9_\.-]+$/,
    :msg => "%s is an invalid username"},
  :sha => {
    :pat => /^[a-f0-9]{40}$/,
    :msg => "%s is an invalid SHA hash"},
  :state => {
    # FIXME: Any way to access Issue::STATES from here?
    :pat => /^(open|closed)$/, 
    :msg => "%s is an invalid state; should be 'open' or 'closed'."  
  }
}

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Base) initialize(attributes = {})



24
25
26
27
28
29
30
31
32
# File 'lib/octopi/base.rb', line 24

def initialize(attributes={})
  # Useful for finding out what attr_accessor needs for classes
  # puts caller.first.inspect
  # puts "#{self.class.inspect} #{attributes.keys.map { |s| s.to_sym }.inspect}"
  attributes.each do |key, value|
    method = "#{key}="
    self.send(method, value) if respond_to? method
  end
end

Instance Attribute Details

- (Object) api

Returns the value of attribute api



22
23
24
# File 'lib/octopi/base.rb', line 22

def api
  @api
end

Instance Method Details

- (Object) error=(error)



34
35
36
37
38
# File 'lib/octopi/base.rb', line 34

def error=(error)
  if /\w+ not found/.match(error)
    raise NotFound, self.class
  end
end

- (Object) property(p, v)



40
41
42
43
# File 'lib/octopi/base.rb', line 40

def property(p, v)
  path = "#{self.class.path_for(:resource)}/#{p}"
  Api.api.find(path, self.class.resource_name(:singular), v)
end

- (Object) save



45
46
47
48
49
# File 'lib/octopi/base.rb', line 45

def save
  hash = {}
  @keys.each { |k| hash[k] = send(k) }
  Api.api.save(self.path_for(:resource), hash)
end