buggy 0.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
File without changes
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ include Rote
22
22
  # Buiild the GEM -------------------------------------------------------
23
23
 
24
24
  PKG_NAME = 'buggy'
25
- PKG_VERSION = '0.1'
25
+ PKG_VERSION = '0.4'
26
26
  RUBY_FORGE_PROJECT = "buggy"
27
27
  RUBY_FORGE_USER = "cdcarter"
28
28
 
@@ -49,9 +49,9 @@ spec = Gem::Specification.new do |s|
49
49
  s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
50
50
  s.require_path = 'lib'
51
51
 
52
- # s.bindir = "bin" # Use these for applications.
53
- # s.executables = ["buggy"]
54
- # s.default_executable = "buggy"
52
+ s.bindir = "bin"
53
+ s.executables = ["buggy"]
54
+ s.default_executable = "buggy"
55
55
 
56
56
  s.author = "Christian Carter"
57
57
  s.email = "cdcarter@concentrationstudios.com"
@@ -0,0 +1,111 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'simpleconsole'
5
+ require 'hpricot'
6
+ require 'rfuzz/client'
7
+ require 'cgi'
8
+ require 'builder'
9
+
10
+
11
+ FIELDS = %w[priority project body id]
12
+ CFIELDS = %w[closed project body id]
13
+
14
+ class Bug
15
+ attr_writer :project, :priority, :body, :id, :closed
16
+ attr_reader :project, :priority, :body, :id, :closed
17
+
18
+ def initialize(hash={})
19
+ @project = hash[:project]
20
+ @priority = hash[:priority]
21
+ @body = hash[:body]
22
+ @id = hash[:id]
23
+ @closed = hash[:closed]
24
+ end
25
+ end
26
+
27
+ class Controller < SimpleConsole::Controller
28
+ params :int => { :id => :id, :p => :port },
29
+ :string => { :project => :project, :host => :host, :priority => :priority},
30
+ :text => { :body => :body }
31
+
32
+ def get
33
+ connection = RFuzz::HttpClient.new(params[:host], params[:port])
34
+ encoded_id = CGI::escape(params[:id].to_s)
35
+ resp = connection.get("/#{encoded_id}").http_body
36
+ doc = Hpricot(resp)
37
+ (doc/:bug).each do |xml_bug|
38
+ @bug = Bug.new
39
+ for field in FIELDS
40
+ @bug.send("#{field}=", (xml_bug/field).first.innerHTML)
41
+ end
42
+ end
43
+ @bug
44
+ end
45
+
46
+ def close
47
+ connection = RFuzz::HttpClient.new(params[:host], params[:port])
48
+ encoded_id = CGI::escape(params[:id].to_s)
49
+ resp = connection.delete("/#{encoded_id}").http_body
50
+ doc = Hpricot(resp)
51
+ @bug = Bug.new
52
+ for field in CFIELDS
53
+ @bug.send("#{field}=", (doc/:bug/field).first.innerHTML)
54
+ end
55
+ @bug.freeze
56
+ @bug
57
+ end
58
+
59
+
60
+ def new
61
+ connection = RFuzz::HttpClient.new(params[:host], params[:port])
62
+ @nbug = Bug.new(:project => params[:project], :priority => params[:priority], :body => params[:body])
63
+ xml = gen_xml(@nbug)
64
+ resp = connection.post("/", :body => "bug=#{xml}").http_body
65
+ doc = Hpricot(resp)
66
+ @bug = Bug.new
67
+ for field in FIELDS
68
+ @bug.send("#{field}=", (doc/:bug/field).first.innerHTML)
69
+ end
70
+ end
71
+
72
+ def gen_xml(bug)
73
+ @returned_xml = ""
74
+ xml = Builder::XmlMarkup.new(:target => @returned_xml)
75
+ xml.instruct!
76
+ xml.buglist do
77
+ xml.bug do
78
+ xml.project bug.project
79
+ xml.priority bug.priority
80
+ xml.body bug.body
81
+ end
82
+ end
83
+ return @returned_xml
84
+ end
85
+ end
86
+
87
+ class View < SimpleConsole::View
88
+ def get
89
+ puts "ID: #{@bug.id}-#{@bug.project}"
90
+ puts "Priority: #{@bug.priority}"
91
+ puts "--------------"
92
+ puts "#{@bug.body}"
93
+ end
94
+
95
+ def close
96
+ puts "ID: #{@bug.id}-#{@bug.project}"
97
+ puts "Status: Closed" if @bug.closed == "1"
98
+ puts "Status: Open" if @bug.closed == "0"
99
+ puts "--------------"
100
+ puts "#{@bug.body}"
101
+ end
102
+
103
+ def new
104
+ puts "ID: #{@bug.id}-#{@bug.project}"
105
+ puts "Priority: #{@bug.priority}"
106
+ puts "--------------"
107
+ puts "#{@bug.body}"
108
+ end
109
+ end
110
+
111
+ SimpleConsole::Application.run(ARGV, Controller, View)
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'rubygems'
4
+ require 'hpricot'
5
+ require 'rfuzz/client'
6
+ require 'cgi'
7
+ require 'builder'
8
+
9
+ FIELDS = %w[priority project body]
10
+ class Bug
11
+ attr_writer :project, :priority, :body, :id, :closed
12
+ attr_reader :project, :priority, :body, :id, :closed
13
+
14
+ def initalize(hash)
15
+ @project = hash[:project]
16
+ @priority = hash[:priority]
17
+ @body = hash[:body]
18
+ @id = hash[:id]
19
+ @closed = hash[:closed]
20
+ end
21
+
22
+ def connection
23
+ self.class.connection
24
+ end
25
+
26
+ def self.connection
27
+ @@connections[name]
28
+ end
29
+
30
+ def self.connect(host, port)
31
+ RFuzz::HttpClient.new(host, port)
32
+ end
33
+
34
+ def self.establish_connection(options)
35
+ @@connections ||= {}
36
+ @@connections[name] = connect(options[:host], options[:port])
37
+ end
38
+
39
+ def self.get(id)
40
+ encoded_id = CGI::escape(id.to_s)
41
+ resp = @@connections[name].get("/#{encoded_id}").http_body
42
+ doc = Hpricot(resp)
43
+ (doc/:bug).each do |xml_bug|
44
+ @bug = Bug.new
45
+ for field in FIELDS
46
+ @bug.send("#{field}=", (xml_bug/field).first.innerHTML)
47
+ end
48
+ @bug.id = id
49
+ end
50
+ return @bug
51
+ end
52
+
53
+ def save
54
+ xml = generate_xml(self)
55
+ resp = connection.post("/", :body => "bug=#{xml}").http_body
56
+ doc = Hpricot(resp)
57
+ @bug = Bug.new
58
+ for field in FIELDS
59
+ @bug.send("#{field}=", (doc/:bug/field).first.innerHTML)
60
+ end
61
+ return @bug
62
+ end
63
+
64
+ def destroy!
65
+ encoded_id = CGI::escape(self.id.to_s)
66
+ resp = connection.delete("/#{encoded_id}").http_body
67
+ self.closed = "1"
68
+ self.freeze
69
+ end
70
+
71
+ def generate_xml(bug)
72
+ xml = Builder::XmlMarkup.new
73
+ xml.instruct!
74
+
75
+ xml.buglist do
76
+ xml.bug do
77
+ xml.project bug.project
78
+ xml.priority bug.priority
79
+ xml.body bug.body
80
+ end
81
+ end
82
+ end
83
+ end
@@ -7,6 +7,7 @@ Camping.goes :Buggy
7
7
  module Buggy::Models
8
8
 
9
9
  class Bug < Base
10
+ has_many :annotations
10
11
  def close
11
12
  self.closed = 1
12
13
  self.save
@@ -17,18 +18,26 @@ module Buggy::Models
17
18
  "Open" if self.closed == 0
18
19
  end
19
20
  end
21
+
22
+ class Annotation < Base
23
+ belongs_to :bug
24
+ end
20
25
 
21
26
  class CreateBuggy < V 1.0
22
27
  def self.up
23
28
  create_table :buggy_bugs, :force => true do |t|
24
- t.column :priority, :integer
29
+ t.column :priority, :string
25
30
  t.column :project, :string
26
31
  t.column :body, :text
27
32
 
28
33
  # 1 is true, 0 is false
29
34
  t.column :closed, :integer
30
35
  end
31
-
36
+
37
+ create_table :buggy_annotations, :force => true do |t|
38
+ t.column :body, :text
39
+ t.column :bug_id, :integer
40
+ end
32
41
  end
33
42
  def self.down
34
43
  drop_table :buggy_bugs
@@ -48,12 +57,11 @@ module Buggy::Controllers
48
57
  def delete id
49
58
  @bug = Bug.find(id)
50
59
  @bug.close
51
- render :apideleted
60
+ render :apishow
52
61
  end
53
62
  end
54
63
 
55
64
  class Resource < R '/'
56
- FIELDS = %w[priority project body]
57
65
  def get
58
66
  @headers['Content-Type'] = 'text/xml charset=utf8'
59
67
  @bugs = Bug.find(:all, :limit => 10, :conditions => ["closed=?",0])
@@ -61,19 +69,18 @@ module Buggy::Controllers
61
69
  end
62
70
 
63
71
  def post
64
- @status = 201
65
- @bugs = []
66
- doc = Hpricot.parse(input.keys.first)
67
- (doc/:bug).each do |xml_bug|
68
- bug = Bug.new
69
- for field in FIELDS
70
- bug[field] = (xml_bug/field).first.innerHTML
71
- end
72
- bug.closed = 0
73
- bug.save
74
- @bugs << bug
72
+ doc = Hpricot(input.bug)
73
+ @bug = Bug.new
74
+ @bug.priority = (doc/:bug/:priority).first.innerHTML
75
+ @bug.project = (doc/:bug/:project).first.innerHTML
76
+ @bug.body = (doc/:bug/:body).first.innerHTML
77
+ @bug.closed = 0
78
+ if @bug.save
79
+ @status = 201
80
+ render :apishow
81
+ else
82
+ @status = 500
75
83
  end
76
- render :apilist
77
84
  end
78
85
  end
79
86
  end
@@ -94,19 +101,6 @@ module Buggy::Views
94
101
  end
95
102
  end
96
103
 
97
- def apideleted
98
- xml = Builder::XmlMarkup.new(:target => self)
99
- xml.instruct!
100
-
101
- xml.buglist do
102
- xml.bug do
103
- xml.id @bug.id
104
- xml.status @bug.status
105
- xml.project @bug.project
106
- xml.body @bug.body
107
- end
108
- end
109
- end
110
104
 
111
105
  def apishow
112
106
  @headers['Content-Type'] = 'text/xml'
@@ -119,6 +113,7 @@ module Buggy::Views
119
113
  xml.id @bug.id
120
114
  xml.project @bug.project
121
115
  xml.priority @bug.priority
116
+ xml.closed @bug.closed
122
117
  xml.body @bug.body
123
118
  end
124
119
  end
@@ -0,0 +1,8 @@
1
+ require 'buggster'
2
+
3
+ def test_the_new_record
4
+ Bug.establish_connection(:host => 'localhost', :port => 3301)
5
+ new = Bug.get(1)
6
+ new.priority = '2'
7
+ new.save
8
+ end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: buggy
5
5
  version: !ruby/object:Gem::Version
6
- version: "0.1"
7
- date: 2006-09-10 00:00:00 -05:00
6
+ version: "0.4"
7
+ date: 2006-09-24 00:00:00 -05:00
8
8
  summary: Buggy!
9
9
  require_paths:
10
10
  - lib
@@ -13,7 +13,7 @@ homepage: http://buggy.rubyforge.org
13
13
  rubyforge_project: buggy
14
14
  description: Buggy! A simple bugtraker
15
15
  autorequire:
16
- default_executable:
16
+ default_executable: buggy
17
17
  bindir: bin
18
18
  has_rdoc: false
19
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
@@ -28,12 +28,15 @@ cert_chain:
28
28
  authors:
29
29
  - Christian Carter
30
30
  files:
31
+ - bin
31
32
  - docs
32
33
  - lib
33
34
  - LICENSE
34
35
  - Rakefile
35
- - README.rdoc
36
+ - README
37
+ - lib/buggster.rb
36
38
  - lib/buggy.rb
39
+ - lib/test.rb
37
40
  test_files: []
38
41
 
39
42
  rdoc_options:
@@ -41,8 +44,8 @@ rdoc_options:
41
44
  - .
42
45
  extra_rdoc_files: []
43
46
 
44
- executables: []
45
-
47
+ executables:
48
+ - buggy
46
49
  extensions: []
47
50
 
48
51
  requirements: []