citrusbyte-schemer 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +19 -0
- data/README.markdown +75 -0
- data/Rakefile +35 -0
- data/lib/schemer.rb +51 -0
- data/rails/init.rb +3 -0
- data/test/schemer_test.rb +5 -0
- metadata +58 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2009 Ben Alavi for Citrusbyte
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
Schemer
|
2
|
+
=======
|
3
|
+
|
4
|
+
On-the-fly ActiveRecord schema changes for extremely rapid prototyping.
|
5
|
+
|
6
|
+
Description
|
7
|
+
-----------
|
8
|
+
|
9
|
+
Loosely define your schema in your ActiveRecord model and have it created and
|
10
|
+
updated for you without worrying about migrations. Useful for when you want to
|
11
|
+
play around with real data handling during extremely rapid prototyping but you
|
12
|
+
really don't care about keeping the data or how it's defined.
|
13
|
+
|
14
|
+
**WARNING:** This will create and delete data definitions on the fly with no
|
15
|
+
warning! Only use this with volatile data! Never attach it to an existing model
|
16
|
+
you care about as it will start adding and dropping columns without your
|
17
|
+
consent!
|
18
|
+
|
19
|
+
Usage
|
20
|
+
-----
|
21
|
+
|
22
|
+
class User < ActiveRecord::Base
|
23
|
+
schema :username, :password
|
24
|
+
end
|
25
|
+
|
26
|
+
Creates a `users` table if it doesn't exist, complete with `username` and
|
27
|
+
`password` columns the first time you call `User.new`.
|
28
|
+
|
29
|
+
Need another column to play with?
|
30
|
+
|
31
|
+
class User < ActiveRecord::Base
|
32
|
+
schema :username, :password, :email
|
33
|
+
end
|
34
|
+
|
35
|
+
Adds an `email` column the next time `User.new` is called.
|
36
|
+
|
37
|
+
Don't want a column anymore?
|
38
|
+
|
39
|
+
class User < ActiveRecord::Base
|
40
|
+
schema :password, :email
|
41
|
+
end
|
42
|
+
|
43
|
+
Removes the `username` column the next time `User.new` is called.
|
44
|
+
|
45
|
+
Installation
|
46
|
+
------------
|
47
|
+
|
48
|
+
$ gem sources -a http://gems.github.com (you only have to do this once)
|
49
|
+
$ sudo gem install citrusbyte-schemer
|
50
|
+
|
51
|
+
License
|
52
|
+
-------
|
53
|
+
|
54
|
+
Copyright (c) 2009 Ben Alavi for Citrusbyte
|
55
|
+
|
56
|
+
Permission is hereby granted, free of charge, to any person
|
57
|
+
obtaining a copy of this software and associated documentation
|
58
|
+
files (the "Software"), to deal in the Software without
|
59
|
+
restriction, including without limitation the rights to use,
|
60
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
61
|
+
copies of the Software, and to permit persons to whom the
|
62
|
+
Software is furnished to do so, subject to the following
|
63
|
+
conditions:
|
64
|
+
|
65
|
+
The above copyright notice and this permission notice shall be
|
66
|
+
included in all copies or substantial portions of the Software.
|
67
|
+
|
68
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
69
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
70
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
71
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
72
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
73
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
74
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
75
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/clean'
|
5
|
+
|
6
|
+
gem_spec_file = 'schemer.gemspec'
|
7
|
+
|
8
|
+
gem_spec = eval(File.read(gem_spec_file)) rescue nil
|
9
|
+
|
10
|
+
task :default => :test
|
11
|
+
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.pattern = 'test/**/*_test.rb'
|
14
|
+
t.verbose = false
|
15
|
+
end
|
16
|
+
|
17
|
+
Rake::GemPackageTask.new(gem_spec) do |pkg|
|
18
|
+
pkg.need_zip = false
|
19
|
+
pkg.need_tar = false
|
20
|
+
rm_f FileList['pkg/**/*.*']
|
21
|
+
end if gem_spec
|
22
|
+
|
23
|
+
desc "Generate the gemspec file."
|
24
|
+
task :gemspec do
|
25
|
+
require 'erb'
|
26
|
+
|
27
|
+
File.open(gem_spec_file, 'w') do |f|
|
28
|
+
f.write ERB.new(File.read("#{gem_spec_file}.erb")).result(binding)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "Builds and installs the gem."
|
33
|
+
task :install => :repackage do
|
34
|
+
`sudo gem install pkg/#{gem_spec.name}-#{gem_spec.version}.gem`
|
35
|
+
end
|
data/lib/schemer.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Schemer
|
2
|
+
def schema(*args)
|
3
|
+
extend ClassMethods
|
4
|
+
include InstanceMethods
|
5
|
+
|
6
|
+
class_inheritable_accessor :schema_columns
|
7
|
+
self.schema_columns = args.collect(&:to_s)
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def protected_columns
|
12
|
+
%w( id )
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
def initialize(*args)
|
18
|
+
setup_schema
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def setup_schema
|
25
|
+
begin
|
26
|
+
ActiveRecord::Migration.table_structure(self.class.table_name)
|
27
|
+
update_schema
|
28
|
+
rescue ActiveRecord::StatementInvalid => e
|
29
|
+
if e.message.match(/Could not find table/)
|
30
|
+
create_schema
|
31
|
+
else
|
32
|
+
raise e
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_schema
|
38
|
+
self.class.schema_columns.each do |column|
|
39
|
+
ActiveRecord::Migration.add_column(self.class.table_name, column, :string) unless respond_to?(column.to_sym)
|
40
|
+
(self.class.column_names - self.class.protected_columns).each do |column|
|
41
|
+
ActiveRecord::Migration.remove_column(self.class.table_name, column) unless self.class.schema_columns.include?(column.to_s)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def create_schema
|
47
|
+
ActiveRecord::Migration.create_table(self.class.table_name) do |t|;end;
|
48
|
+
update_schema
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/rails/init.rb
ADDED
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: citrusbyte-schemer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben Alavi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-03 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: ben.alavi@citrusbyte.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/schemer.rb
|
26
|
+
- README.markdown
|
27
|
+
- LICENSE
|
28
|
+
- Rakefile
|
29
|
+
- rails/init.rb
|
30
|
+
- test/schemer_test.rb
|
31
|
+
has_rdoc: false
|
32
|
+
homepage: http://github.com/citrusbyte/schemer
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: On-the-fly ActiveRecord schema changes for extremely rapid prototyping.
|
57
|
+
test_files: []
|
58
|
+
|