capcode-base-sequel 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 glejeune
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = capcode-base-sequel
2
+
3
+ Capcode plugin to access databases via Sequel
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "capcode-base-sequel"
8
+ gem.summary = %Q{Capcode plugin to access databases via Sequel}
9
+ gem.description = gem.summary
10
+ gem.email = "gregoire.lejeune@free.fr"
11
+ gem.homepage = "http://github.com/glejeune/Capcode.more/tree/master/%s" % gem.name
12
+ gem.authors = ["Gregoire Lejeune"]
13
+
14
+ gem.add_dependency('sequel')
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,47 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{capcode-base-sequel}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Gregoire Lejeune"]
12
+ s.date = %q{2010-01-07}
13
+ s.description = %q{Capcode plugin to access databases via Sequel}
14
+ s.email = %q{gregoire.lejeune@free.fr}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "capcode-base-sequel.gemspec",
24
+ "examples/blog-sq.rb",
25
+ "examples/blog-sq.yml",
26
+ "lib/capcode/base/sequel.rb"
27
+ ]
28
+ s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-base-sequel}
29
+ s.rdoc_options = ["--charset=UTF-8"]
30
+ s.require_paths = ["lib"]
31
+ s.rubygems_version = %q{1.3.5}
32
+ s.summary = %q{Capcode plugin to access databases via Sequel}
33
+
34
+ if s.respond_to? :specification_version then
35
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
36
+ s.specification_version = 3
37
+
38
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
39
+ s.add_runtime_dependency(%q<sequel>, [">= 0"])
40
+ else
41
+ s.add_dependency(%q<sequel>, [">= 0"])
42
+ end
43
+ else
44
+ s.add_dependency(%q<sequel>, [">= 0"])
45
+ end
46
+ end
47
+
@@ -0,0 +1,82 @@
1
+ require 'rubygems'
2
+ require 'capcode'
3
+ $:.unshift( "../lib" )
4
+ require 'capcode/base/sequel'
5
+
6
+ class Basic < Capcode::Model 1.0
7
+ def up
8
+ create_table :stories do
9
+ primary_key :id
10
+ String :title
11
+ String :body
12
+ String :date
13
+ end
14
+ end
15
+ end
16
+
17
+ class UpdateBasic < Capcode::Model 1.1
18
+ def up
19
+ create_table :users do
20
+ String :name
21
+ String :password
22
+ end
23
+ end
24
+
25
+ def down
26
+ drop_table :users
27
+ end
28
+ end
29
+
30
+ class Story < Capcode::Base
31
+ include Capcode::Resource
32
+ end
33
+
34
+ module Capcode
35
+ class HTTPError
36
+ def r404(f)
37
+ "Pas glop !!! #{f} est inconnu !!!"
38
+ end
39
+ end
40
+
41
+ class Index < Route '/'
42
+ def get
43
+ r = "<html><body>"
44
+
45
+ story = Story.all
46
+
47
+ story.each do |s|
48
+ r += "<h2>#{s[:title]}</h2><small>#{s[:date]} - <a href='#{URL( Remove, s[:id] )}'>Delete this entry</a></small><p>#{s[:body]}</p>"
49
+ end
50
+
51
+ r+"<hr /><a href='#{URL(Add)}'>Add a new entry</a></body></html>"
52
+ end
53
+ end
54
+
55
+ class Remove < Route '/remove/([^\/]*)'
56
+ def get( id )
57
+ Story.filter(:id => id).delete
58
+ redirect( Index )
59
+ end
60
+ end
61
+
62
+ class Add < Route '/add'
63
+ def get
64
+ '
65
+ <html><body>
66
+ <h1>Add a new entry</h1>
67
+ <form method="POST">
68
+ Titre : <input type="text" name="title"><br />
69
+ <textarea name="body"></textarea><br />
70
+ <input type="submit">
71
+ </form>
72
+ </body></html>
73
+ '
74
+ end
75
+ def post
76
+ Story.insert( :title => params['title'], :body => params['body'], :date => Time.now.to_s )
77
+ redirect( Index )
78
+ end
79
+ end
80
+ end
81
+
82
+ Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-sq.yml" )
@@ -0,0 +1,3 @@
1
+ adapter: sqlite3
2
+ database: sq_blog.db
3
+ schema_version: 1.0
@@ -0,0 +1,58 @@
1
+ begin
2
+ require 'sequel'
3
+ Sequel.extension :migration
4
+ Sequel.extension :inflector
5
+ rescue LoadError => e
6
+ raise Capcode::MissingLibrary, "Sequel could not be loaded (is it installed?): #{e.message}"
7
+ end
8
+
9
+ module Capcode
10
+ # This module contains the resources needed in a model
11
+ module Resource
12
+ end
13
+
14
+ # This class allow you to define models
15
+ class Base
16
+ def self.method_missing( name, *args, &block )
17
+ if block_given?
18
+ Capcode::db[self.to_s.tableize.to_sym].__send__(name.to_sym, *args, &block)
19
+ else
20
+ Capcode::db[self.to_s.tableize.to_sym].__send__(name.to_sym, *args)
21
+ end
22
+ end
23
+ end
24
+
25
+ class << self
26
+ # This class allow you to define models
27
+ def Model( n )
28
+ @final = [n, @final.to_f].max
29
+ m = (@migrations ||= [])
30
+ Class.new(Sequel::Migration) do
31
+ meta_def(:version) { n }
32
+ meta_def(:inherited) { |k| m << k }
33
+ end
34
+ end
35
+
36
+ def db
37
+ @db ||= Sequel.connect(@dbconfig)
38
+ end
39
+
40
+ def db_connect( dbfile, logfile )
41
+ @dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
42
+ @dbconfig[:adapter] = "sqlite" if @dbconfig[:adapter] == "sqlite3"
43
+ version = @dbconfig.delete(:schema_version) { |_| @final }
44
+
45
+ if @migrations
46
+ Capcode::db.create_table? :schema_table do
47
+ Float :version
48
+ end
49
+ si = Capcode::db[:schema_table].first || (Capcode::db[:schema_table].insert(:version => 0); {:version => 0})
50
+ @migrations.each do |k|
51
+ k.apply(Capcode::db, :up) if si[:version] < k.version and k.version <= version
52
+ k.apply(Capcode::db, :down) if si[:version] >= k.version and k.version > version
53
+ end
54
+ Capcode::db[:schema_table].where(:version => si[:version]).update(:version => version)
55
+ end
56
+ end
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capcode-base-sequel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gregoire Lejeune
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-07 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sequel
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: Capcode plugin to access databases via Sequel
26
+ email: gregoire.lejeune@free.fr
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - LICENSE
35
+ - README.rdoc
36
+ - Rakefile
37
+ - VERSION
38
+ - capcode-base-sequel.gemspec
39
+ - examples/blog-sq.rb
40
+ - examples/blog-sq.yml
41
+ - lib/capcode/base/sequel.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-base-sequel
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --charset=UTF-8
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.5
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Capcode plugin to access databases via Sequel
70
+ test_files: []
71
+