neovintage-dm-mysql 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ == 0.0.1 2009-02-23
2
+
3
+ * Initial release
@@ -0,0 +1,11 @@
1
+ History.txt
2
+ Manifest.txt
3
+ Rakefile
4
+ lib/dm-mysql.rb
5
+ lib/dm-mysql/model.rb
6
+ lib/dm-mysql/mysql_adapter.rb
7
+ lib/dm-mysql/version.rb
8
+ README.rdoc
9
+ spec/dm-mysql_spec.rb
10
+ spec/spec_helper.rb
11
+ dm-mysql.gemspec
@@ -0,0 +1,29 @@
1
+ = dm-mysql
2
+
3
+ A plugin that allows you to specify mysql table options when creating
4
+ databases.
5
+
6
+ == LICENSE:
7
+
8
+ (The MIT License)
9
+
10
+ Copyright (c) 2009 Rimas Silkaitis
11
+
12
+ Permission is hereby granted, free of charge, to any person obtaining
13
+ a copy of this software and associated documentation files (the
14
+ 'Software'), to deal in the Software without restriction, including
15
+ without limitation the rights to use, copy, modify, merge, publish,
16
+ distribute, sublicense, and/or sell copies of the Software, and to
17
+ permit persons to whom the Software is furnished to do so, subject to
18
+ the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be
21
+ included in all copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
24
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
28
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
29
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/dm-mysql'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('dm-mysql', DataMapper::Mysql::VERSION) do |p|
7
+ p.developer('Rimas Silkaitis', 'FIXME email')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.rubyforge_name = p.name # TODO this is default value
10
+ p.extra_deps = [
11
+ ['dm-core','>= 0.9.10'],
12
+ ]
13
+ p.extra_dev_deps = [
14
+ ['newgem', ">= #{::Newgem::VERSION}"]
15
+ ]
16
+
17
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
18
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
19
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
20
+ p.rsync_args = '-av --delete --ignore-errors'
21
+ end
22
+
23
+ require 'newgem/tasks' # load /tasks/*.rake
24
+ # Dir['tasks/**/*.rake'].each { |t| load t }
25
+
26
+ # TODO - want other tests/tasks run by default? Add them to the list
27
+ # task :default => [:spec, :features]
@@ -0,0 +1,10 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require 'rubygems'
5
+ gem 'dm-core', '~>0.9.10'
6
+ require 'dm-core'
7
+
8
+ require 'dm-mysql/version'
9
+ require 'dm-mysql/mysql_adapter'
10
+ require 'dm-mysql/model'
@@ -0,0 +1,15 @@
1
+ module DataMapper
2
+ module Model
3
+
4
+ ##
5
+ # defines the table options for creating the resource in the database
6
+ #
7
+ # @param <Hash(Symbol => String) options of a hash of available options
8
+ def table_opts(options={})
9
+ raise ArgumentError, "Table options needs to be a Hash!" if !options.is_a?(Hash)
10
+ @table_options ||= options
11
+ end
12
+
13
+ end
14
+ end
15
+
@@ -0,0 +1,47 @@
1
+ module DataMapper
2
+ module Adapters
3
+ class MysqlAdapter < DataObjectsAdapter
4
+
5
+ module Migration
6
+ module SQL
7
+
8
+ ##
9
+ # Engine, Character Set and Collate are default options which are
10
+ # inherited from options set in the adapter.
11
+ #
12
+ # See http://dev.mysql.com/doc/refman/5.1/en/create-table.html
13
+ # for details on how to set the various table options
14
+ #
15
+ # === Returns
16
+ # @returns <String>
17
+ def create_table_statement(repository, model)
18
+ <<-EOS.compress_lines.rstrip
19
+ #{super}
20
+ ENGINE = #{ model.table_opts[:engine] ? model.table_opts[:engine] : 'InnoDB' }
21
+ CHARACTER SET #{character_set}
22
+ COLLATE #{collation}
23
+ #{ "AVG_ROW_LENGTH = #{model.table_opts[:avg_row_length]}" if model.table_opts[:avg_row_length] }
24
+ #{ "CHECKSUM = #{model.table_opts[:checksum]}" if model.table_opts[:checksum] }
25
+ #{ "COMMENT = '#{model.table_opts[:comment]}'" if model.table_opts[:comment] }
26
+ #{ "CONNECTION = '#{model.table_opts[:connection]}'" if model.table_opts[:connection] }
27
+ #{ "DATA DIRECTORY = '#{model.table_opts[:data_directory]}'" if model.table_opts[:data_directory] }
28
+ #{ "DELAY_KEY_WRITE = #{model.table_opts[:delay_key_write]}" if model.table_opts[:delay_key_write] }
29
+ #{ "INDEX DIRECTORY = '#{model.table_opts[:index_directory]}'" if model.table_opts[:index_directory] }
30
+ #{ "INSERT_METHOD = #{model.table_opts[:insert_method].upcase}" if model.table_opts[:insert_method] }
31
+ #{ "KEY_BLOCK_SIZE = #{model.table_opts[:key_block_size]}" if model.table_opts[:key_block_size] }
32
+ #{ "MAX_ROWS = #{model.table_opts[:max_rows]}" if model.table_opts[:max_rows] }
33
+ #{ "MIN_ROWS = #{model.table_opts[:min_rows]}" if model.table_opts[:min_rows] }
34
+ #{ "PACK_KEYS = #{model.table_opts[:pack_keys]}" if model.table_opts[:pack_keys] }
35
+ #{ "PASSWORD = #{model.table_opts[:password]}" if model.table_opts[:password] }
36
+ #{ "ROW_FORMAT = #{model.table_opts[:row_format]}" if model.table_opts[:row_format] }
37
+ #{ "TABLESPACE #{model.table_opts[:tablespace]}" if model.table_opts[:table_opts] }
38
+ #{ "UNION = #{model.table_opts[:union]}" if model.table_opts[:union] }
39
+ EOS
40
+ end
41
+
42
+ end # module SQL
43
+ end # module Migration
44
+
45
+ end # class MysqlAdapter
46
+ end # module Adapters
47
+ end # module DataMapper
@@ -0,0 +1,5 @@
1
+ module DataMapper
2
+ module Mysql
3
+ VERSION = '0.0.2'
4
+ end
5
+ end
@@ -0,0 +1,77 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe DataMapper::Model do
4
+ before(:all) do
5
+ class NotIncluded
6
+ include DataMapper::Resource
7
+
8
+ property :id, Integer
9
+ property :name, Text
10
+ end
11
+
12
+ class HasIt
13
+ include DataMapper::Resource
14
+
15
+ property :id, Integer
16
+ property :name, Text
17
+
18
+ table_opts :engine => 'MyISAM'
19
+
20
+ end
21
+
22
+ class AllOption
23
+ include DataMapper::Resource
24
+
25
+ property :id, Integer
26
+ property :name, Text
27
+
28
+ table_opts :engine => 'MyISAM',
29
+ :avg_row_length => 7,
30
+ :checksum => 1,
31
+ :comment => "Best Comment EVER!!",
32
+ :connection => 'another_connection',
33
+ :data_directory => '/dude/wheres/my/dictionary',
34
+ :delay_key_write => 0,
35
+ :index_directory => '/index/this',
36
+ :insert_method => 'FIRST',
37
+ :key_block_size => 256,
38
+ :max_rows => 5,
39
+ :min_rows => 0,
40
+ :pack_keys => 0,
41
+ :password => 'secret',
42
+ :row_format => 'COMPRESSED',
43
+ :tablespace => 'DUDE',
44
+ :union => 'has_its, not_includeds'
45
+ end
46
+ end
47
+
48
+ it "should add a class method to models which include DataMapper::Resource" do
49
+ NotIncluded.should respond_to(:table_opts)
50
+ HasIt.should respond_to(:table_opts)
51
+ AllOption.should respond_to(:table_opts)
52
+ end
53
+
54
+ describe ".table_opts" do
55
+ before do
56
+ @adapter = repository(:default).adapter
57
+ @repository = mock('repository', :kind_of? => true, :name => :default)
58
+ end
59
+
60
+ it "should accept a Hash" do
61
+ lambda{ HasIt.table_opts(:engine => 'MyISAM') }.should_not raise_error(ArgumentError)
62
+ end
63
+
64
+ it "should error if argument is not a Hash" do
65
+ lambda{ NotIncluded.table_opts([:engine, 'MEMORY']) }.should raise_error(ArgumentError)
66
+ end
67
+
68
+ it "should create a proper table options syntax" do
69
+ @adapter.create_table_statement(@repository, AllOption).should == "CREATE TABLE `all_options` (`id` INT(11), `name` TEXT) ENGINE = MyISAM CHARACTER SET utf8 COLLATE utf8_general_ci AVG_ROW_LENGTH = 7 CHECKSUM = 1 COMMENT = 'Best Comment EVER!!' CONNECTION = 'another_connection' DATA DIRECTORY = '/dude/wheres/my/dictionary' DELAY_KEY_WRITE = 0 INDEX DIRECTORY = '/index/this' INSERT_METHOD = FIRST KEY_BLOCK_SIZE = 256 MAX_ROWS = 5 MIN_ROWS = 0 PACK_KEYS = 0 PASSWORD = secret ROW_FORMAT = COMPRESSED UNION = has_its, not_includeds"
70
+ end
71
+
72
+ it "should create a proper create table syntax if not specified" do
73
+ @adapter.create_table_statement(@repository, NotIncluded).should == "CREATE TABLE `not_includeds` (`id` INT(11), `name` TEXT) ENGINE = InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci"
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ gem 'dm-core', '~>0.9.10'
3
+ require 'dm-core'
4
+
5
+ require File.dirname(__FILE__) + '/../lib/dm-mysql'
6
+
7
+ DataMapper.setup(:default, 'mysql://root@localhost/dm_mysql')
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: neovintage-dm-mysql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Rimas Silkaitis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-23 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: dm-core
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.10
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: newgem
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.3
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.8.0
44
+ version:
45
+ description: ""
46
+ email:
47
+ - neovintage@gmail.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - History.txt
54
+ - Manifest.txt
55
+ - README.rdoc
56
+ files:
57
+ - History.txt
58
+ - Manifest.txt
59
+ - Rakefile
60
+ - lib/dm-mysql.rb
61
+ - lib/dm-mysql/model.rb
62
+ - lib/dm-mysql/mysql_adapter.rb
63
+ - lib/dm-mysql/version.rb
64
+ - README.rdoc
65
+ - spec/dm-mysql_spec.rb
66
+ - spec/spec_helper.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/neovintage/dm-mysql/tree/master
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --main
72
+ - README.rdoc
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "0"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: dm-mysql
90
+ rubygems_version: 1.2.0
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: Plugin for fine grain MySQL options in DataMapper
94
+ test_files: []
95
+