merb_strokedb 1

Sign up to get free protection for your applications and to get access to all the features.
data/.manifest ADDED
@@ -0,0 +1,12 @@
1
+ example_merb_app/application.rb
2
+ example_merb_app/config/framework.rb
3
+ example_merb_app/config/init.rb
4
+ example_merb_app/config/store.yml
5
+ example_merb_app/views/test.html.haml
6
+ lib/merb/orms/strokedb/connection.rb
7
+ lib/merb/orms/strokedb/store.example.yml
8
+ lib/merb_strokedb/strokedb.task
9
+ lib/merb_strokedb.rb
10
+ README.mkdn
11
+ task/echoe.task
12
+ .manifest
data/README.mkdn ADDED
@@ -0,0 +1,71 @@
1
+ rdie
2
+ ====
3
+
4
+ merb_strokedb is a simple plugin for [Merb][] that allows you to use [StrokeDB][]
5
+ as an 'ORM' in your Merb applications.
6
+
7
+ [Merb]: <http://merbivore.com> (Merb homepage)
8
+ [StrokeDB]: <http://strokedb.com> (StrokeDB homepage)
9
+
10
+ Getting
11
+ -------
12
+
13
+ You can install merb_strokedb using the following command:
14
+
15
+ sudo gem install merb_strokedb
16
+
17
+ The authoritative source for this project is available at
18
+ <http://github.com/elliottcable/merb_strokedb>. You can clone your own copy with the
19
+ following command:
20
+
21
+ git clone git://github.com/elliottcable/merb_strokedb.git
22
+
23
+ If you want to make changes to the codebase, you need to fork your own github
24
+ repository for said changes. Send a pullrequest to [elliottcable][GitHub]
25
+ when you've got something ready for the master that you think should be
26
+ integrated into the root source.
27
+
28
+ [GitHub]: <http://github.com/elliottcable> (elliottcable on GitHub)
29
+
30
+ Requirements
31
+ ------------
32
+
33
+ To integrate merb_strokedb into your own apps, you need the following gems:
34
+
35
+ * merb-core (see below)
36
+ * strokedb (see below)
37
+
38
+ To develop and contribute to merb_strokedb, you also need:
39
+
40
+ * rspec
41
+ * rake
42
+ * rcov
43
+
44
+ merb-core
45
+ ---------
46
+
47
+ As it currently stands, merb_strokedb is only compatible with merb master.
48
+
49
+ To easily install the current merb master, install them with the merb-dev
50
+ Sakefile as follows:
51
+
52
+ sudo gem install sake
53
+ mkdir -p ~/.ruby; cd ~/.ruby
54
+ sake -i http://github.com/ivey/merb-dev/tree/master/merb-dev.rake?raw=true
55
+ sake merb:clone
56
+ cd ~/.ruby/merb
57
+ sudo sake merb:gems:wipe
58
+ sudo sake merb:install
59
+
60
+ Licensing
61
+ ---------
62
+
63
+ This software package is currently released under the terms of the
64
+ [Creative Commons Attribution-ShareAlike 3.0][1] license (and any later
65
+ version, at the discretion of the user). If you wish to use this code in a
66
+ project licensed under the GPL, hold on tight! The next version will likely be
67
+ dual-licensed under the CC and GNU licenses, to allow exactly that (my
68
+ licensing scheme is under review by a lawyer at the moment, I want to ensure
69
+ it is air-tight).
70
+
71
+ [1]: <http://creativecommons.org/licenses/by-sa/3.0/> (Creative Commons Attribution-ShareAlike 3.0 license)
@@ -0,0 +1,26 @@
1
+ Fruit = StrokeDB::Meta.new
2
+
3
+ class SdbTest < Merb::Controller
4
+
5
+ def _template_location(action, type = nil, controller = controller_name)
6
+ controller == "layout" ? "layout.#{action}.#{type}" : "#{action}.#{type}"
7
+ end
8
+
9
+ def index
10
+ @apple = Fruit.new
11
+ @apple.save!
12
+ "#{CGI::escapeHTML(@apple.inspect)}"
13
+ end
14
+
15
+ def test
16
+ @orange = Fruit.new
17
+ @orange.save!
18
+ render
19
+ end
20
+
21
+ def list
22
+ @fruitcake = Fruit.find
23
+ "#{CGI::escapeHTML(@fruitcake.inspect)}"
24
+ end
25
+
26
+ end
@@ -0,0 +1,6 @@
1
+ Merb::Config[:framework] = {
2
+ :application => "application.rb",
3
+ :view => "views",
4
+ :model => "models",
5
+ :config => "config"
6
+ }
@@ -0,0 +1,33 @@
1
+ # Move this to application.rb if you want it to be reloadable in dev mode.
2
+ Merb::Router.prepare do |r|
3
+ r.match('/').to(:controller => 's_d_b_test', :action =>'index')
4
+ r.default_routes
5
+ end
6
+
7
+
8
+ Merb::Config.use { |c|
9
+ c[:environment] = 'production',
10
+ c[:framework] = {},
11
+ c[:log_level] = 'debug',
12
+ c[:use_mutex] = false,
13
+ c[:session_store] = 'cookie',
14
+ c[:session_id_key] = '_session_id',
15
+ c[:session_secret_key] = 'c1d41384ec11f78e2bf0a44cedf3976fa112b5f5',
16
+ c[:exception_details] = true,
17
+ c[:reload_classes] = true,
18
+ c[:reload_time] = 0.5
19
+ }
20
+
21
+ # Development StrokeDB
22
+ STROKEDB_PATH = '/Users/elliottcable/Documents/Work/Code/strokedb'
23
+ raise 'You need to set STROKEDB_PATH in config/init.rb!' unless STROKEDB_PATH
24
+ require STROKEDB_PATH + '/strokedb-ruby/strokedb.rb'
25
+
26
+ # Development merb_strokedb
27
+ MERB_STROKEDB_PATH = '/Users/elliottcable/Documents/Work/Code/merb_strokedb'
28
+ raise 'You need to set MERB_STROKEDB_PATH in config/init.rb!' unless MERB_STROKEDB_PATH
29
+ $LOAD_PATH.unshift(MERB_STROKEDB_PATH + '/lib').uniq!
30
+
31
+ use_orm :strokedb
32
+
33
+ dependency 'merb-haml', '> 0.9'
@@ -0,0 +1,15 @@
1
+ ---
2
+ # This is a sample configuration file for StrokeDB
3
+ :development: &defaults
4
+ :threadsafe: false
5
+ :database: development
6
+
7
+ :test:
8
+ <<: *defaults
9
+ :database: test
10
+
11
+ :production:
12
+ <<: *defaults
13
+ :threadsafe: true
14
+ :port: 9999
15
+ :database: production
@@ -0,0 +1 @@
1
+ %pre= CGI::escapeHTML(@orange.inspect)
@@ -0,0 +1,80 @@
1
+ require 'fileutils'
2
+ require 'strokedb' unless Object.const_defined? 'StrokeDB'
3
+
4
+ module Merb
5
+ module Orms
6
+
7
+ module StrokeDB
8
+ THREADS = []
9
+
10
+ class << self
11
+ def config_file() Merb.root / "config" / "store.yml" end
12
+ def sample_dest() Merb.root / "config" / "store.example.yml" end
13
+ def sample_source() File.dirname(__FILE__) / "store.example.yml" end
14
+
15
+ def copy_sample_config
16
+ FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
17
+ end
18
+
19
+ def config
20
+ @config ||=
21
+ begin
22
+ # Convert string keys to symbols
23
+ full_config = Erubis.load_yaml_file(config_file)
24
+ config = (Merb::Plugins.config[:merb_strokedb] = {})
25
+
26
+ envd_config = (full_config[Merb.environment.to_sym] || full_config[Merb.environment])
27
+ envd_config.each do |k, v|
28
+ if k == 'port'
29
+ config[k.to_sym] = v.to_i
30
+ else
31
+ config[k.to_sym] = v
32
+ end
33
+ end
34
+ config
35
+ end
36
+ end
37
+
38
+ # Database connects as soon as the gem is loaded
39
+ def connect
40
+ if File.exists?(config_file)
41
+ Merb.logger.info!("Setting up & connecting to database db/#{config[:database]}.strokedb...")
42
+ ::StrokeDB.use_global_default_config!
43
+
44
+ if config[:threadsafe]
45
+ Merb.logger.info!("Starting StrokeDB DRb server on druby://localhost:#{config[:port]}...")
46
+ # Create the server, and detach...
47
+ ::StrokeDB::Config.build :default => true, :base_path => "db/#{config[:database]}.strokedb"
48
+ Merb::Orms::StrokeDB::THREADS <<
49
+ ::StrokeDB.default_store.remote_server("druby://localhost:#{config[:port]}").start
50
+
51
+ Merb::Orms::StrokeDB::THREADS.map do |thread|
52
+ ::Kernel.fork { thread.join }
53
+ end
54
+
55
+
56
+ # Reattach to the now-running server
57
+ ::StrokeDB.default_store = ::StrokeDB::RemoteStore::DRb::Client.new("druby://localhost:#{config[:port]}")
58
+ else
59
+ ::StrokeDB::Config.build :default => true, :base_path => "db/#{config[:database]}.strokedb"
60
+ end
61
+ else
62
+ copy_sample_config
63
+ Merb.logger.warn "No store.yml file found in #{Merb.root}/config."
64
+ Merb.logger.warn "A sample file was created called store.example.yml for you to copy and edit."
65
+ exit(1)
66
+ end
67
+ end
68
+
69
+ # Registering this ORM lets the user choose StrokeDB as a session store
70
+ # in merb.yml's session_store: option. No idea if this works, correctly...?
71
+ def register_session_type
72
+ Merb.register_session_type("strokedb",
73
+ "merb/session/strokedb_session",
74
+ "Using StrokeDB sessions")
75
+ end
76
+ end
77
+ end
78
+
79
+ end
80
+ end
@@ -0,0 +1,15 @@
1
+ ---
2
+ # This is a sample configuration file for StrokeDB
3
+ :development: &defaults
4
+ :threadsafe: false
5
+ :database: development
6
+
7
+ :test:
8
+ <<: *defaults
9
+ :database: test
10
+
11
+ :production:
12
+ <<: *defaults
13
+ :threadsafe: true
14
+ :port: 9999
15
+ :database: production
@@ -0,0 +1,23 @@
1
+ if defined?(Merb::Plugins)
2
+ module Merb::Orms
3
+
4
+ module StrokeDB
5
+ VERSION = '1'
6
+ end
7
+
8
+ end
9
+
10
+ require File.join(File.dirname(__FILE__) / :merb / :orms / :strokedb / :connection)
11
+ Merb::Plugins.add_rakefiles 'merb_strokedb' / 'strokedb.task'
12
+
13
+ class Merb::Orms::StrokeDB::Connect < Merb::BootLoader
14
+
15
+ after BeforeAppRuns
16
+
17
+ def self.run
18
+ Merb::Orms::StrokeDB.connect
19
+ # Merb::Orms::DataMapper.register_session_type
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ namespace :stroke do
2
+
3
+ # Nothing here yet!
4
+
5
+ end
@@ -0,0 +1,67 @@
1
+
2
+ # Gem::Specification for Merb_strokedb-1
3
+ # Originally generated by Echoe
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{merb_strokedb}
7
+ s.version = "1"
8
+
9
+ s.specification_version = 2 if s.respond_to? :specification_version=
10
+
11
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.authors = ["elliottcable"]
13
+ s.date = %q{2008-04-19}
14
+ s.description = %q{a plugin for Merb, that allows the use of StrokeDB as an ORM within a Merb application}
15
+ s.email = ["merb_strokedb@elliottcable.com"]
16
+ s.extra_rdoc_files = ["lib/merb/orms/strokedb/connection.rb", "lib/merb/orms/strokedb/store.example.yml", "lib/merb_strokedb/strokedb.task", "lib/merb_strokedb.rb", "README.mkdn"]
17
+ s.files = ["example_merb_app/application.rb", "example_merb_app/config/framework.rb", "example_merb_app/config/init.rb", "example_merb_app/config/store.yml", "example_merb_app/views/test.html.haml", "lib/merb/orms/strokedb/connection.rb", "lib/merb/orms/strokedb/store.example.yml", "lib/merb_strokedb/strokedb.task", "lib/merb_strokedb.rb", "README.mkdn", "task/echoe.task", ".manifest", "merb_strokedb.gemspec"]
18
+ s.has_rdoc = true
19
+ s.homepage = %q{http://find.elliottcable.name/merb_strokedb}
20
+ s.post_install_message = %q{ - Thanks for installing merb_strokedb!
21
+ - Add this to your config/init.rb to get started:
22
+ - use_orm :strokedb}
23
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Merb_strokedb", "--main", "README.mkdn"]
24
+ s.require_paths = ["lib"]
25
+ s.rubyforge_project = %q{merb-strokedb}
26
+ s.rubygems_version = %q{1.1.1}
27
+ s.summary = %q{StrokeDB plugin for Merb}
28
+
29
+ s.add_dependency(%q<merb-core>, [">= 0"])
30
+ s.add_dependency(%q<strokedb>, [">= 0"])
31
+ end
32
+
33
+
34
+ # # Original Rakefile source (requires the Echoe gem):
35
+ #
36
+ # require 'rubygems'; require 'merb-core'
37
+ # $:.unshift(File.dirname(__FILE__) + '/lib'); require 'merb_strokedb'
38
+ # Dir['task/**/*.task'].each {|t| load t}
39
+ #
40
+ # Echoe.taskify do
41
+ # Echoe.new('merb_strokedb', Merb::Orms::StrokeDB::VERSION) do |g|
42
+ # g.author = ['elliottcable']
43
+ # g.email = ['merb_strokedb@elliottcable.com']
44
+ # g.summary = 'StrokeDB plugin for Merb'
45
+ # g.url = 'http://find.elliottcable.name/merb_strokedb'
46
+ # g.description = 'a plugin for Merb, that allows the use of StrokeDB as an ORM within a Merb application'
47
+ # g.dependencies = ['merb-core', 'strokedb']
48
+ # g.manifest_name = '.manifest'
49
+ # g.ignore_pattern = /(^\.git|^example_merb_app\/(db|log))/
50
+ # g.project = 'merb-strokedb'
51
+ # g.install_message = " - Thanks for installing merb_strokedb!\n" +
52
+ # " - Add this to your config/init.rb to get started:\n"+
53
+ # " - use_orm :strokedb"
54
+ # end
55
+ #
56
+ # desc 'tests packaged files to ensure they are all present'
57
+ # task :verify => :package do
58
+ # # An error message will be displayed if files are missing
59
+ # if system %(ruby -e "require 'rubygems'; require 'merb-core'; require 'pkg/merb_strokedb-#{Merb::Orms::StrokeDB::VERSION}/lib/merb_strokedb'")
60
+ # puts "\nThe library files are present"
61
+ # end
62
+ # end
63
+ #
64
+ # # desc 'Run specs, clean tree, update manifest, run coverage, and install gem!'
65
+ # desc 'Clean tree, update manifest, and install gem!'
66
+ # task :magic => [:clean, :manifest, :install]
67
+ # end
data/task/echoe.task ADDED
@@ -0,0 +1,14 @@
1
+ class Echoe
2
+ def self.taskify(&block)
3
+
4
+ begin
5
+ require 'echoe'
6
+ yield
7
+ rescue LoadError
8
+ puts "(You need to install the echoe and rspec gems if you wish to" +
9
+ " perform meta-gem operations, such as installing from source or" +
10
+ " running specs)"
11
+ end
12
+
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: merb_strokedb
3
+ version: !ruby/object:Gem::Version
4
+ version: "1"
5
+ platform: ruby
6
+ authors:
7
+ - elliottcable
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-19 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: merb-core
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: strokedb
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: "0"
32
+ version:
33
+ description: a plugin for Merb, that allows the use of StrokeDB as an ORM within a Merb application
34
+ email:
35
+ - merb_strokedb@elliottcable.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - lib/merb/orms/strokedb/connection.rb
42
+ - lib/merb/orms/strokedb/store.example.yml
43
+ - lib/merb_strokedb/strokedb.task
44
+ - lib/merb_strokedb.rb
45
+ - README.mkdn
46
+ files:
47
+ - example_merb_app/application.rb
48
+ - example_merb_app/config/framework.rb
49
+ - example_merb_app/config/init.rb
50
+ - example_merb_app/config/store.yml
51
+ - example_merb_app/views/test.html.haml
52
+ - lib/merb/orms/strokedb/connection.rb
53
+ - lib/merb/orms/strokedb/store.example.yml
54
+ - lib/merb_strokedb/strokedb.task
55
+ - lib/merb_strokedb.rb
56
+ - README.mkdn
57
+ - task/echoe.task
58
+ - .manifest
59
+ - merb_strokedb.gemspec
60
+ has_rdoc: true
61
+ homepage: http://find.elliottcable.name/merb_strokedb
62
+ post_install_message: " - Thanks for installing merb_strokedb!\n - Add this to your config/init.rb to get started:\n - use_orm :strokedb"
63
+ rdoc_options:
64
+ - --line-numbers
65
+ - --inline-source
66
+ - --title
67
+ - Merb_strokedb
68
+ - --main
69
+ - README.mkdn
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: "0"
77
+ version:
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: "0"
83
+ version:
84
+ requirements: []
85
+
86
+ rubyforge_project: merb-strokedb
87
+ rubygems_version: 1.1.1
88
+ signing_key:
89
+ specification_version: 2
90
+ summary: StrokeDB plugin for Merb
91
+ test_files: []
92
+