Class: Octopi::Base
- Inherits:
-
Object
- Object
- Octopi::Base
- Defined in:
- lib/octopi/base.rb
Direct Known Subclasses
Blob, Branch, Commit, FileObject, Issue, Key, Repository, Tag, User
Constant Summary collapse
- 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"}, :file => { :pat => /^[^ \/]+$/, :msg => "%s is an invalid filename"}, :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
-
#api ⇒ Object
Returns the value of attribute api.
Instance Method Summary collapse
-
#initialize(api, hash) ⇒ Base
constructor
A new instance of Base.
- #property(p, v) ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(api, hash) ⇒ Base
Returns a new instance of Base.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/octopi/base.rb', line 32 def initialize(api, hash) @api = api @keys = [] raise "Missing data for #{@resource}" unless hash hash.each_pair do |k,v| @keys << k next if k =~ /\./ instance_variable_set("@#{k}", v) method = (TrueClass === v || FalseClass === v) ? "#{k}?" : k self.class.send :define_method, "#{method}=" do |v| instance_variable_set("@#{k}", v) end self.class.send :define_method, method do instance_variable_get("@#{k}") end end end |
Instance Attribute Details
#api ⇒ Object
Returns the value of attribute api.
30 31 32 |
# File 'lib/octopi/base.rb', line 30 def api @api end |
Instance Method Details
#property(p, v) ⇒ Object
55 56 57 58 |
# File 'lib/octopi/base.rb', line 55 def property(p, v) path = "#{self.class.path_for(:resource)}/#{p}" @api.find(path, self.class.resource_name(:singular), v) end |
#save ⇒ Object
60 61 62 63 64 |
# File 'lib/octopi/base.rb', line 60 def save hash = {} @keys.each { |k| hash[k] = send(k) } @api.save(self.path_for(:resource), hash) end |