rails3_assist 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/LICENSE +20 -0
- data/README.markdown +63 -0
- data/Rakefile +21 -0
- data/VERSION +1 -0
- data/lib/rails3_assist/app/file_names.rb +34 -0
- data/lib/rails3_assist/app/methods/crud.rb +31 -0
- data/lib/rails3_assist/app/methods/new_content.rb +11 -0
- data/lib/rails3_assist/app/rails_dirs.rb +105 -0
- data/lib/rails3_assist/app/rails_files.rb +128 -0
- data/lib/rails3_assist/app.rb +47 -0
- data/lib/rails3_assist/artifact/markers.rb +39 -0
- data/lib/rails3_assist/artifact/migration.rb +24 -0
- data/lib/rails3_assist/artifact/orm.rb +136 -0
- data/lib/rails3_assist/artifact/view.rb +67 -0
- data/lib/rails3_assist/base/class_methods.rb +11 -0
- data/lib/rails3_assist/base/create.rb +48 -0
- data/lib/rails3_assist/base/file_name.rb +17 -0
- data/lib/rails3_assist/base/insert.rb +53 -0
- data/lib/rails3_assist/base/read.rb +19 -0
- data/lib/rails3_assist/base/remove.rb +14 -0
- data/lib/rails3_assist/base.rb +49 -0
- data/lib/rails3_assist/extensions/core_ext.rb +29 -0
- data/lib/rails3_assist/rspec/macro.rb +34 -0
- data/lib/rails3_assist.rb +21 -0
- data/rails3_assist.gemspec +107 -0
- data/rails_generator.log +14 -0
- data/spec/load_spec.rb +1 -0
- data/spec/rails3_assist/app/app_dirs_spec.rb +23 -0
- data/spec/rails3_assist/app/app_file_names_spec.rb +0 -0
- data/spec/rails3_assist/app/app_files_spec.rb +0 -0
- data/spec/rails3_assist/artifact/controller/controller_spec.rb +33 -0
- data/spec/rails3_assist/artifact/helper/helper_spec.rb +33 -0
- data/spec/rails3_assist/artifact/mailer/mailer_spec.rb +33 -0
- data/spec/rails3_assist/artifact/migration/migration_spec.rb +34 -0
- data/spec/rails3_assist/artifact/model/model_spec.rb +34 -0
- data/spec/rails3_assist/artifact/observer/observer_spec.rb +34 -0
- data/spec/rails3_assist/artifact/orm/active_record_spec.rb +33 -0
- data/spec/rails3_assist/artifact/orm/mongo_mapper_spec.rb +63 -0
- data/spec/rails3_assist/artifact/orm/mongoid_spec.rb +63 -0
- data/spec/rails3_assist/artifact/view_spec/view_spec.rb +32 -0
- data/spec/spec_helper.rb +43 -0
- metadata +168 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format nested
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Kristian Mandrup
|
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.
|
data/README.markdown
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Rails3 Assistant
|
2
|
+
|
3
|
+
Includes various helpers to assist operating on a Rails 3 application, including various Rails 3 artifacts, such as migrations etc.
|
4
|
+
|
5
|
+
## Rails Artifacts
|
6
|
+
|
7
|
+
Rails assist also includes various artifact libraries to help operate on different Rails 3 artifacts.
|
8
|
+
These assist libraries mainly contain some common CRUD (Create, Read, Update, Delete) operations.
|
9
|
+
The same API is shared in all the artifact assist libraries.
|
10
|
+
The following is a list of the main API, including an alias for each method.
|
11
|
+
|
12
|
+
* create_[x] - new_[x])
|
13
|
+
* insert_into_[x] - update_[x]
|
14
|
+
* read_model - [x]_content
|
15
|
+
* remove_[x] - delete_[x]
|
16
|
+
* remove_[x]s - delete_[x]s
|
17
|
+
|
18
|
+
Rails 3 artifacts that have a CRUD assistant:
|
19
|
+
|
20
|
+
* controller
|
21
|
+
* helper
|
22
|
+
* mailer
|
23
|
+
* migration (pending!)
|
24
|
+
* model (insert bug!)
|
25
|
+
* observer
|
26
|
+
* view
|
27
|
+
|
28
|
+
## Model
|
29
|
+
|
30
|
+
* create_model (new_model)
|
31
|
+
* insert_into_model (update_model)
|
32
|
+
|
33
|
+
Create and insert for *model* operate according to the ORM currently used.
|
34
|
+
The ORM used is specified by calling <code>use_orm :[orm]</code> fx <code>use_orm :active_record</code>
|
35
|
+
|
36
|
+
### Usage
|
37
|
+
|
38
|
+
Generators are often designed to create Rails 3 artifacts or update existing artifacts. It's often useful to include one or more Rails 3 artifact assisters along
|
39
|
+
with a generator assister (see above).
|
40
|
+
This combination greatly facilitates your work in developing the generator, as much of the heavy lifting will be done for you in the assisters.
|
41
|
+
To use a helper, simply call:
|
42
|
+
|
43
|
+
*assist_with [list of helpers]*
|
44
|
+
|
45
|
+
Example:
|
46
|
+
|
47
|
+
<code>assist_with :app, :controller, :model, :view</code>
|
48
|
+
|
49
|
+
Aliases: *use_helpers* and *use_helper*
|
50
|
+
|
51
|
+
## Note on Patches/Pull Requests
|
52
|
+
|
53
|
+
* Fork the project.
|
54
|
+
* Make your feature addition or bug fix.
|
55
|
+
* Add tests for it. This is important so I don't break it in a
|
56
|
+
future version unintentionally.
|
57
|
+
* Commit, do not mess with rakefile, version, or history.
|
58
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
59
|
+
* Send me a pull request. Bonus points for topic branches.
|
60
|
+
|
61
|
+
## Copyright
|
62
|
+
|
63
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "rails3_assist"
|
5
|
+
gem.summary = %Q{Assist in operating on Rails 3 artifacts including migrations}
|
6
|
+
gem.description = %Q{Assist in operating on Rails 3 artifacts including migrations}
|
7
|
+
gem.email = "kmandrup@gmail.com"
|
8
|
+
gem.homepage = "http://github.com/kristianmandrup/rails3-assist"
|
9
|
+
gem.authors = ["Kristian Mandrup"]
|
10
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
|
11
|
+
# gem.add_development_dependency "generator-rspec", ">= 0.6.0"
|
12
|
+
gem.add_dependency "require_all", ">= 1.1.0"
|
13
|
+
gem.add_dependency "migration_assist", ">= 0.1.2"
|
14
|
+
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.2
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Rails::Assist
|
2
|
+
module View
|
3
|
+
module FileName
|
4
|
+
def view_file_name folder, action=nil, type=nil
|
5
|
+
File.join(view_dir, folder.to_s, "#{get_action action}.#{get_type type}")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Migration
|
11
|
+
module FileName
|
12
|
+
def migration_file_name name, options={}
|
13
|
+
number = options[:number]
|
14
|
+
number = next_migration_number(migration_dir) if !number
|
15
|
+
File.join(migration_dir, "#{number}_#{name}.rb")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
(Rails::Assist.artifacts. - [:migration, :view]).each do |name|
|
21
|
+
class_eval %{
|
22
|
+
module #{name.to_s.camelize}
|
23
|
+
module FileName
|
24
|
+
|
25
|
+
def #{name}_file_name name, options=nil
|
26
|
+
artifact_path name, :#{name}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
include FileName
|
31
|
+
end
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Rails::Assist
|
2
|
+
artifacts.each do |name|
|
3
|
+
class_eval %{
|
4
|
+
module #{name.to_s.camelize}
|
5
|
+
include Rails::Assist::BaseHelper
|
6
|
+
|
7
|
+
def create_#{name} name, options={}, &block
|
8
|
+
create_artifact(name, set(options, :#{name}), &block)
|
9
|
+
end
|
10
|
+
|
11
|
+
def insert_into_#{name}(name, options={}, &block)
|
12
|
+
insert_content(name, set(options, :#{name}), &block)
|
13
|
+
end
|
14
|
+
|
15
|
+
def read_#{name}(name, options={}, &block)
|
16
|
+
read_artifact(name, set(options, :#{name}), &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove_#{name} name
|
20
|
+
remove_artifact name, :#{name}
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_#{name}s *names
|
24
|
+
remove_artifacts :#{name}, *names
|
25
|
+
end
|
26
|
+
|
27
|
+
aliases_for :#{name}
|
28
|
+
end
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module Rails::Assist
|
2
|
+
module App
|
3
|
+
class << self
|
4
|
+
attr_accessor :rails_root_dir
|
5
|
+
end
|
6
|
+
|
7
|
+
module RailsDirs
|
8
|
+
def self.root_directories
|
9
|
+
[:app, :config, :db, :public, :lib, :log, :doc, :test, :spec]
|
10
|
+
end
|
11
|
+
|
12
|
+
def root_directories
|
13
|
+
Rails::Assist::App::RailsDirs.root_directories
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.app_artifacts
|
17
|
+
[:controller, :mailer, :helper, :view, :model]
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.app_directories
|
21
|
+
app_artifacts.map {|a| a.to_s.singularize.to_sym}
|
22
|
+
end
|
23
|
+
|
24
|
+
def app_directories
|
25
|
+
Rails::Assist::App::RailsDirs.app_directories
|
26
|
+
end
|
27
|
+
|
28
|
+
def app_artifacts
|
29
|
+
Rails::Assist::App::RailsDirs.app_artifacts
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.rails_containers
|
33
|
+
Rails::Assist::App::RailsDirs.instance_methods.grep(/_dir$/).map{|dir| dir.gsub(/^(.*)_dir/, '\1').to_sym }
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.valid_container? type
|
37
|
+
rails_containers.include?(type)
|
38
|
+
end
|
39
|
+
|
40
|
+
def root_dir
|
41
|
+
dir = Rails::Assist::App.rails_root_dir
|
42
|
+
raise "You must set the Rails app root dir: Rails::Assist::App.root_dir = '/my/root/dir'" if !dir
|
43
|
+
dir
|
44
|
+
end
|
45
|
+
|
46
|
+
def rails_dir_for type
|
47
|
+
raise ArgumentError, '#rails_dir_for takes a dir type argument' if !type
|
48
|
+
dir_method = "#{type}_dir"
|
49
|
+
self.send(dir_method) if respond_to?(dir_method)
|
50
|
+
end
|
51
|
+
|
52
|
+
def migration_dir
|
53
|
+
File.join(db_dir, 'migrations')
|
54
|
+
end
|
55
|
+
|
56
|
+
def config_dir_for type
|
57
|
+
File.join(config_dir, type.to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
def initializer_dir
|
61
|
+
config_dir_for type :initializers
|
62
|
+
end
|
63
|
+
|
64
|
+
def locale_dir
|
65
|
+
config_dir_for type :locales
|
66
|
+
end
|
67
|
+
|
68
|
+
def public_dir_for type
|
69
|
+
File.join(public_dir, type.to_s)
|
70
|
+
end
|
71
|
+
|
72
|
+
def stylesheet_dir
|
73
|
+
public_dir_for :stylesheets
|
74
|
+
end
|
75
|
+
|
76
|
+
def javascript_dir
|
77
|
+
public_dir_for :javascripts
|
78
|
+
end
|
79
|
+
|
80
|
+
root_directories.each do |name|
|
81
|
+
class_eval %{
|
82
|
+
def #{name}_dir
|
83
|
+
File.join(root_dir, '#{name}')
|
84
|
+
end
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
app_artifacts.each do |name|
|
89
|
+
class_eval %{
|
90
|
+
def #{name}_dir
|
91
|
+
File.join(app_dir, '#{name}')
|
92
|
+
end
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def app_dir
|
97
|
+
File.join(root_dir, 'app')
|
98
|
+
end
|
99
|
+
|
100
|
+
def observer_dir
|
101
|
+
model_dir
|
102
|
+
end
|
103
|
+
end # RailsDirs
|
104
|
+
end # App
|
105
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Rails::Assist
|
2
|
+
module App
|
3
|
+
module RailsFiles
|
4
|
+
|
5
|
+
def files_from expr, *types
|
6
|
+
types.inject([]) {|files, type| files + self.send(:"#{type}_files", expr)}
|
7
|
+
end
|
8
|
+
|
9
|
+
def all_files expr=nil
|
10
|
+
rails_files(root_dir).grep expr
|
11
|
+
end
|
12
|
+
|
13
|
+
def app_files expr=nil
|
14
|
+
rails_app_files.grep expr
|
15
|
+
end
|
16
|
+
|
17
|
+
def rails_files_for type, expr=nil, &block
|
18
|
+
files_method = "#{type}_files"
|
19
|
+
send files_method, expr, &block if respond_to?(files_method)
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.rails_artifacts
|
23
|
+
@rails_artifacts ||= Rails::Assist::RailsDirs.instance_methods.grep(/_files$/).map{|dir| dir.gsub(/^(.*)_dir/, '\1').to_sym }
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.valid_artifact? type
|
27
|
+
rails_artifacts.include?(type)
|
28
|
+
end
|
29
|
+
|
30
|
+
[:model, :controller, :helper].each do |name|
|
31
|
+
class_eval %{
|
32
|
+
def #{name}_files expr=nil
|
33
|
+
files = rails_app_files(:#{name.to_s.pluralize}).grep expr
|
34
|
+
yield files if block_given?
|
35
|
+
end
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
[:mailer, :observer].each do |name|
|
40
|
+
class_eval %{
|
41
|
+
def #{name}_files expr=nil
|
42
|
+
files = rails_app_files(:#{name.to_s.pluralize}, '**/*_#{name}.rb').grep expr
|
43
|
+
yield files if block_given?
|
44
|
+
end
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def view_files *args
|
49
|
+
expr, model_name = get_view_args args
|
50
|
+
file_expr = model_name ? "#{model_name}/*.*" : '**/*.*'
|
51
|
+
files = rails_app_files(:views, file_expr).grep expr
|
52
|
+
yield files if block_given?
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
[:erb, :haml].each do |name|
|
57
|
+
class_eval %{
|
58
|
+
def #{name}_view_files *args
|
59
|
+
expr, model_name = get_view_args(args)
|
60
|
+
file_expr = model_name ? "\#{model_name}/*.\#{name}*" : '**/*.\#{name}*'
|
61
|
+
files = rails_app_files(:views, file_expr).grep expr
|
62
|
+
yield files if block_given?
|
63
|
+
end
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
[:initializer, :db, :migration].each do |name|
|
68
|
+
class_eval %{
|
69
|
+
def #{name}_files expr=nil
|
70
|
+
files = rails_files(#{name}_dir).grep expr
|
71
|
+
yield files if block_given?
|
72
|
+
end
|
73
|
+
}
|
74
|
+
end
|
75
|
+
|
76
|
+
{:locale => :yml, :javascript => :js}.each_pair do |name, ext|
|
77
|
+
class_eval %{
|
78
|
+
def #{name}_files expr=nil
|
79
|
+
files = rails_files(#{name}_dir, '**/*.#{ext}').grep expr
|
80
|
+
yield files if block_given?
|
81
|
+
end
|
82
|
+
}
|
83
|
+
end
|
84
|
+
|
85
|
+
[:css, :sass].each do |ext|
|
86
|
+
class_eval %{
|
87
|
+
def #{ext}_files expr=nil
|
88
|
+
files = rails_files(stylesheet_dir, '**/*.#{ext}').grep expr
|
89
|
+
yield files if block_given?
|
90
|
+
end
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
protected
|
95
|
+
|
96
|
+
RB_FILES = '**/*.rb'
|
97
|
+
|
98
|
+
def get_view_args args
|
99
|
+
args = args.flatten
|
100
|
+
first_arg = args.first
|
101
|
+
case first_arg
|
102
|
+
when Regexp
|
103
|
+
expr = first_arg
|
104
|
+
when String, Symbol
|
105
|
+
_model = first_arg
|
106
|
+
end
|
107
|
+
expr = args[1] if args > 1 && args1.kind_of?(Regexp)
|
108
|
+
[expr, _model]
|
109
|
+
end
|
110
|
+
|
111
|
+
def rails_files dir, type=nil, pattern=nil
|
112
|
+
path = case type
|
113
|
+
when nil
|
114
|
+
"#{dir}/#{RB_FILES}"
|
115
|
+
when String
|
116
|
+
"#{dir}/#{type}"
|
117
|
+
when Symbol
|
118
|
+
pattern ? "#{dir}/#{type}/#{pattern}" : "#{dir}/#{type}"
|
119
|
+
end
|
120
|
+
FileList[path]
|
121
|
+
end
|
122
|
+
|
123
|
+
def rails_app_files type=nil, pattern='**/*.rb'
|
124
|
+
rails_files :app, type, pattern
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end # App
|
128
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Rails::Assist
|
2
|
+
def self.helper_list
|
3
|
+
self.artifacts + [:view]
|
4
|
+
end
|
5
|
+
|
6
|
+
module ArtifactPath
|
7
|
+
def artifact_path name, type, dir=nil
|
8
|
+
dir ||= send :"#{type}_dir"
|
9
|
+
File.join(dir, "#{name}#{type_postfix type}.rb")
|
10
|
+
end
|
11
|
+
|
12
|
+
def type_postfix type
|
13
|
+
"_#{type}" if ![:model].include?(type)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module App
|
18
|
+
include ArtifactPath
|
19
|
+
|
20
|
+
def create_empty_tmp *dir_types
|
21
|
+
dir_types.flatten.each do |dir_type|
|
22
|
+
dir = rails_dir_for(dir_type)
|
23
|
+
FileUtils.mkdir_p dir
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
# first load all base modules that the app helper will build upon
|
31
|
+
require 'rails3_assist/base'
|
32
|
+
|
33
|
+
# then load the app 'modules'
|
34
|
+
require_all File.dirname(__FILE__) + '/app'
|
35
|
+
|
36
|
+
# into App
|
37
|
+
module Rails::Assist::App
|
38
|
+
include RailsFiles
|
39
|
+
include RailsDirs
|
40
|
+
|
41
|
+
# put all FileName modules into App
|
42
|
+
Rails::Assist.artifacts.each do |name|
|
43
|
+
class_eval %{
|
44
|
+
include Rails::Assist::#{name.to_s.camelize}::FileName
|
45
|
+
}
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Rails::Assist
|
2
|
+
module Controller
|
3
|
+
def controller_marker name, options=nil
|
4
|
+
"#{name.to_s.camelize}Controller < ActionController::Base"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module Helper
|
9
|
+
def helper_marker name, options=nil
|
10
|
+
"#{name.to_s.camelize}Helper"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Mailer
|
15
|
+
def mailer_marker name, options=nil
|
16
|
+
"#{name.to_s.camelize} < ActionMailer::Base"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
module Observer
|
21
|
+
def observer_marker name, options=nil
|
22
|
+
"#{name.to_s.camelize}Observer < ActiveRecord::Observer"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module Model
|
27
|
+
include Rails::Assist::BaseHelper
|
28
|
+
|
29
|
+
def model_marker name, options={}
|
30
|
+
return send :orm_marker_name, options if respond_to?(:orm_marker_name)
|
31
|
+
name.camelize
|
32
|
+
end
|
33
|
+
|
34
|
+
def orm_notify
|
35
|
+
". You must specify an ORM with the macro use_orm, f.ex -- use_orm :active_record"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'migration_assist'
|
2
|
+
|
3
|
+
Rails::Migration::Assist.rails_root_dir = Rails::Assist::App.rails_root_dir
|
4
|
+
|
5
|
+
module Rails::Assist
|
6
|
+
module Migration
|
7
|
+
include Rails::Assist::BaseHelper
|
8
|
+
include Rails::Migration::Assist::ClassMethods
|
9
|
+
|
10
|
+
include FileName
|
11
|
+
|
12
|
+
def find_migration name, option=nil
|
13
|
+
migrations = Dir.glob("#{migration_dir}/[0-9]*_*.rb")
|
14
|
+
return nil if !migrations.empty?
|
15
|
+
matching_migrations = migrations.grep(/\d+_#{name}\.rb$/)
|
16
|
+
return nil if matching_migrations.empty?
|
17
|
+
migration_file = (option == :last) ? matching_migrations.last : matching_migrations.first
|
18
|
+
end
|
19
|
+
|
20
|
+
def migration_marker name, options=nil
|
21
|
+
"#{name.to_s.camelize} < ActiveRecord::Migration"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
module Rails::Assist
|
2
|
+
module Orm
|
3
|
+
module Base
|
4
|
+
include Rails::Assist::Model
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def orm_marker_name options = {:model_type => :document}
|
9
|
+
document_name options
|
10
|
+
end
|
11
|
+
|
12
|
+
def document_name options = {:model_type => :document}
|
13
|
+
type_content = options[:model_type] == :embedded ? "#{orm_name}::EmbeddedDocument" : "#{orm_name}::Document"
|
14
|
+
end
|
15
|
+
|
16
|
+
def clazz name
|
17
|
+
"class #{name.to_s.camelize}"
|
18
|
+
end
|
19
|
+
|
20
|
+
def file name, include_stmt, &block
|
21
|
+
%Q{#{clazz name}
|
22
|
+
#{include_stmt}
|
23
|
+
#{yield if block}
|
24
|
+
end}
|
25
|
+
end
|
26
|
+
|
27
|
+
def file_w_include name, module_name, &block
|
28
|
+
file name, "include #{module_name}", &block
|
29
|
+
end
|
30
|
+
|
31
|
+
def simple_file name, module_name, &block
|
32
|
+
%Q{#{clazz name}
|
33
|
+
#{yield if block}
|
34
|
+
end}
|
35
|
+
end
|
36
|
+
|
37
|
+
def file_w_inherit name, module_name, &block
|
38
|
+
%Q{#{clazz name} < #{module_name}
|
39
|
+
#{yield if block}
|
40
|
+
end}
|
41
|
+
end
|
42
|
+
|
43
|
+
def field name, type = nil
|
44
|
+
return "#{field_name} :#{name}, #{type}" if type
|
45
|
+
"#{field_name} :#{name}"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module None
|
50
|
+
include Rails::Assist::Orm::Base
|
51
|
+
|
52
|
+
def orm_marker_name options=nil
|
53
|
+
@name
|
54
|
+
end
|
55
|
+
|
56
|
+
def new_model_content name, options={}, &block
|
57
|
+
content = options[:content] || yield if block
|
58
|
+
@name = name
|
59
|
+
simple_file(name, orm_marker_name(options)) { content }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
module ActiveRecord
|
64
|
+
include Rails::Assist::Orm::Base
|
65
|
+
|
66
|
+
def orm_marker_name options=nil
|
67
|
+
'ActiveRecord::Base'
|
68
|
+
end
|
69
|
+
|
70
|
+
def new_model_content name, options={}, &block
|
71
|
+
content = options[:content] || yield if block
|
72
|
+
file_w_inherit(name, orm_marker_name(options)) { content }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
module MongoMapper
|
77
|
+
include Rails::Assist::Orm::Base
|
78
|
+
|
79
|
+
def orm_name
|
80
|
+
'MongoMapper'
|
81
|
+
end
|
82
|
+
|
83
|
+
def new_model_content name, options={}, &block
|
84
|
+
content = options[:content] || yield if block
|
85
|
+
file_w_include(name, orm_marker_name(options)) { content }
|
86
|
+
end
|
87
|
+
|
88
|
+
def field_name
|
89
|
+
'key'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
module Mongoid
|
94
|
+
include Rails::Assist::Orm::Base
|
95
|
+
|
96
|
+
def orm_name
|
97
|
+
'Mongoid'
|
98
|
+
end
|
99
|
+
|
100
|
+
def field_name
|
101
|
+
'field'
|
102
|
+
end
|
103
|
+
|
104
|
+
def new_model_content name, options={}, &block
|
105
|
+
content = options[:content] || yield if block
|
106
|
+
file_w_include(name, orm_marker_name(options)) { content }
|
107
|
+
end
|
108
|
+
|
109
|
+
def field name, type = nil
|
110
|
+
return "#{field_name} :#{name}, :type => #{type}" if type
|
111
|
+
"#{field_name} :#{name}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
module DataMapper
|
116
|
+
include Rails::Assist::Orm::Base
|
117
|
+
|
118
|
+
def orm_name
|
119
|
+
'DataMapper'
|
120
|
+
end
|
121
|
+
|
122
|
+
def orm_marker_name options=nil
|
123
|
+
"#{orm_name}::Resource"
|
124
|
+
end
|
125
|
+
|
126
|
+
def new_model_content name, options={}, &block
|
127
|
+
content = options[:content] || yield if block
|
128
|
+
file_w_include(name, orm_marker_name(options)) { content }
|
129
|
+
end
|
130
|
+
|
131
|
+
def field_name
|
132
|
+
'property'
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|