capcode-base-activerecord 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
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-activerecord
2
+
3
+ Capcode plugin to access databases via ActiveRecord
@@ -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-activerecord"
8
+ gem.summary = %Q{Capcode plugin to access databases via ActiveRecord}
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('active_record')
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,49 @@
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-activerecord}
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-06}
13
+ s.description = %q{Capcode plugin to access databases via ActiveRecord}
14
+ s.email = %q{gregoire.lejeune@free.fr}
15
+ s.extra_rdoc_files = [
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION",
25
+ "capcode-base-activerecord.gemspec",
26
+ "examples/blog-ar.rb",
27
+ "examples/blog-ar.yml",
28
+ "lib/capcode/base/ar.rb"
29
+ ]
30
+ s.homepage = %q{http://github.com/glejeune/Capcode.more/tree/master/capcode-base-activerecord}
31
+ s.rdoc_options = ["--charset=UTF-8"]
32
+ s.require_paths = ["lib"]
33
+ s.rubygems_version = %q{1.3.5}
34
+ s.summary = %q{Capcode plugin to access databases via ActiveRecord}
35
+
36
+ if s.respond_to? :specification_version then
37
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
38
+ s.specification_version = 3
39
+
40
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
41
+ s.add_runtime_dependency(%q<active_record>, [">= 0"])
42
+ else
43
+ s.add_dependency(%q<active_record>, [">= 0"])
44
+ end
45
+ else
46
+ s.add_dependency(%q<active_record>, [">= 0"])
47
+ end
48
+ end
49
+
@@ -0,0 +1,81 @@
1
+ $:.unshift( "../lib" )
2
+ require 'rubygems'
3
+ require 'capcode'
4
+ require 'capcode/base/ar'
5
+
6
+ class Basic < Capcode::Model 1.0
7
+ def self.up
8
+ create_table :stories do |t|
9
+ t.string :title
10
+ t.string :body
11
+ t.string :date
12
+ end
13
+ end
14
+ end
15
+
16
+ class UpdateBasic < Capcode::Model 1.1
17
+ def self.up
18
+ create_table :users do |t|
19
+ t.string :name
20
+ t.string :password
21
+ end
22
+ end
23
+
24
+ def self.down
25
+ drop_table :users
26
+ end
27
+ end
28
+
29
+ class Story < Capcode::Base
30
+ include Capcode::Resource
31
+ end
32
+
33
+ module Capcode
34
+ class HTTPError
35
+ def r404(f)
36
+ "Pas glop !!! #{f} est inconnu !!!"
37
+ end
38
+ end
39
+
40
+ class Index < Route '/'
41
+ def get
42
+ r = "<html><body>"
43
+
44
+ story = Story.all
45
+
46
+ story.each do |s|
47
+ r += "<h2>#{s.title}</h2><small>#{s.date} - <a href='#{URL( Remove, s.id )}'>Delete this entry</a></small><p>#{s.body}</p>"
48
+ end
49
+
50
+ r+"<hr /><a href='#{URL(Add)}'>Add a new entry</a></body></html>"
51
+ end
52
+ end
53
+
54
+ class Remove < Route '/remove/([^\/]*)'
55
+ def get( id )
56
+ Story.delete(id)
57
+ redirect( Index )
58
+ end
59
+ end
60
+
61
+ class Add < Route '/add'
62
+ def get
63
+ '
64
+ <html><body>
65
+ <h1>Add a new entry</h1>
66
+ <form method="POST">
67
+ Titre : <input type="text" name="title"><br />
68
+ <textarea name="body"></textarea><br />
69
+ <input type="submit">
70
+ </form>
71
+ </body></html>
72
+ '
73
+ end
74
+ def post
75
+ Story.new( :title => params['title'], :body => params['body'], :date => Time.now.to_s ).save
76
+ redirect( Index )
77
+ end
78
+ end
79
+ end
80
+
81
+ Capcode.run( :port => 3001, :host => "localhost", :db_config => "blog-ar.yml" )
@@ -0,0 +1,3 @@
1
+ adapter: sqlite3
2
+ database: ar_blog.db
3
+ schema_version: 1.0
@@ -0,0 +1,54 @@
1
+ begin
2
+ require 'active_record'
3
+ rescue LoadError => e
4
+ raise Capcode::MissingLibrary, "ActiveRecord could not be loaded (is it installed?): #{e.message}"
5
+ end
6
+
7
+ module Capcode
8
+ # This module contains the resources needed in a model
9
+ module Resource
10
+ end
11
+
12
+ # This class allow you to define models
13
+ Base = ActiveRecord::Base
14
+
15
+ # Schema info
16
+ class SchemaInfo < Base
17
+ end
18
+
19
+ class << self
20
+ # This class allow you to define models
21
+ def Model( n )
22
+ @final = [n, @final.to_f].max
23
+ m = (@migrations ||= [])
24
+ Class.new(ActiveRecord::Migration) do
25
+ meta_def(:version) { n }
26
+ meta_def(:inherited) { |k| m << k }
27
+ end
28
+ end
29
+
30
+ def db_connect( dbfile, logfile ) #:nodoc:
31
+ dbconfig = YAML::load(File.open(dbfile)).keys_to_sym
32
+ version = dbconfig.delete(:schema_version) { |_| @final }
33
+
34
+ ActiveRecord::Base.establish_connection(dbconfig)
35
+ ActiveRecord::Base.logger = Logger.new(logfile)
36
+
37
+ if @migrations
38
+ unless SchemaInfo.table_exists?
39
+ ActiveRecord::Schema.define do
40
+ create_table SchemaInfo.table_name do |t|
41
+ t.column :version, :float
42
+ end
43
+ end
44
+ end
45
+ si = SchemaInfo.find(:first) || SchemaInfo.new(:version => 0)
46
+ @migrations.each do |k|
47
+ k.migrate(:up) if si.version < k.version and k.version <= version
48
+ k.migrate(:down) if si.version >= k.version and k.version > version
49
+ end
50
+ si.update_attributes(:version => version)
51
+ end
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capcode-base-activerecord
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-06 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: active_record
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 ActiveRecord
26
+ email: gregoire.lejeune@free.fr
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - .document
35
+ - .gitignore
36
+ - LICENSE
37
+ - README.rdoc
38
+ - Rakefile
39
+ - VERSION
40
+ - capcode-base-activerecord.gemspec
41
+ - examples/blog-ar.rb
42
+ - examples/blog-ar.yml
43
+ - lib/capcode/base/ar.rb
44
+ has_rdoc: true
45
+ homepage: http://github.com/glejeune/Capcode.more/tree/master/capcode-base-activerecord
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options:
50
+ - --charset=UTF-8
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: "0"
64
+ version:
65
+ requirements: []
66
+
67
+ rubyforge_project:
68
+ rubygems_version: 1.3.5
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Capcode plugin to access databases via ActiveRecord
72
+ test_files: []
73
+