rails3_artifactor 0.1.0
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/.document +5 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/LICENSE +20 -0
- data/README.markdown +67 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/lib/rails3_artifactor/artifact/crud/view.rb +71 -0
- data/lib/rails3_artifactor/artifact/crud.rb +55 -0
- data/lib/rails3_artifactor/artifact/file_name/artifacts.rb +21 -0
- data/lib/rails3_artifactor/artifact/file_name/migration.rb +54 -0
- data/lib/rails3_artifactor/artifact/file_name/view.rb +36 -0
- data/lib/rails3_artifactor/artifact/markers.rb +76 -0
- data/lib/rails3_artifactor/artifact/migration.rb +11 -0
- data/lib/rails3_artifactor/artifact/orm/active_record.rb +14 -0
- data/lib/rails3_artifactor/artifact/orm/data_mapper.rb +22 -0
- data/lib/rails3_artifactor/artifact/orm/mongo_mapper.rb +18 -0
- data/lib/rails3_artifactor/artifact/orm/mongoid.rb +23 -0
- data/lib/rails3_artifactor/artifact/orm/none.rb +17 -0
- data/lib/rails3_artifactor/artifact/orm.rb +51 -0
- data/lib/rails3_artifactor/base/class_methods.rb +9 -0
- data/lib/rails3_artifactor/base/crud/create.rb +48 -0
- data/lib/rails3_artifactor/base/crud/delete.rb +14 -0
- data/lib/rails3_artifactor/base/crud/read.rb +20 -0
- data/lib/rails3_artifactor/base/crud/update.rb +44 -0
- data/lib/rails3_artifactor/base/crud.rb +6 -0
- data/lib/rails3_artifactor/base/file_name.rb +41 -0
- data/lib/rails3_artifactor/namespaces.rb +13 -0
- data/lib/rails3_artifactor/rspec/configure.rb +6 -0
- data/lib/rails3_artifactor/rspec/macro.rb +30 -0
- data/lib/rails3_artifactor.rb +6 -0
- data/spec/fixtures/app/controllers/account_controller.rb +4 -0
- data/spec/fixtures/app/helpers/account_helper.rb +4 -0
- data/spec/fixtures/app/models/account.rb +5 -0
- data/spec/fixtures/app/models/account_observer.rb +4 -0
- data/spec/fixtures/app/views/account/edit.html.erb +4 -0
- data/spec/fixtures/app/views/account/show.html.erb +3 -0
- data/spec/fixtures/db/migrations/20100904095012_create_account.rb +4 -0
- data/spec/fixtures.rb +3 -0
- data/spec/rails3_artifactor/artifact/crud/controller_spec.rb +35 -0
- data/spec/rails3_artifactor/artifact/crud/helper_spec.rb +35 -0
- data/spec/rails3_artifactor/artifact/crud/migration_spec.rb +51 -0
- data/spec/rails3_artifactor/artifact/crud/model_spec.rb +37 -0
- data/spec/rails3_artifactor/artifact/crud/observer_spec.rb +36 -0
- data/spec/rails3_artifactor/artifact/crud/view_controller_action_spec.rb +67 -0
- data/spec/rails3_artifactor/artifact/crud/view_controller_default_action_spec.rb +35 -0
- data/spec/rails3_artifactor/artifact/file_name/artifacts_spec.rb +29 -0
- data/spec/rails3_artifactor/artifact/file_name/migration_spec.rb +30 -0
- data/spec/rails3_artifactor/artifact/file_name/view_spec.rb +27 -0
- data/spec/rails3_artifactor/artifact/markers_spec.rb +97 -0
- data/spec/rails3_artifactor/artifact/migration_spec.rb +0 -0
- data/spec/rails3_artifactor/artifact/orm/active_record_spec.rb +33 -0
- data/spec/rails3_artifactor/artifact/orm/data_mapper_spec.rb +33 -0
- data/spec/rails3_artifactor/artifact/orm/mongo_mapper_spec.rb +63 -0
- data/spec/rails3_artifactor/artifact/orm/mongoid_spec.rb +63 -0
- data/spec/rails3_artifactor/artifact/orm/none_spec.rb +32 -0
- data/spec/rails3_artifactor/base/crud/create_spec.rb +13 -0
- data/spec/rails3_artifactor/base/crud/delete_spec.rb +14 -0
- data/spec/rails3_artifactor/base/crud/read_spec.rb +24 -0
- data/spec/rails3_artifactor/base/crud/update_spec.rb +24 -0
- data/spec/rails3_artifactor/base/file_name_spec.rb +23 -0
- data/spec/spec_helper.rb +9 -0
- metadata +183 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--format nested --color
|
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,67 @@
|
|
1
|
+
# Rails3 Artifactor
|
2
|
+
|
3
|
+
DSL for operating on various types of Rails 3 application artifacts. The DSL mostly allows performing common CRUD operations etc.
|
4
|
+
This is particularly useful when creating Rails 3 generators, plugins etc. that perform code checks and mutations of the app.
|
5
|
+
The artifactor has in part been designed for use with the *please me* tool. (see my github account)
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
<code>gem install rails3_artifactor</code>
|
10
|
+
|
11
|
+
## Status
|
12
|
+
|
13
|
+
* Specs pass
|
14
|
+
* Still needs some refactoring to tidy it up!
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
|
18
|
+
Introduces the ability to easily load one or more artifact helper modules into your class or module of choice.
|
19
|
+
This will introduce various helper methods geared toward operating a that particular kind of artifact, such as CRUD operations etc.
|
20
|
+
|
21
|
+
<pre>
|
22
|
+
module MyCoolModule
|
23
|
+
use_helpers :model, :controller
|
24
|
+
use_orm :mongoid
|
25
|
+
|
26
|
+
def make_hello_model
|
27
|
+
# this is a method available after loading the :model artifact helper
|
28
|
+
# since orm used is set to :mongoid, it will create a mongoid model file
|
29
|
+
create_model :hello do
|
30
|
+
'# Hello'
|
31
|
+
end
|
32
|
+
|
33
|
+
remove_model :hello if has_model? :hello
|
34
|
+
|
35
|
+
create_controller :hello do
|
36
|
+
...
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
</pre>
|
41
|
+
|
42
|
+
## TODO
|
43
|
+
|
44
|
+
Make DSL even better, fx:
|
45
|
+
<pre>
|
46
|
+
with_model :account do |m|
|
47
|
+
m.create! do
|
48
|
+
'# hello'
|
49
|
+
end
|
50
|
+
|
51
|
+
m.remove!
|
52
|
+
end
|
53
|
+
</pre>
|
54
|
+
|
55
|
+
## Note on Patches/Pull Requests
|
56
|
+
|
57
|
+
* Fork the project.
|
58
|
+
* Make your feature addition or bug fix.
|
59
|
+
* Add tests for it. This is important so I don't break it in a
|
60
|
+
future version unintentionally.
|
61
|
+
* Commit, do not mess with rakefile, version, or history.
|
62
|
+
(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)
|
63
|
+
* Send me a pull request. Bonus points for topic branches.
|
64
|
+
|
65
|
+
## Copyright
|
66
|
+
|
67
|
+
Copyright (c) 2010 Kristian Mandrup. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gem|
|
4
|
+
gem.name = "rails3_artifactor"
|
5
|
+
gem.summary = %Q{Helpers for handling Rails 3 artifacts}
|
6
|
+
gem.description = %Q{Helpers for handling Rails 3 artifacts in general, such as CRUD operations etc.}
|
7
|
+
gem.email = "kmandrup@gmail.com"
|
8
|
+
gem.homepage = "http://github.com/kristianmandrup/rails3_artifact_helper"
|
9
|
+
gem.authors = ["Kristian Mandrup"]
|
10
|
+
gem.add_development_dependency "rspec", "~> 2.0.0"
|
11
|
+
gem.add_dependency "require_all", "~> 1.1.0"
|
12
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
13
|
+
end
|
14
|
+
Jeweler::GemcutterTasks.new
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
17
|
+
end
|
18
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Rails3::Assist::Artifact
|
2
|
+
module View
|
3
|
+
include Rails3::Assist::BaseHelper
|
4
|
+
|
5
|
+
def has_view? name, *args, &block
|
6
|
+
file_name = view_file_name(name, args)
|
7
|
+
file_name.path.file?
|
8
|
+
end
|
9
|
+
|
10
|
+
# CREATE
|
11
|
+
def create_view name, *args, &block
|
12
|
+
file_name = view_file_name(name, args)
|
13
|
+
dir = File.dirname(file_name)
|
14
|
+
FileUtils.mkdir_p dir if !File.directory?(dir)
|
15
|
+
|
16
|
+
content = get_content(args) || yield if block
|
17
|
+
|
18
|
+
# abort if no content given
|
19
|
+
debug "Warning: Content must be passed in either as a :content hash or a block" if !content
|
20
|
+
return nil if !content
|
21
|
+
|
22
|
+
debug "Writing view file: #{file_name}"
|
23
|
+
# write file content of view
|
24
|
+
File.open(file_name, 'w') do |f|
|
25
|
+
f.puts content
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# READ
|
30
|
+
def read_view(name, *args, &block)
|
31
|
+
file_name = view_file_name(name, args)
|
32
|
+
debug "reading from: #{file_name}"
|
33
|
+
file = File.new(file_name)
|
34
|
+
raise "The view file: #{file} could not be found" if !file
|
35
|
+
begin
|
36
|
+
content = file.read
|
37
|
+
debug "read content: #{content}"
|
38
|
+
yield content if block
|
39
|
+
content
|
40
|
+
rescue
|
41
|
+
nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# UPDATE
|
46
|
+
def insert_into_view(name, *args, &block)
|
47
|
+
file_name = view_file_name(name, args)
|
48
|
+
debug "file insertion (view): #{file_name}"
|
49
|
+
options = last_option args
|
50
|
+
raise ArgumentError, ":before or :after option must be specified for insertion" if !(options[:before] || options[:after])
|
51
|
+
|
52
|
+
File.insert_into file_name, options, &block
|
53
|
+
end
|
54
|
+
|
55
|
+
# DELETE
|
56
|
+
def remove_view name, action=nil, type=nil
|
57
|
+
file = view_file_name(name, action, type)
|
58
|
+
FileUtils.rm_f(file) if File.exist?(file)
|
59
|
+
end
|
60
|
+
|
61
|
+
def get_content args
|
62
|
+
args = args.flatten
|
63
|
+
case args.first
|
64
|
+
when Hash
|
65
|
+
args.first[:content]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
multi_aliases_for :view
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'sugar-high/file'
|
2
|
+
require_all File.dirname(__FILE__) + '/crud'
|
3
|
+
|
4
|
+
module Rails3::Assist::Artifact
|
5
|
+
(Rails3::Assist.artifacts - [:model]).each do |name|
|
6
|
+
class_eval %{
|
7
|
+
module #{name.to_s.camelize}
|
8
|
+
def new_#{name}_content name, content=nil, &block
|
9
|
+
new_artifact_content name, :#{name}, content, &block
|
10
|
+
end
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
Rails3::Assist.artifacts.each do |name|
|
16
|
+
class_eval %{
|
17
|
+
module #{name.to_s.camelize}
|
18
|
+
include Rails3::Assist::BaseHelper
|
19
|
+
include Rails3::Assist::Artifact::CRUD
|
20
|
+
|
21
|
+
def has_#{name}? name, &block
|
22
|
+
begin
|
23
|
+
found = existing_file_name(name, :#{name}).path.file?
|
24
|
+
rescue IOError
|
25
|
+
found = false
|
26
|
+
end
|
27
|
+
yield if block && found
|
28
|
+
found
|
29
|
+
end
|
30
|
+
|
31
|
+
def create_#{name} name, options={}, &block
|
32
|
+
create_artifact(name, set(options, :#{name}), &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def insert_into_#{name}(name, options={}, &block)
|
36
|
+
insert_into_artifact(name, set(options, :#{name}), &block)
|
37
|
+
end
|
38
|
+
|
39
|
+
def read_#{name}(name, options={}, &block)
|
40
|
+
read_artifact(name, set(options, :#{name}), &block)
|
41
|
+
end
|
42
|
+
|
43
|
+
def remove_#{name} name
|
44
|
+
remove_artifact name, :#{name}
|
45
|
+
end
|
46
|
+
|
47
|
+
def remove_#{name}s *names
|
48
|
+
remove_artifacts :#{name}, *names
|
49
|
+
end
|
50
|
+
|
51
|
+
multi_aliases_for :#{name}
|
52
|
+
end
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'migration_assist'
|
2
|
+
require 'rails3_artifactor/base/file_name'
|
3
|
+
|
4
|
+
module Rails3::Assist::Artifact
|
5
|
+
(Rails3::Assist.artifacts - [:migration, :view]).each do |name|
|
6
|
+
class_eval %{
|
7
|
+
module #{name.to_s.camelize}
|
8
|
+
module FileName
|
9
|
+
include Rails3::Assist::Artifact::FileName
|
10
|
+
|
11
|
+
def #{name}_file_name name, options=nil
|
12
|
+
artifact_path name, :#{name}, options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
extend FileName
|
17
|
+
include FileName
|
18
|
+
end
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'migration_assist'
|
2
|
+
require 'sugar-high/regexp'
|
3
|
+
|
4
|
+
module Rails3::Assist::Artifact
|
5
|
+
module Migration
|
6
|
+
module FileName
|
7
|
+
include ::Rails::Migration::Assist::ClassMethods
|
8
|
+
|
9
|
+
DIR = Rails3::Assist::Artifact::Directory
|
10
|
+
|
11
|
+
class FindError
|
12
|
+
attr_accessor :find_expr
|
13
|
+
|
14
|
+
def initialize find_expr
|
15
|
+
self.find_expr = find_expr
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def migration_file_name name, options={}
|
20
|
+
number = options[:number]
|
21
|
+
|
22
|
+
migration_dir_name = File.expand_path(DIR.migration_dir options[:root_path])
|
23
|
+
|
24
|
+
number = next_migration_number(migration_dir_name) if !number
|
25
|
+
File.join(migration_dir_name, "#{number}_#{name}.rb")
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_migration name, options={}
|
29
|
+
root_path = options[:root_path]
|
30
|
+
|
31
|
+
migration_dir_name = File.expand_path(DIR.migration_dir options[:root_path])
|
32
|
+
|
33
|
+
migration_find_expr = "#{migration_dir_name}/[0-9]*_*.rb"
|
34
|
+
migrations = Dir.glob(migration_find_expr)
|
35
|
+
|
36
|
+
find_err = FindError.new migration_find_expr
|
37
|
+
|
38
|
+
return find_err if migrations.empty?
|
39
|
+
|
40
|
+
migration_find_expr = /\d+_#{name}\.rb$/
|
41
|
+
find_err.find_expr = migration_find_expr
|
42
|
+
|
43
|
+
matching_migrations = migrations.grep_it(migration_find_expr)
|
44
|
+
|
45
|
+
return find_err if matching_migrations.empty?
|
46
|
+
|
47
|
+
migration_file = (options[:last]) ? matching_migrations.last : matching_migrations.first
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
include FileName
|
52
|
+
extend FileName
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Rails3::Assist::Artifact
|
2
|
+
module View
|
3
|
+
module FileName
|
4
|
+
DEFAULT_TEMPLATE_LANG = 'html.erb'
|
5
|
+
DEFAULT_REST_ACTION = 'show'
|
6
|
+
|
7
|
+
DIR = Rails3::Assist::Artifact::Directory
|
8
|
+
|
9
|
+
def view_file_name folder, *args
|
10
|
+
action, type, args = get_view_args(args)
|
11
|
+
File.expand_path File.join(DIR.view_dir, folder.to_s, "#{action}.#{type}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def get_view_args args
|
15
|
+
args = args.flatten
|
16
|
+
action = DEFAULT_REST_ACTION
|
17
|
+
type = DEFAULT_TEMPLATE_LANG
|
18
|
+
case args.first
|
19
|
+
when Hash
|
20
|
+
action = args.first.delete(:action)
|
21
|
+
type = args.first.delete(:type)
|
22
|
+
when String, Symbol
|
23
|
+
action = args.delete_at(0)
|
24
|
+
end
|
25
|
+
case args.first
|
26
|
+
when String, Symbol
|
27
|
+
type = args.delete_at(0)
|
28
|
+
end
|
29
|
+
[action || DEFAULT_REST_ACTION, type || DEFAULT_TEMPLATE_LANG, args]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
include FileName
|
34
|
+
extend FileName
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'rails3_artifactor/base/class_methods'
|
2
|
+
require 'rails3_assist/base'
|
3
|
+
|
4
|
+
module Rails3::Assist::Artifact
|
5
|
+
module Marker
|
6
|
+
def marker name, type, options=nil
|
7
|
+
method = "#{type}_marker"
|
8
|
+
raise "No such marker method in this context: #{self}, ##{method}" if !respond_to? method
|
9
|
+
send method, name, options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Controller
|
14
|
+
def controller_marker name, options=nil
|
15
|
+
"#{name.to_s.camelize}Controller < ActionController::Base"
|
16
|
+
end
|
17
|
+
|
18
|
+
extend self
|
19
|
+
end
|
20
|
+
|
21
|
+
module Helper
|
22
|
+
def helper_marker name, options=nil
|
23
|
+
"#{name.to_s.camelize}Helper"
|
24
|
+
end
|
25
|
+
|
26
|
+
extend self
|
27
|
+
end
|
28
|
+
|
29
|
+
module Permit
|
30
|
+
def permit_marker name, options=nil
|
31
|
+
"#{name.to_s.camelize}"
|
32
|
+
end
|
33
|
+
|
34
|
+
extend self
|
35
|
+
end
|
36
|
+
|
37
|
+
module Mailer
|
38
|
+
def mailer_marker name, options=nil
|
39
|
+
"#{name.to_s.camelize}Mailer < ActionMailer::Base"
|
40
|
+
end
|
41
|
+
|
42
|
+
extend self
|
43
|
+
end
|
44
|
+
|
45
|
+
module Observer
|
46
|
+
def observer_marker name, options=nil
|
47
|
+
"#{name.to_s.camelize}Observer < ActiveRecord::Observer"
|
48
|
+
end
|
49
|
+
|
50
|
+
extend self
|
51
|
+
end
|
52
|
+
|
53
|
+
module Migration
|
54
|
+
def migration_marker name, options=nil
|
55
|
+
"#{name.to_s.camelize} < ActiveRecord::Migration"
|
56
|
+
end
|
57
|
+
|
58
|
+
extend self
|
59
|
+
end
|
60
|
+
|
61
|
+
module Model
|
62
|
+
include Rails3::Assist::BaseHelper
|
63
|
+
|
64
|
+
def model_marker name, options={}
|
65
|
+
return send :orm_marker_name, options if respond_to?(:orm_marker_name)
|
66
|
+
name.to_s.camelize
|
67
|
+
end
|
68
|
+
|
69
|
+
def orm_notify
|
70
|
+
". You must specify an ORM with the macro use_orm, f.ex -- use_orm :active_record"
|
71
|
+
end
|
72
|
+
|
73
|
+
extend self
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'migration_assist'
|
2
|
+
|
3
|
+
Rails::Migration::Assist.rails_root_dir = Rails3::Assist::Directory.rails_root
|
4
|
+
|
5
|
+
module Rails3::Assist::Artifact
|
6
|
+
module Migration
|
7
|
+
include Rails3::Assist::BaseHelper
|
8
|
+
include Rails::Migration::Assist::ClassMethods
|
9
|
+
include Rails3::Assist::Artifact::FileName
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Rails3::Assist::Orm
|
2
|
+
module ActiveRecord
|
3
|
+
include Rails3::Assist::Orm::Base
|
4
|
+
|
5
|
+
def orm_marker_name options=nil
|
6
|
+
'ActiveRecord::Base'
|
7
|
+
end
|
8
|
+
|
9
|
+
def new_model_content name, options={}, &block
|
10
|
+
content = options[:content] || yield if block
|
11
|
+
file_w_inherit(name, orm_marker_name(options)) { content }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Rails3::Assist::Orm
|
2
|
+
module DataMapper
|
3
|
+
include Rails3::Assist::Orm::Base
|
4
|
+
|
5
|
+
def orm_name
|
6
|
+
'DataMapper'
|
7
|
+
end
|
8
|
+
|
9
|
+
def orm_marker_name options=nil
|
10
|
+
"#{orm_name}::Resource"
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_model_content name, options={}, &block
|
14
|
+
content = options[:content] || yield if block
|
15
|
+
file_w_include(name, orm_marker_name(options)) { content }
|
16
|
+
end
|
17
|
+
|
18
|
+
def field_name
|
19
|
+
'property'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Rails3::Assist::Orm
|
2
|
+
module MongoMapper
|
3
|
+
include Rails3::Assist::Orm::Base
|
4
|
+
|
5
|
+
def orm_name
|
6
|
+
'MongoMapper'
|
7
|
+
end
|
8
|
+
|
9
|
+
def new_model_content name, options={}, &block
|
10
|
+
content = options[:content] || yield if block
|
11
|
+
file_w_include(name, orm_marker_name(options)) { content }
|
12
|
+
end
|
13
|
+
|
14
|
+
def field_name
|
15
|
+
'key'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Rails3::Assist::Orm
|
2
|
+
module Mongoid
|
3
|
+
include Rails3::Assist::Orm::Base
|
4
|
+
|
5
|
+
def orm_name
|
6
|
+
'Mongoid'
|
7
|
+
end
|
8
|
+
|
9
|
+
def field_name
|
10
|
+
'field'
|
11
|
+
end
|
12
|
+
|
13
|
+
def new_model_content name, options={}, &block
|
14
|
+
content = options[:content] || yield if block
|
15
|
+
file_w_include(name, orm_marker_name(options)) { content }
|
16
|
+
end
|
17
|
+
|
18
|
+
def field name, type = nil
|
19
|
+
return "#{field_name} :#{name}, :type => #{type}" if type
|
20
|
+
"#{field_name} :#{name}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
3
|
+
module Rails3::Assist::Orm
|
4
|
+
module None
|
5
|
+
include Rails3::Assist::Orm::Base
|
6
|
+
|
7
|
+
def orm_marker_name options=nil
|
8
|
+
@name.to_s.camelize
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_model_content name, options={}, &block
|
12
|
+
content = block ? yield : options[:content]
|
13
|
+
@name = name
|
14
|
+
simple_file(name, orm_marker_name(options)) { content }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Rails3::Assist
|
2
|
+
module Orm
|
3
|
+
module Base
|
4
|
+
# include Rails3::Assist::Artifact::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
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
require_all File.dirname(__FILE__) + '/orm'
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Rails3::Assist::Artifact::CRUD
|
2
|
+
module Create
|
3
|
+
include Rails3::Assist::Artifact::Marker
|
4
|
+
|
5
|
+
def create_artifact name, options={}, &block
|
6
|
+
type = get_type(options)
|
7
|
+
file = make_file_name(name, type)
|
8
|
+
return nil if File.exist?(file)
|
9
|
+
|
10
|
+
create_artifact_dir(file)
|
11
|
+
content = get_content(name, type, content, options, &block)
|
12
|
+
return if content.blank?
|
13
|
+
|
14
|
+
File.overwrite file, content
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def new_artifact_content name, type, content=nil, &block
|
20
|
+
content ||= yield if block
|
21
|
+
%Q{class #{marker(name, type)}
|
22
|
+
#{content}
|
23
|
+
end}
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def content_method type
|
29
|
+
method = :"new_#{type}_content"
|
30
|
+
raise "Content method #{content_method} not found #{orm_notify}" if !respond_to?(method)
|
31
|
+
method
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def create_artifact_dir file
|
36
|
+
# make dir
|
37
|
+
dir = File.dirname(file)
|
38
|
+
FileUtils.mkdir_p dir if !File.directory?(dir)
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_content name, type, content, options = {}, &block
|
42
|
+
content = block ? yield : options[:content]
|
43
|
+
content = type == :model ? content : options.merge(:content => content)
|
44
|
+
method = content_method(type)
|
45
|
+
send method, name, content, &block
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|