sk-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,62 @@
1
+ module SKApi
2
+ module Utils
3
+ # Mixed into Resources::Base providing to_hash and to_json serialisation for
4
+ # SKApi Resources.
5
+ # Inside SalesKing this serialising is used to render the output.
6
+ # f.ex. in the clients api controller
7
+ # => SKApi::Resources::Client.to_json(a_client)
8
+ # This way you can keep your API client up to date by using the resources and
9
+ # relying on SKApi::Resources::Client.api_fields
10
+ module Serializer
11
+ def self.included(base)
12
+ base.extend ClassMethods
13
+ end
14
+
15
+ module ClassMethods
16
+
17
+ # Create a Hash with the available (api)object attributes defined in api_fields.
18
+ #
19
+ # ==== Parameter
20
+ # obj<object>:. An object which is returned as hash
21
+ def to_hash_from_schema(obj)
22
+ # first set the root node to the objects class name as symbol
23
+ obj_class_name = obj.class.name.split('::').last.underscore
24
+ # obj_class_name = obj.class.to_s.underscore.to_sym
25
+ data = { obj_class_name => {} }
26
+ # iterate over the defined api fields hash
27
+ self.schema_props.each do |field, props|
28
+ if props['type'] == 'array'
29
+ # always set the field, so the user can expect an empty array
30
+ data[obj_class_name][field] = []
31
+ if rel_objects = obj.send( field )
32
+ rel_objects.each do |rel_obj|
33
+ # setup scope for related class
34
+ klass = "SKApi::Resources::#{rel_obj.class}".constantize
35
+ # call related objects to_hash_from_schema method ex: data[:client][:addresses] << SKApi::Models::Address.to_hash_from_schema(object)
36
+ data[obj_class_name][field] << klass.to_hash_from_schema(rel_obj)
37
+ end
38
+ end
39
+ elsif props['type'] == 'object' # a singular resource TODO should we add an empty object?
40
+ if rel_obj = obj.send( field )
41
+ klass = "SKApi::Resources::#{rel_obj.class}".constantize
42
+ # ex: data['invoice']['client'] = SKApi::Models::Client.to_hash_from_schema(client)
43
+ data[obj_class_name][field] = klass.to_hash_from_schema(rel_obj)
44
+ end
45
+ else # a simple field which can be directly called
46
+ data[obj_class_name][field] = obj.send(field)
47
+ end
48
+ end
49
+ data
50
+ end
51
+
52
+ def to_json(obj)
53
+ data = self.to_hash_from_schema(obj)
54
+ # data[:links] = self.api_links
55
+ Rufus::Json.encode(data)
56
+ end
57
+
58
+ end #ClassMethods
59
+
60
+ end #mixin
61
+ end #utils
62
+ end #SKApi
data/lib/version.rb ADDED
@@ -0,0 +1,9 @@
1
+ module SKApi
2
+ module VERSION #:nodoc:
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ TINY = 1
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,111 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ describe SKApi::Resources::Client, "in general" do
4
+
5
+ before :all do
6
+ #setup test client to work with
7
+ @client = SKApi::Resources::Client.new(:organisation=>'from testing API2')
8
+ @client.save
9
+ end
10
+
11
+ after :all do
12
+ #delete test client
13
+ @client.destroy
14
+ lambda {
15
+ client = SKApi::Resources::Client.find(@client.id)
16
+ }.should raise_error(ActiveResource::ResourceNotFound)
17
+ end
18
+
19
+ it "should create a client" do
20
+ @client.number.should_not be_nil
21
+ @client.new?.should be_false
22
+ end
23
+
24
+ it "should fail create a client" do
25
+ client = SKApi::Resources::Client.new(:organisation=>'from testing API2')
26
+ client.bank_iban = 'safasf'
27
+ client.save.should == false
28
+ client.errors.count.should == 1
29
+ client.errors.full_messages.should == ["Bank iban is invalid"]
30
+ end
31
+
32
+ it "should find a client" do
33
+ client = SKApi::Resources::Client.find(@client.id)
34
+ client.organisation.should == @client.organisation
35
+ end
36
+
37
+ it "should edit a client" do
38
+ @client.first_name = 'Theodore'
39
+ @client.gender = 'male'
40
+ @client.lock_version.should == 0
41
+ @client.save
42
+ @client.lock_version.should == 1 # because save returns the data
43
+ end
44
+
45
+ it "should fail edit a client" do
46
+ @client.last_name = ''
47
+ @client.organisation = ''
48
+ @client.save.should == false
49
+ @client.errors.count.should == 1
50
+ @client.errors.on_base.should == "<p>clients.errors.fill_name_or_organisation</p>"
51
+ end
52
+
53
+ it "should validate raw json object with schema" do
54
+ client = SKApi::Resources::Client.find(@client.id)
55
+ # convert to json and read raw without activeresource assigning classes
56
+ json = client.to_json
57
+ obj = Rufus::Json.decode(json)
58
+ lambda {
59
+ JSON::Schema.validate(obj, SKApi::Resources::Client.schema)
60
+ }.should_not raise_error
61
+ end
62
+
63
+ it "should validate raw json object with to_hash_with_schema" do
64
+ client = SKApi::Resources::Client.find(@client.id)
65
+ # convert to json and read raw without activeresource assigning classes
66
+ hash_obj = SKApi::Resources::Client.to_hash_from_schema(client)
67
+ # hash_obj.should == ''
68
+ lambda {
69
+ JSON::Schema.validate(hash_obj['client'], SKApi::Resources::Client.schema)
70
+ }.should_not raise_error
71
+ end
72
+
73
+ end
74
+
75
+ describe SKApi::Resources::Client, "with addresses" do
76
+
77
+ before :all do
78
+ #setup test client to work with
79
+ @client = SKApi::Resources::Client.new(:organisation=>'Second from testing API2',
80
+ :addresses => [{ :zip => '50374', :city => 'Cologne' }] )
81
+ @client.save
82
+ end
83
+
84
+ after :all do
85
+ @client.destroy
86
+ lambda {
87
+ client = SKApi::Resources::Client.find(@client.id)
88
+ }.should raise_error(ActiveResource::ResourceNotFound)
89
+ end
90
+
91
+ it "should create an address" do
92
+ @client.addresses.length.should == 1
93
+ @client.addresses.first.zip.should == '50374'
94
+ end
95
+
96
+ it "should edit an address" do
97
+ @client.addresses[0].zip = '40001'
98
+ @client.save
99
+ @client.addresses.length.should == 1
100
+ @client.addresses.first.zip.should == '40001'
101
+ end
102
+
103
+ it "should add an address" do
104
+ adr = SKApi::Resources::Address.new( { :zip => '50374', :city => 'Cologne' } )
105
+ @client.addresses << adr
106
+ @client.save
107
+ @client.addresses.length.should == 2
108
+ # @client.addresses[0].zip = '40001'
109
+ # @client.addresses.[1].zip.should == '40001'
110
+ end
111
+ end
@@ -0,0 +1,116 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ describe SKApi::Resources::CreditNote, "in general" do
4
+
5
+ before :all do
6
+ #setup test doc to work with
7
+ # create client
8
+ @client = SKApi::Resources::Client.new(:organisation=>'Credit Note API-Tester')
9
+ @client.save.should be_true
10
+ @doc = SKApi::Resources::CreditNote.new()
11
+ @doc.title = 'A Document from the API'
12
+ @doc.client_id = @client.id
13
+ @doc.save.should be_true
14
+ end
15
+
16
+ after :all do
17
+ #delete test doc
18
+ @doc.destroy
19
+ @client.destroy
20
+ lambda {
21
+ doc = SKApi::Resources::CreditNote.find(@doc.id)
22
+ }.should raise_error(ActiveResource::ResourceNotFound)
23
+ lambda {
24
+ client = SKApi::Resources::Client.find(@client.id)
25
+ }.should raise_error(ActiveResource::ResourceNotFound)
26
+ end
27
+
28
+ it "should create a doc" do
29
+ @doc.errors.should be_empty
30
+ @doc.new?.should be_false
31
+ end
32
+
33
+ it "should fail create a doc" do
34
+ doc = SKApi::Resources::CreditNote.new()
35
+ doc.save.should == false
36
+ doc.errors.count.should == 1
37
+ doc.errors.on(:client_id).should == "can't be blank"
38
+ end
39
+
40
+ it "should find a doc" do
41
+ doc = SKApi::Resources::CreditNote.find(@doc.id)
42
+ doc.title.should == @doc.title
43
+ end
44
+
45
+ it "should validate raw json object with schema" do
46
+ doc = SKApi::Resources::CreditNote.find(@doc.id)
47
+ # doc.number.should=='23'
48
+ # convert to json and read raw without activeresource assigning classes
49
+ json = doc.to_json
50
+ obj = Rufus::Json.decode(json)
51
+ lambda {
52
+ JSON::Schema.validate(obj, SKApi::Resources::CreditNote.schema)
53
+ }.should_not raise_error
54
+ end
55
+
56
+ it "should edit a doc" do
57
+ # @doc.lock_version.should == 0 # dont work cause doc is saved twice, for recalc of totals
58
+ old_lock_version = @doc.lock_version
59
+ @doc.notes_before = 'You will recieve the amout of:'
60
+ @doc.notes_before = 'Payment made to you bank Account'
61
+ @doc.title = 'Changed doc title'
62
+
63
+ @doc.save.should be_true
64
+ @doc.lock_version.should > old_lock_version # because save returns the data
65
+ end
66
+
67
+ it "should fail edit a doc" do
68
+ @doc.client_id = ''
69
+ @doc.save.should == false
70
+ @doc.errors.count.should == 1
71
+ @doc.errors.on(:client_id).should == "can't be blank"
72
+ end
73
+ end
74
+
75
+ describe SKApi::Resources::CreditNote, "with line items" do
76
+
77
+ before :all do
78
+ @client = SKApi::Resources::Client.new(:organisation=>'Credit Note API-Tester')
79
+ @client.save.should be_true
80
+ #setup test doc to work with
81
+ @doc = SKApi::Resources::CreditNote.new(:client_id => @client.id,
82
+ :line_items => [{ :position=>1, :description => 'Pork Chops', :quantity => 12, :price_single =>'10.00' }] )
83
+ @doc.save.should be_true
84
+ end
85
+
86
+ after :all do
87
+ @client.destroy #also destroys all docs
88
+ # @doc.destroy
89
+ lambda {
90
+ doc = SKApi::Resources::CreditNote.find(@doc.id)
91
+ }.should raise_error(ActiveResource::ResourceNotFound)
92
+ end
93
+
94
+ it "should create a line item" do
95
+ @doc.line_items.length.should == 1
96
+ @doc.line_items.first.description.should == 'Pork Chops'
97
+ @doc.price_total.should == 120.0
98
+ end
99
+
100
+ it "should edit line item" do
101
+ @doc.line_items[0].description = 'Egg Sandwich'
102
+ @doc.save
103
+ @doc.line_items.length.should == 1
104
+ @doc.line_items.first.description.should == 'Egg Sandwich'
105
+ end
106
+
107
+ it "should add line item" do
108
+ item = SKApi::Resources::LineItem.new( { :position=>2, :description => 'Goat-Pie', :price_single => 10, :quantity=>10} )
109
+ @doc.line_items << item
110
+ @doc.save
111
+ @doc.line_items.length.should == 2
112
+ @doc.price_total.should == 220.0
113
+ # @doc.line_items[0].zip = '40001'
114
+ # @doc.line_items.[1].zip.should == '40001'
115
+ end
116
+ end
@@ -0,0 +1,77 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ describe SKApi::Resources::Product, "in general" do
4
+
5
+ before :all do
6
+ #setup test product to work with
7
+ @product = SKApi::Resources::Product.new(:name=>'Eis am Stiel', :price => 1.50)
8
+ @product.save.should be_true
9
+ end
10
+
11
+ after :all do
12
+ #delete test product
13
+ @product.destroy
14
+ lambda {
15
+ product = SKApi::Resources::Product.find(@product.id)
16
+ }.should raise_error(ActiveResource::ResourceNotFound)
17
+ end
18
+
19
+ it "should create a product" do
20
+ @product.number.should_not be_nil
21
+ @product.price.should == 1.50
22
+ @product.new?.should be_false
23
+ end
24
+
25
+ it "should fail create a product without name" do
26
+ product = SKApi::Resources::Product.new(:price => 2.50)
27
+ product.save.should == false
28
+ product.errors.count.should == 1
29
+ product.errors.full_messages.should == ["Name can't be blank"]
30
+ end
31
+
32
+ it "should create a product with price 0.0 when price is missing" do
33
+ product = SKApi::Resources::Product.new(:name => 'No brain')
34
+ product.save
35
+ # product.save.should == false
36
+ product.price.should == 0.0
37
+ end
38
+
39
+ it "should find a product by id" do
40
+ product = SKApi::Resources::Product.find(@product.id)
41
+ product.name.should == @product.name
42
+ end
43
+
44
+ it "should edit a product" do
45
+ @product.name = 'A new product name'
46
+ @product.lock_version.should == 0
47
+ @product.save
48
+ @product.lock_version.should == 1 # because save returns the data
49
+ end
50
+
51
+ it "should fail edit a product" do
52
+ @product.name = ''
53
+ @product.save.should == false
54
+ @product.errors.count.should == 1
55
+ @product.errors.on(:name).should == "can't be blank"
56
+ end
57
+
58
+ it "should validate raw json object with schema" do
59
+ product = SKApi::Resources::Product.find(@product.id)
60
+ # convert to json and read raw without activeresource assigning classes
61
+ json = product.to_json
62
+ obj = Rufus::Json.decode(json)
63
+ lambda {
64
+ JSON::Schema.validate(obj, SKApi::Resources::Product.schema)
65
+ }.should_not raise_error
66
+ end
67
+
68
+ it "should validate raw json object with to_hash_with_schema" do
69
+ product = SKApi::Resources::Product.find(@product.id)
70
+ # convert to json and read raw without activeresource assigning classes
71
+ hash_obj = SKApi::Resources::Product.to_hash_from_schema(product)
72
+ # hash_obj.should == ''
73
+ lambda {
74
+ JSON::Schema.validate(hash_obj['product'], SKApi::Resources::Product.schema)
75
+ }.should_not raise_error
76
+ end
77
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require "#{File.dirname(__FILE__)}/../lib/sk_api"
4
+
5
+ ##
6
+ SKApi::CONNECTION = {
7
+ :site => "http://demo.salesking.local:3000/api/",
8
+ :user => "demo@salesking.eu",
9
+ :password => "demo",
10
+ :format => :json
11
+ }
12
+ SKApi::Resources::Base.set_connection(SKApi::CONNECTION)
@@ -0,0 +1,73 @@
1
+ require "#{File.dirname(__FILE__)}/../spec_helper"
2
+
3
+ describe SKApi::Utils::FieldMap do
4
+
5
+ before :each do
6
+ @loc_obj = LocalContact.new
7
+ @rem_obj = RemoteContact.new()
8
+ @map = SKApi::Utils::FieldMap.new(@loc_obj, @rem_obj, map_hash)
9
+ end
10
+
11
+ it "should create a mapping" do
12
+ @map.outdated?.should be_false # both objects are empty
13
+ end
14
+
15
+ it "should find outdated fields" do
16
+ @loc_obj.firstname = 'theo'
17
+ @map.outdated?.should be_true
18
+ @map.outdated.first[:loc_key].should == :firstname
19
+ end
20
+
21
+ it "should update outdated remote fields" do
22
+ @loc_obj.firstname = 'theo'
23
+ @map.update_remote_outdated
24
+ @rem_obj.first_name.should == @loc_obj.firstname
25
+ # test logging
26
+ @map.log.should_not be_empty
27
+ end
28
+
29
+ it "should update outdated local fields" do
30
+ @rem_obj.first_name = 'Heinz'
31
+ @map.update_local_outdated
32
+ @rem_obj.first_name.should == @loc_obj.firstname
33
+ @map.log.length.should == 1
34
+ end
35
+ # it "should update outdated local fields" do
36
+ # @rem_obj.first_name = 'Heinz'
37
+ # @map.outdated?
38
+ # @map.update_local_outdated
39
+ # @rem_obj.first_name.should == @loc_obj.firstname
40
+ # end
41
+
42
+ def map_hash
43
+ [
44
+ {:loc_key => :firstname, :rem_key => :first_name},
45
+ {:loc_key => :street, :rem_key => :address1},
46
+ {:loc_key => :postcode, :rem_key => :zip},
47
+ {:loc_key => :city, :rem_key => :city},
48
+ {:loc_key => :gender, :rem_key => :gender, :trans => { :obj=>'TransferFunctions',
49
+ :loc_trans => 'set_local_gender',
50
+ :rem_trans => 'set_remote_gender'}
51
+ }
52
+ ]
53
+ end
54
+
55
+ end
56
+
57
+ class RemoteContact
58
+ attr_accessor :first_name, :address1, :zip, :city, :gender
59
+ end
60
+ class LocalContact
61
+ attr_accessor :firstname, :street, :postcode, :city, :gender
62
+ end
63
+
64
+ class TransferFunctions
65
+ def self.set_local_gender(remote_val)
66
+ return 'male' if remote_val == 'm'
67
+ return 'female' if remote_val == 'f'
68
+ end
69
+ def self.set_remote_gender(local_val)
70
+ return 'm' if local_val == 'male'
71
+ return 'f' if local_val == 'female'
72
+ end
73
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :sk_api_base do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,94 @@
1
+ = Ruby/jsonschema
2
+
3
+ * http://github.com/Constellation/jsonchema
4
+
5
+ == DESCRIPTION:
6
+
7
+ json schema library ruby porting
8
+ from http://code.google.com/p/jsonschema/
9
+
10
+ == SYNOPSIS:
11
+ ruby code
12
+ require 'jsonschema'
13
+ schema = {
14
+ "type" => "object",
15
+ "properties" => {
16
+ "prop01" => {
17
+ "type" => "number",
18
+ "maximum" => 10
19
+ },
20
+ "prop02" => {
21
+ "type" => "integer",
22
+ "maximum" => 20
23
+ }
24
+ }
25
+ }
26
+ data = {
27
+ "prop01"=> 5,
28
+ "prop02"=> 10
29
+ }
30
+ JSON::Schema.validate(data, schema)
31
+
32
+ if you have json library
33
+ require 'json'
34
+ require 'jsonschema'
35
+ schema = File.open("path/to/schema.json", "rb"){|f| JSON.parse(f.read)}
36
+ data = File.open("path/to/data.json", "rb"){|f| JSON.parse(f.read)}
37
+ JSON::Schema.validate(data, schema)
38
+
39
+ == INSTALL:
40
+
41
+ gem source -a http://gemcutter.org
42
+ sudo gem install jsonschema
43
+
44
+ == LICENSE:
45
+
46
+ Ruby/jsonschema
47
+ (The MIT License)
48
+
49
+ Copyright (c) 2009 Constellation
50
+
51
+ Permission is hereby granted, free of charge, to any person obtaining
52
+ a copy of this software and associated documentation files (the
53
+ 'Software'), to deal in the Software without restriction, including
54
+ without limitation the rights to use, copy, modify, merge, publish,
55
+ distribute, sublicense, and/or sell copies of the Software, and to
56
+ permit persons to whom the Software is furnished to do so, subject to
57
+ the following conditions:
58
+
59
+ The above copyright notice and this permission notice shall be
60
+ included in all copies or substantial portions of the Software.
61
+
62
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
63
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
64
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
65
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
66
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
67
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
68
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
69
+
70
+
71
+ jsonschema
72
+ http://code.google.com/p/jsonschema/
73
+ (The MIT License)
74
+
75
+ Copyright (c) 2008 Ian Lewis, Yusuke Muraoka
76
+
77
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
78
+ this software and associated documentation files (the "Software"), to deal in
79
+ the Software without restriction, including without limitation the rights to
80
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
81
+ of the Software, and to permit persons to whom the Software is furnished to do
82
+ so, subject to the following conditions:
83
+
84
+ The above copyright notice and this permission notice shall be included in all
85
+ copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
88
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
89
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
90
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
91
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
92
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
93
+ SOFTWARE.
94
+
@@ -0,0 +1,94 @@
1
+ # vim: fileencoding=utf-8
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rake/clean'
5
+ require 'rake/testtask'
6
+ require 'rake/packagetask'
7
+ require 'rake/gempackagetask'
8
+ require 'rake/rdoctask'
9
+ require 'rake/contrib/rubyforgepublisher'
10
+ require 'rake/contrib/sshpublisher'
11
+ require 'fileutils'
12
+ require 'lib/jsonschema'
13
+ include FileUtils
14
+
15
+ $version = JSON::Schema::VERSION
16
+ $readme = 'README.rdoc'
17
+ $rdoc_opts = %W(--main #{$readme} --charset utf-8 --line-numbers --inline-source)
18
+ $name = 'jsonschema'
19
+ $github_name = 'ruby-jsonschema'
20
+ $summary = 'json schema library ruby porting from http://code.google.com/p/jsonschema/'
21
+ $author = 'Constellation'
22
+ $email = 'utatane.tea@gmail.com'
23
+ $page = 'http://github.com/Constellation/ruby-jsonchema/tree/master'
24
+ #$exec = %W(jsonschema)
25
+ $rubyforge_project = 'jsonschema'
26
+
27
+
28
+ task :default => [:test]
29
+ task :package => [:clean]
30
+
31
+ Rake::TestTask.new("test") do |t|
32
+ t.libs << "test"
33
+ t.pattern = "test/**/*_test.rb"
34
+ t.verbose = true
35
+ end
36
+
37
+ spec = Gem::Specification.new do |s|
38
+ s.name = $name
39
+ s.version = $version
40
+ s.platform = Gem::Platform::RUBY
41
+ s.has_rdoc = true
42
+ s.extra_rdoc_files = [$readme]
43
+ s.rdoc_options += $rdoc_opts
44
+ s.summary = $summary
45
+ s.description = $summary
46
+ s.author = $author
47
+ s.email = $email
48
+ s.homepage = $page
49
+ s.executables = $exec
50
+ s.rubyforge_project = $rubyforge_project
51
+ # s.bindir = 'bin'
52
+ s.require_path = 'lib'
53
+ s.test_files = Dir["test/*_test.rb"]
54
+ # {
55
+ # }.each do |dep, ver|
56
+ # s.add_dependency(dep, ver)
57
+ # end
58
+ s.files = %w(README.rdoc Rakefile) + Dir["{bin,test,lib}/**/*"]
59
+ end
60
+
61
+ Rake::GemPackageTask.new(spec) do |p|
62
+ p.need_tar = true
63
+ p.gem_spec = spec
64
+ end
65
+
66
+ Rake::RDocTask.new do |rdoc|
67
+ rdoc.rdoc_dir = 'doc'
68
+ rdoc.options += $rdoc_opts
69
+ # rdoc.template = 'resh'
70
+ rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb", "ext/**/*.c")
71
+ end
72
+
73
+ desc "gem spec"
74
+ task :gemspec do
75
+ File.open("#{$github_name}.gemspec", "wb") do |f|
76
+ f << spec.to_ruby
77
+ end
78
+ end
79
+
80
+ desc "gem build"
81
+ task :build => [:gemspec] do
82
+ sh "gem build #{$github_name}.gemspec"
83
+ end
84
+
85
+ desc "gem install"
86
+ task :install => [:build] do
87
+ sh "sudo gem install #{$name}-#{$version}.gem --local"
88
+ end
89
+
90
+ desc "gem uninstall"
91
+ task :uninstall do
92
+ sh "sudo gem uninstall #{$name}"
93
+ end
94
+ # vim: syntax=ruby