rails3_assist 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +10 -3
- data/VERSION +1 -1
- data/lib/rails3_assist/app.rb +7 -41
- data/lib/rails3_assist/artifact/directory.rb +42 -0
- data/lib/rails3_assist/artifact/files.rb +63 -0
- data/lib/rails3_assist/artifact/path.rb +16 -0
- data/lib/rails3_assist/artifact.rb +34 -0
- data/lib/rails3_assist/directory/app.rb +17 -0
- data/lib/rails3_assist/directory/container.rb +24 -0
- data/lib/rails3_assist/directory/root.rb +20 -0
- data/lib/rails3_assist/directory.rb +55 -0
- data/lib/rails3_assist/file/application.rb +14 -0
- data/lib/rails3_assist/file/environment.rb +15 -0
- data/lib/rails3_assist/file/special.rb +48 -0
- data/lib/rails3_assist/file.rb +38 -0
- data/lib/rails3_assist/files.rb +83 -0
- data/lib/rails3_assist/namespaces.rb +11 -0
- data/lib/rails3_assist/rspec/configure.rb +2 -0
- data/lib/rails3_assist/rspec/matchers/have_app_config.rb +49 -0
- data/{spec/rails3_assist/app/app_file_names_spec.rb → lib/rails3_assist/rspec/matchers/have_special_file.rb} +0 -0
- data/lib/rails3_assist.rb +20 -11
- data/rails3_assist.gemspec +140 -49
- data/spec/fixtures/.gitignore +4 -0
- data/spec/fixtures/Gemfile +30 -0
- data/spec/fixtures/Gemfile.lock +73 -0
- data/spec/fixtures/README +256 -0
- data/spec/fixtures/Rakefile +7 -0
- data/spec/fixtures/app/controllers/application_controller.rb +3 -0
- data/spec/fixtures/app/controllers/users_controller.rb +83 -0
- data/spec/fixtures/app/helpers/application_helper.rb +2 -0
- data/spec/fixtures/app/helpers/users_helper.rb +2 -0
- data/spec/{rails3_assist/app/app_files_spec.rb → fixtures/app/mailers/user_mailer.rb} +0 -0
- data/spec/fixtures/app/models/user.rb +2 -0
- data/spec/fixtures/app/models/user_observer.rb +0 -0
- data/spec/fixtures/app/permits/user_permit.rb +0 -0
- data/spec/fixtures/app/views/layouts/application.html.erb +14 -0
- data/spec/fixtures/app/views/users/_form.html.erb +21 -0
- data/spec/fixtures/app/views/users/edit.html.erb +6 -0
- data/spec/fixtures/app/views/users/index.html.erb +23 -0
- data/spec/fixtures/app/views/users/new.html.erb +5 -0
- data/spec/fixtures/app/views/users/show.html.erb +10 -0
- data/spec/fixtures/config/application.rb +42 -0
- data/spec/fixtures/config/boot.rb +13 -0
- data/spec/fixtures/config/database.yml +22 -0
- data/spec/fixtures/config/environment.rb +5 -0
- data/spec/fixtures/config/environments/development.rb +26 -0
- data/spec/fixtures/config/environments/production.rb +49 -0
- data/spec/fixtures/config/environments/test.rb +35 -0
- data/spec/fixtures/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/fixtures/config/initializers/inflections.rb +10 -0
- data/spec/fixtures/config/initializers/mime_types.rb +5 -0
- data/spec/fixtures/config/initializers/secret_token.rb +7 -0
- data/spec/fixtures/config/initializers/session_store.rb +8 -0
- data/spec/fixtures/config/locales/en.yml +5 -0
- data/spec/fixtures/config/routes.rb +60 -0
- data/spec/fixtures/config.ru +4 -0
- data/spec/fixtures/db/migrate/20100831135208_create_users.rb +13 -0
- data/spec/fixtures/db/seeds.rb +7 -0
- data/spec/fixtures/doc/README_FOR_APP +2 -0
- data/spec/fixtures/lib/tasks/.gitkeep +0 -0
- data/spec/fixtures/public/404.html +26 -0
- data/spec/fixtures/public/422.html +26 -0
- data/spec/fixtures/public/500.html +26 -0
- data/spec/fixtures/public/favicon.ico +0 -0
- data/spec/fixtures/public/images/rails.png +0 -0
- data/spec/fixtures/public/index.html +239 -0
- data/spec/fixtures/public/javascripts/application.js +2 -0
- data/spec/fixtures/public/javascripts/controls.js +965 -0
- data/spec/fixtures/public/javascripts/dragdrop.js +974 -0
- data/spec/fixtures/public/javascripts/effects.js +1123 -0
- data/spec/fixtures/public/javascripts/prototype.js +6001 -0
- data/spec/fixtures/public/javascripts/rails.js +175 -0
- data/spec/fixtures/public/robots.txt +5 -0
- data/spec/fixtures/public/stylesheets/.gitkeep +0 -0
- data/spec/fixtures/public/stylesheets/scaffold.css +56 -0
- data/spec/fixtures/script/rails +6 -0
- data/spec/fixtures/test/fixtures/users.yml +7 -0
- data/spec/fixtures/test/functional/users_controller_test.rb +49 -0
- data/spec/fixtures/test/performance/browsing_test.rb +9 -0
- data/spec/fixtures/test/test_helper.rb +13 -0
- data/spec/fixtures/test/unit/helpers/users_helper_test.rb +4 -0
- data/spec/fixtures/test/unit/user_test.rb +8 -0
- data/spec/fixtures/vendor/plugins/.gitkeep +0 -0
- data/spec/fixtures.rb +3 -0
- data/spec/rails3_assist/app_spec.rb +30 -0
- data/spec/rails3_assist/artifact/directory_spec.rb +66 -0
- data/spec/rails3_assist/artifact/files_spec.rb +64 -0
- data/spec/rails3_assist/artifact/path_spec.rb +23 -0
- data/spec/rails3_assist/artifact_spec.rb +33 -0
- data/spec/rails3_assist/directory/app_spec.rb +41 -0
- data/spec/rails3_assist/directory/container_spec.rb +63 -0
- data/spec/rails3_assist/directory/root_spec.rb +41 -0
- data/spec/rails3_assist/directory_spec.rb +59 -0
- data/spec/rails3_assist/file/application_spec.rb +33 -0
- data/spec/rails3_assist/file/environment_spec.rb +49 -0
- data/spec/rails3_assist/file/special_spec.rb +61 -0
- data/spec/rails3_assist/file_spec.rb +48 -0
- data/spec/rails3_assist/files_spec.rb +128 -0
- data/spec/rails3_assist/rspec/have_app_config_spec.rb +0 -0
- data/spec/spec_helper.rb +4 -2
- metadata +140 -49
- data/lib/rails3_assist/app/file_names.rb +0 -97
- data/lib/rails3_assist/app/methods/crud.rb +0 -31
- data/lib/rails3_assist/app/methods/new_content.rb +0 -11
- data/lib/rails3_assist/app/rails_dirs.rb +0 -106
- data/lib/rails3_assist/app/rails_files.rb +0 -128
- data/lib/rails3_assist/artifact/markers.rb +0 -45
- data/lib/rails3_assist/artifact/migration.rb +0 -10
- data/lib/rails3_assist/artifact/orm.rb +0 -136
- data/lib/rails3_assist/artifact/view.rb +0 -70
- data/lib/rails3_assist/base/class_methods.rb +0 -11
- data/lib/rails3_assist/base/create.rb +0 -48
- data/lib/rails3_assist/base/file_name.rb +0 -40
- data/lib/rails3_assist/base/insert.rb +0 -57
- data/lib/rails3_assist/base/read.rb +0 -19
- data/lib/rails3_assist/base/remove.rb +0 -14
- data/lib/rails3_assist/base.rb +0 -49
- data/lib/rails3_assist/extensions/core_ext.rb +0 -29
- data/lib/rails3_assist/rspec/macro.rb +0 -34
- data/spec/rails3_assist/app/app_dirs_spec.rb +0 -23
- data/spec/rails3_assist/artifact/controller/controller_spec.rb +0 -33
- data/spec/rails3_assist/artifact/helper/helper_spec.rb +0 -33
- data/spec/rails3_assist/artifact/mailer/mailer_spec.rb +0 -33
- data/spec/rails3_assist/artifact/migration/migration_spec.rb +0 -49
- data/spec/rails3_assist/artifact/model/model_spec.rb +0 -34
- data/spec/rails3_assist/artifact/observer/observer_spec.rb +0 -34
- data/spec/rails3_assist/artifact/orm/active_record_spec.rb +0 -33
- data/spec/rails3_assist/artifact/orm/mongo_mapper_spec.rb +0 -63
- data/spec/rails3_assist/artifact/orm/mongoid_spec.rb +0 -63
- data/spec/rails3_assist/artifact/view_spec/view_controller_action_spec.rb +0 -65
- data/spec/rails3_assist/artifact/view_spec/view_controller_default_action_specc.rb +0 -32
@@ -1,97 +0,0 @@
|
|
1
|
-
require 'migration_assist'
|
2
|
-
|
3
|
-
module Rails::Assist
|
4
|
-
module View
|
5
|
-
module FileName
|
6
|
-
DEFAULT_TEMPLATE_LANG = 'html.erb'
|
7
|
-
DEFAULT_REST_ACTION = 'show'
|
8
|
-
|
9
|
-
def view_file_name folder, *args
|
10
|
-
action, type, args = get_view_args(args)
|
11
|
-
File.expand_path File.join(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, type, args]
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
include FileName
|
34
|
-
end
|
35
|
-
|
36
|
-
module Migration
|
37
|
-
module FileName
|
38
|
-
include Rails::Migration::Assist::ClassMethods
|
39
|
-
|
40
|
-
class FindError
|
41
|
-
attr_accessor :find_expr
|
42
|
-
|
43
|
-
def initialize find_expr
|
44
|
-
self.find_expr = find_expr
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def migration_file_name name, options={}
|
49
|
-
number = options[:number]
|
50
|
-
|
51
|
-
migration_dir_name = File.expand_path(migration_dir options[:root_path])
|
52
|
-
|
53
|
-
number = next_migration_number(migration_dir_name) if !number
|
54
|
-
File.join(migration_dir, "#{number}_#{name}.rb")
|
55
|
-
end
|
56
|
-
|
57
|
-
def find_migration name, options={}
|
58
|
-
root_path = options[:root_path]
|
59
|
-
|
60
|
-
migration_dir_name = File.expand_path(migration_dir options[:root_path])
|
61
|
-
|
62
|
-
migration_find_expr = "#{migration_dir_name}/[0-9]*_*.rb"
|
63
|
-
migrations = Dir.glob(migration_find_expr)
|
64
|
-
|
65
|
-
find_err = FindError.new migration_find_expr
|
66
|
-
|
67
|
-
return find_err if migrations.empty?
|
68
|
-
|
69
|
-
migration_find_expr = /\d+_#{name}\.rb$/
|
70
|
-
find_err.find_expr = migration_find_expr
|
71
|
-
|
72
|
-
matching_migrations = migrations.grep(migration_find_expr)
|
73
|
-
|
74
|
-
return find_err if matching_migrations.empty?
|
75
|
-
|
76
|
-
migration_file = (options[:last]) ? matching_migrations.last : matching_migrations.first
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
include FileName
|
81
|
-
end
|
82
|
-
|
83
|
-
(Rails::Assist.artifacts. - [:migration, :view]).each do |name|
|
84
|
-
class_eval %{
|
85
|
-
module #{name.to_s.camelize}
|
86
|
-
module FileName
|
87
|
-
|
88
|
-
def #{name}_file_name name, options=nil
|
89
|
-
artifact_path name, :#{name}, options
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
include FileName
|
94
|
-
end
|
95
|
-
}
|
96
|
-
end
|
97
|
-
end
|
@@ -1,31 +0,0 @@
|
|
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
|
@@ -1,106 +0,0 @@
|
|
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 options={}
|
41
|
-
dir = options[:root_path] if options
|
42
|
-
dir ||= Rails::Assist::App.rails_root_dir || Rails.root
|
43
|
-
raise "You must set the Rails app root dir: Rails::Assist::App.root_dir = '/my/root/dir'" if !dir
|
44
|
-
dir
|
45
|
-
end
|
46
|
-
|
47
|
-
def rails_dir_for type, options={}
|
48
|
-
raise ArgumentError, '#rails_dir_for takes a dir type argument' if !type
|
49
|
-
dir_method = "#{type}_dir"
|
50
|
-
self.send(dir_method, options) if respond_to?(dir_method)
|
51
|
-
end
|
52
|
-
|
53
|
-
def migration_dir options={}
|
54
|
-
File.join(db_dir(options), 'migrations')
|
55
|
-
end
|
56
|
-
|
57
|
-
def config_dir_for type, options={}
|
58
|
-
File.join(config_dir(options), type.to_s)
|
59
|
-
end
|
60
|
-
|
61
|
-
def initializer_dir options={}
|
62
|
-
config_dir_for type :initializers, options
|
63
|
-
end
|
64
|
-
|
65
|
-
def locale_dir options={}
|
66
|
-
config_dir_for type :locales, options
|
67
|
-
end
|
68
|
-
|
69
|
-
def public_dir_for type, options={}
|
70
|
-
File.join(public_dir(options), type.to_s)
|
71
|
-
end
|
72
|
-
|
73
|
-
def stylesheet_dir options={}
|
74
|
-
public_dir_for :stylesheets, options
|
75
|
-
end
|
76
|
-
|
77
|
-
def javascript_dir options={}
|
78
|
-
public_dir_for :javascripts, options
|
79
|
-
end
|
80
|
-
|
81
|
-
root_directories.each do |name|
|
82
|
-
class_eval %{
|
83
|
-
def #{name}_dir options={}
|
84
|
-
File.join(root_dir(options), '#{name}')
|
85
|
-
end
|
86
|
-
}
|
87
|
-
end
|
88
|
-
|
89
|
-
app_artifacts.each do |name|
|
90
|
-
class_eval %{
|
91
|
-
def #{name}_dir options={}
|
92
|
-
File.join(app_dir(options), '#{name}')
|
93
|
-
end
|
94
|
-
}
|
95
|
-
end
|
96
|
-
|
97
|
-
def app_dir options={}
|
98
|
-
File.join(root_dir(options), 'app')
|
99
|
-
end
|
100
|
-
|
101
|
-
def observer_dir options={}
|
102
|
-
model_dir options
|
103
|
-
end
|
104
|
-
end # RailsDirs
|
105
|
-
end # App
|
106
|
-
end
|
@@ -1,128 +0,0 @@
|
|
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
|
@@ -1,45 +0,0 @@
|
|
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 Migration
|
27
|
-
def migration_marker name, options=nil
|
28
|
-
"#{name.to_s.camelize} < ActiveRecord::Migration"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
module Model
|
33
|
-
include Rails::Assist::BaseHelper
|
34
|
-
|
35
|
-
def model_marker name, options={}
|
36
|
-
return send :orm_marker_name, options if respond_to?(:orm_marker_name)
|
37
|
-
name.camelize
|
38
|
-
end
|
39
|
-
|
40
|
-
def orm_notify
|
41
|
-
". You must specify an ORM with the macro use_orm, f.ex -- use_orm :active_record"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
@@ -1,136 +0,0 @@
|
|
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
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module Rails::Assist
|
2
|
-
module View
|
3
|
-
include Rails::Assist::BaseHelper
|
4
|
-
|
5
|
-
# CREATE
|
6
|
-
def create_view name, *args, &block
|
7
|
-
file_name = view_file_name(name, args)
|
8
|
-
dir = File.dirname(file_name)
|
9
|
-
FileUtils.mkdir_p dir if !File.directory?(dir)
|
10
|
-
|
11
|
-
content = get_content(args) || yield if block
|
12
|
-
|
13
|
-
# abort if no content given
|
14
|
-
debug "Warning: Content must be passed in either as a :content hash or a block" if !content
|
15
|
-
return nil if !content
|
16
|
-
|
17
|
-
debug "Writing view file: #{file_name}"
|
18
|
-
# write file content of view
|
19
|
-
File.open(file_name, 'w') do |f|
|
20
|
-
f.puts content
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
# READ
|
25
|
-
def read_view(name, *args, &block)
|
26
|
-
file_name = view_file_name(name, args)
|
27
|
-
debug "reading from: #{file_name}"
|
28
|
-
file = File.new(file_name)
|
29
|
-
raise "The view file: #{file} could not be found" if !file
|
30
|
-
begin
|
31
|
-
content = file.read
|
32
|
-
debug "read content: #{content}"
|
33
|
-
yield content if block
|
34
|
-
content
|
35
|
-
rescue
|
36
|
-
nil
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
# UPDATE
|
41
|
-
def insert_into_view(name, *args, &block)
|
42
|
-
arguments = args.clone
|
43
|
-
action, type, args = get_view_args(args)
|
44
|
-
file_name = view_file_name(name, arguments)
|
45
|
-
debug "file insertion (view): #{file_name}"
|
46
|
-
|
47
|
-
options = args.first.kind_of?(Hash) ? args.first : {}
|
48
|
-
marker = options[:before] || options[:after]
|
49
|
-
|
50
|
-
raise ArgumentError, ":before or :after option must be specified for insertion" if !marker
|
51
|
-
file_insertion(file_name, marker, options, &block)
|
52
|
-
end
|
53
|
-
|
54
|
-
# DELETE
|
55
|
-
def remove_view name, action=nil, type=nil
|
56
|
-
file = view_file_name(name, action, type)
|
57
|
-
FileUtils.rm_f(file) if File.exist?(file)
|
58
|
-
end
|
59
|
-
|
60
|
-
def get_content args
|
61
|
-
args = args.flatten
|
62
|
-
case args.first
|
63
|
-
when Hash
|
64
|
-
args.first[:content]
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
aliases_for :view
|
69
|
-
end
|
70
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Rails::Assist
|
2
|
-
module BaseHelper
|
3
|
-
def new_artifact_content name, type, content=nil, &block
|
4
|
-
content ||= yield if block
|
5
|
-
%Q{class #{marker(name, type)}
|
6
|
-
#{content}
|
7
|
-
end}
|
8
|
-
end
|
9
|
-
|
10
|
-
# CREATE
|
11
|
-
def create_artifact name, options={}, &block
|
12
|
-
type = get_type(options)
|
13
|
-
|
14
|
-
file = make_file_name name, type
|
15
|
-
return if File.exist?(file)
|
16
|
-
|
17
|
-
debug "create #{type}: #{name}, opt: #{options}"
|
18
|
-
debug "file: #{file}"
|
19
|
-
|
20
|
-
# make dir
|
21
|
-
dir = File.dirname(file)
|
22
|
-
FileUtils.mkdir_p dir if !File.directory?(dir)
|
23
|
-
|
24
|
-
content = options[:content]
|
25
|
-
content ||= yield if block
|
26
|
-
|
27
|
-
content_method = :"new_#{type}_content"
|
28
|
-
debug "inner content: #{content}, to inject using ##{content_method}"
|
29
|
-
|
30
|
-
raise "Content method #{content_method} not found #{orm_notify}" if !respond_to?(content_method)
|
31
|
-
|
32
|
-
insert_content = if type == :model
|
33
|
-
send content_method, name, options.merge(:content => content), &block
|
34
|
-
else
|
35
|
-
send content_method, name, content, &block
|
36
|
-
end
|
37
|
-
|
38
|
-
debug "content to insert: #{insert_content}"
|
39
|
-
|
40
|
-
return if insert_content.blank?
|
41
|
-
|
42
|
-
File.open(file, 'w') do |f|
|
43
|
-
f.puts insert_content
|
44
|
-
end
|
45
|
-
debug "file created and content inserted"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|