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
data/README.markdown
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
Includes various helpers to assist operating on a Rails 3 application, including various Rails 3 artifacts, such as migrations etc.
|
4
4
|
|
5
|
+
## Development status
|
6
|
+
|
7
|
+
TODO specs: artifact
|
8
|
+
|
9
|
+
* files
|
10
|
+
* directory
|
11
|
+
|
5
12
|
## Rails Artifacts
|
6
13
|
|
7
14
|
Rails assist also includes various artifact libraries to help operate on different Rails 3 artifacts.
|
@@ -24,6 +31,7 @@ Rails 3 artifacts that have a CRUD assistant:
|
|
24
31
|
* model (insert bug!)
|
25
32
|
* observer
|
26
33
|
* view
|
34
|
+
* permit (NEW - used with cancan)
|
27
35
|
|
28
36
|
## Model
|
29
37
|
|
@@ -60,10 +68,9 @@ Example:
|
|
60
68
|
|
61
69
|
Aliases: *use_helpers* and *use_helper*
|
62
70
|
|
63
|
-
##
|
71
|
+
## TODO
|
64
72
|
|
65
|
-
|
66
|
-
- rails3_assist/artifact/view.rb:7:in `[]' can't convert Symbol into Integer
|
73
|
+
Refactor: split it up into smaller gems and modules to be loaded individually as the need arises.
|
67
74
|
|
68
75
|
## Note on Patches/Pull Requests
|
69
76
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.5
|
data/lib/rails3_assist/app.rb
CHANGED
@@ -1,47 +1,13 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
self.artifacts + [:view]
|
4
|
-
end
|
5
|
-
|
6
|
-
module ArtifactPath
|
7
|
-
def artifact_path name, type, options={}
|
8
|
-
dir = send :"#{type}_dir", options[:root_path]
|
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
|
-
|
1
|
+
module Rails3::Assist
|
2
|
+
module App
|
20
3
|
def create_empty_tmp *dir_types
|
21
4
|
dir_types.flatten.each do |dir_type|
|
22
|
-
dir = rails_dir_for(dir_type)
|
5
|
+
dir = Rails3::Assist::Directory.rails_dir_for(dir_type)
|
23
6
|
FileUtils.mkdir_p dir
|
24
7
|
end
|
25
|
-
end
|
26
|
-
|
27
|
-
|
8
|
+
end
|
9
|
+
|
10
|
+
extend self
|
11
|
+
end
|
28
12
|
end
|
29
13
|
|
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.helper_list.each do |name|
|
43
|
-
class_eval %{
|
44
|
-
include Rails::Assist::#{name.to_s.camelize}::FileName
|
45
|
-
}
|
46
|
-
end
|
47
|
-
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Rails3::Assist::Artifact
|
2
|
+
module Directory
|
3
|
+
module Methods
|
4
|
+
DIR = Rails3::Assist::Directory
|
5
|
+
APP_DIR = Rails3::Assist::Directory::App
|
6
|
+
|
7
|
+
# :controller, :mailer, :helper, :view, :model, :permit
|
8
|
+
#
|
9
|
+
# controller_dir, mailer_dir ...
|
10
|
+
Rails3::Assist::Artifact.app_artifacts.each do |name|
|
11
|
+
class_eval %{
|
12
|
+
def #{name}_dir options={}
|
13
|
+
File.join(APP_DIR.app_dir(options), '#{name.to_s.pluralize}')
|
14
|
+
end
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
# initializer_dir, locale_dir
|
19
|
+
# stylesheet_dir, javascript_dir
|
20
|
+
{:config => [:initializer, :locale], :public => [:stylesheet, :javascript]}.each_pair do |container, names|
|
21
|
+
names.each do |name|
|
22
|
+
class_eval %{
|
23
|
+
def #{name}_dir options={}
|
24
|
+
Rails3::Assist::Directory.#{container}_dir_for :#{name.to_s.pluralize}, options
|
25
|
+
end
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def migration_dir options={}
|
31
|
+
File.join(DIR.db_dir(options), 'migrations')
|
32
|
+
end
|
33
|
+
|
34
|
+
def observer_dir options={}
|
35
|
+
model_dir options
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
extend Methods
|
40
|
+
include Methods
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'sugar-high/regexp'
|
2
|
+
|
3
|
+
module Rails3::Assist::Artifact
|
4
|
+
module Files
|
5
|
+
module Methods
|
6
|
+
[:model].each do |name|
|
7
|
+
class_eval %{
|
8
|
+
def #{name}_files expr=nil
|
9
|
+
files = Rails3::Assist::Files.rails_app_files(:#{name.to_s.pluralize}).grep_it expr
|
10
|
+
yield files if block_given?
|
11
|
+
files
|
12
|
+
end
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
# artifact files using xxx_[artifact].rb convention, i.e postfixing with type of artifact
|
17
|
+
[:mailer, :observer, :permit, :controller, :helper].each do |name|
|
18
|
+
class_eval %{
|
19
|
+
def #{name}_files expr=nil
|
20
|
+
files = Rails3::Assist::Files.rails_app_files(:#{name.to_s.pluralize}, :pattern => '**/*_#{name}.rb').grep_it expr
|
21
|
+
yield files if block_given?
|
22
|
+
files
|
23
|
+
end
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def view_files *args
|
28
|
+
expr, model_name = Helper.get_view_args args
|
29
|
+
ext = last_option(args)[:template_language] || 'erb'
|
30
|
+
pattern = model_name ? "#{model_name.to_s.pluralize}/*.#{ext}*" : "**/*.#{ext}*"
|
31
|
+
files = Rails3::Assist::Files.rails_app_files(:views, :pattern => pattern).grep_it expr
|
32
|
+
yield files if block_given?
|
33
|
+
files
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
[:erb, :haml].each do |name|
|
38
|
+
class_eval %{
|
39
|
+
def #{name}_view_files *args
|
40
|
+
view_files args, :template_language => :#{name}
|
41
|
+
end
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
extend Methods
|
46
|
+
include Methods
|
47
|
+
|
48
|
+
module Helper
|
49
|
+
def self.get_view_args args
|
50
|
+
args = args.flatten
|
51
|
+
first_arg = args.first
|
52
|
+
case first_arg
|
53
|
+
when Regexp
|
54
|
+
expr = first_arg
|
55
|
+
when String, Symbol
|
56
|
+
_model = first_arg
|
57
|
+
end
|
58
|
+
expr = args[1] if args.size > 1 && args[1].kind_of?(Regexp)
|
59
|
+
[expr, _model]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Rails3::Assist::Artifact
|
2
|
+
module Path
|
3
|
+
include Rails3::Assist::Artifact::Directory
|
4
|
+
|
5
|
+
def artifact_path name, type, options={}
|
6
|
+
dir = send :"#{type}_dir", options
|
7
|
+
File.join(dir, "#{name}#{type_postfix type}.rb")
|
8
|
+
end
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
def type_postfix type
|
13
|
+
"_#{type}" if ![:model].include?(type)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Rails3::Assist::Artifact
|
2
|
+
module Methods
|
3
|
+
def helper_list
|
4
|
+
Rails3::Assist.artifacts + [:view]
|
5
|
+
end
|
6
|
+
|
7
|
+
def app_artifacts
|
8
|
+
[:controller, :mailer, :helper, :view, :model, :permit]
|
9
|
+
end
|
10
|
+
|
11
|
+
def rails_artifacts
|
12
|
+
@rails_artifacts ||= begin
|
13
|
+
files_methods = Rails3::Assist::Artifact::Files.instance_methods
|
14
|
+
files_symbols = files_methods.grep(/_files$/).map{|f| f.to_s.gsub(/^(.*)_files/, '\1').to_sym }
|
15
|
+
|
16
|
+
# dir_methods = Rails3::Assist::Artifact::Directory.instance_methods
|
17
|
+
# dir_symbols = dir_methods.map{|dir| dir.to_s.gsub(/^(.*)_dir/, '\1').to_sym }
|
18
|
+
dir_symbols = []
|
19
|
+
|
20
|
+
(files_symbols + dir_symbols).uniq
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def valid_artifact? type
|
25
|
+
rails_artifacts.include?(type)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
extend Methods
|
30
|
+
include Methods
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
require_all File.dirname(__FILE__) + '/artifact'
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Rails3::Assist::Directory
|
2
|
+
module App
|
3
|
+
module Methods
|
4
|
+
def app_directories
|
5
|
+
Rails3::Assist::Artifact::app_artifacts.map {|a| a.to_s.pluralize.to_sym}
|
6
|
+
end
|
7
|
+
|
8
|
+
def app_dir options={}
|
9
|
+
rails_root_dir = Rails3::Assist::Directory::Root.root_dir(options)
|
10
|
+
File.join(rails_root_dir, 'app')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
include Methods
|
15
|
+
extend Methods
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rails3::Assist::Directory
|
2
|
+
module Container
|
3
|
+
|
4
|
+
# return list of symbols for all kinds of supported Rails 3 containers
|
5
|
+
# (those that have a [container]_dir method)
|
6
|
+
|
7
|
+
module Methods
|
8
|
+
def rails_containers
|
9
|
+
app_methods = Rails3::Assist::Directory.instance_methods
|
10
|
+
artifact_methods = Rails3::Assist::Artifact::Directory.instance_methods
|
11
|
+
all_methods = app_methods + artifact_methods
|
12
|
+
|
13
|
+
all_methods.grep(/_dir$/).map{|dir| dir.to_s.gsub(/^(.*)_dir/, '\1').to_sym }
|
14
|
+
end
|
15
|
+
|
16
|
+
def valid_container? type
|
17
|
+
rails_containers.include?(type)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
include Methods
|
22
|
+
extend Methods
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rails3::Assist::Directory
|
2
|
+
module Root
|
3
|
+
module Methods
|
4
|
+
def root_directories
|
5
|
+
[:app, :config, :db, :public, :lib, :log, :doc, :test, :spec]
|
6
|
+
end
|
7
|
+
|
8
|
+
def root_dir options={}
|
9
|
+
raise ArgumentError, "options argument to root_dir must be a hash, was: #{options.inspect}" if options && !options.kind_of?(Hash)
|
10
|
+
dir = options[:root_path] if options
|
11
|
+
dir ||= Rails3::Assist::Directory.rails_root || Rails.root
|
12
|
+
raise "You must set the Rails app root dir: Rails::Assist::App.root_dir = '/my/root/dir'" if !dir
|
13
|
+
dir
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
include Methods
|
18
|
+
extend Methods
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_all File.dirname(__FILE__) + '/directory'
|
2
|
+
require 'rails3_assist/artifact'
|
3
|
+
|
4
|
+
module Rails3::Assist
|
5
|
+
module Directory
|
6
|
+
class << self
|
7
|
+
attr_accessor :rails_root
|
8
|
+
end
|
9
|
+
|
10
|
+
include Root
|
11
|
+
include App
|
12
|
+
include Container
|
13
|
+
|
14
|
+
# dir_for helpers
|
15
|
+
# -------------------
|
16
|
+
|
17
|
+
module Methods
|
18
|
+
DIR = Rails3::Assist::Artifact::Directory
|
19
|
+
|
20
|
+
# :app, :config, :db, :public, :lib, :log, :doc, :test, :spec
|
21
|
+
#
|
22
|
+
# app_dir, config_dir ...
|
23
|
+
Rails3::Assist::Directory::Root.root_directories.each do |name|
|
24
|
+
class_eval %{
|
25
|
+
def #{name}_dir options={}
|
26
|
+
::File.join(Rails3::Assist::Directory::Root.root_dir(options), '#{name}')
|
27
|
+
end
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def rails_dir_for type, options={}
|
32
|
+
raise ArgumentError, '#rails_dir_for takes a dir type argument' if !type
|
33
|
+
dir_method = "#{type}_dir"
|
34
|
+
return send(dir_method, options) if respond_to?(dir_method)
|
35
|
+
DIR.send(dir_method, options) if DIR.respond_to?(dir_method)
|
36
|
+
end
|
37
|
+
|
38
|
+
def app_dir_for type, options={}
|
39
|
+
::File.join(app_dir(options), type.to_s.pluralize)
|
40
|
+
end
|
41
|
+
|
42
|
+
def config_dir_for type, options={}
|
43
|
+
::File.join(config_dir(options), type.to_s.pluralize)
|
44
|
+
end
|
45
|
+
|
46
|
+
def public_dir_for type, options={}
|
47
|
+
::File.join(public_dir(options), type.to_s.pluralize)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
include Methods
|
52
|
+
extend Methods
|
53
|
+
|
54
|
+
end # Directories
|
55
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'sugar-high/file'
|
2
|
+
|
3
|
+
module Rails3::Assist::File
|
4
|
+
module Application
|
5
|
+
module Methods
|
6
|
+
def insert_application_config statement=nil, &block
|
7
|
+
statement = block ? yield : "config.#{statement}"
|
8
|
+
File.insert_into application_file, statement, :after => 'Rails::Application', &block
|
9
|
+
end
|
10
|
+
end
|
11
|
+
include Methods
|
12
|
+
extend Methods
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Rails3::Assist::File
|
2
|
+
module Environment
|
3
|
+
def insert_before_application_init content=nil, &block
|
4
|
+
insert_application_init :before, content, &block
|
5
|
+
end
|
6
|
+
|
7
|
+
def insert_after_application_init content=nil, &block
|
8
|
+
insert_application_init :after, content, &block
|
9
|
+
end
|
10
|
+
|
11
|
+
def insert_application_init place, statement=nil, &block
|
12
|
+
File.insert_into environment_file, statement, place => /\w+::Application.initialize!/
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require_all File.dirname(__FILE__)
|
2
|
+
|
3
|
+
module Rails3::Assist::File
|
4
|
+
module Special
|
5
|
+
module Methods
|
6
|
+
# application_file, environment_file
|
7
|
+
[:application, :environment].each do |name|
|
8
|
+
class_eval %{
|
9
|
+
def #{name}_file
|
10
|
+
File.join(Rails3::Assist::Directory.config_dir, '#{name}.rb')
|
11
|
+
end
|
12
|
+
}
|
13
|
+
end
|
14
|
+
|
15
|
+
def seed_file
|
16
|
+
File.join(Rails3::Assist::Directory.db_dir, 'seeds.rb')
|
17
|
+
end
|
18
|
+
|
19
|
+
# read_application_file
|
20
|
+
# append_to_application_file
|
21
|
+
[:application, :environment, :seed].each do |name|
|
22
|
+
class_eval %{
|
23
|
+
def read_#{name}_file
|
24
|
+
fname = #{name}_file
|
25
|
+
File.read(fname) if File.file?(fname)
|
26
|
+
end
|
27
|
+
|
28
|
+
def remove_#{name}_file
|
29
|
+
File.delete #{name}_file
|
30
|
+
end
|
31
|
+
|
32
|
+
def append_to_#{name}_file content=nil, &block
|
33
|
+
File.append(#{name}_file, content, &block)
|
34
|
+
end
|
35
|
+
}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
include Methods
|
40
|
+
extend Methods
|
41
|
+
|
42
|
+
include Rails3::Assist::File::Application
|
43
|
+
include Rails3::Assist::File::Environment
|
44
|
+
|
45
|
+
extend Rails3::Assist::File::Application
|
46
|
+
extend Rails3::Assist::File::Environment
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Rails3::Assist
|
2
|
+
module File
|
3
|
+
module Methods
|
4
|
+
{:initializer => '.rb', :db => '.rb', :migration => '.rb', :locale => '.yml', :javascript => 'js', :stylesheet => 'css'}.each_pair do |name, ext|
|
5
|
+
plural_name = name.to_s.pluralize
|
6
|
+
|
7
|
+
class_eval %{
|
8
|
+
def #{name}_file name
|
9
|
+
name = (name =~ /.rb$/) ? name : name + '#{ext}'
|
10
|
+
::File.join(Rails3::Assist::Artifact::Directory.#{name}_dir, name)
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_#{name} name, &block
|
14
|
+
::File.overwrite #{name}_file(name) do
|
15
|
+
yield
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove_all_#{plural_name}
|
20
|
+
#{name}_files.each{|f| ::File.delete_file! f}
|
21
|
+
end
|
22
|
+
|
23
|
+
def remove_#{plural_name} *names
|
24
|
+
return remove_all_#{plural_name} if names.empty?
|
25
|
+
names.each do |name|
|
26
|
+
::File.delete #{name}_file(name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
alias_method :remove_#{name}, :remove_#{plural_name}
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
include Methods
|
35
|
+
extend Methods
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rails3_assist/directory'
|
3
|
+
require 'sugar-high/regexp'
|
4
|
+
|
5
|
+
require_all File.dirname(__FILE__) + '/file'
|
6
|
+
|
7
|
+
module Rails3::Assist
|
8
|
+
module Files
|
9
|
+
# we depend on the Directories module doing some of the hard work!
|
10
|
+
module Methods
|
11
|
+
RYBY_FILES = '**/*.rb'
|
12
|
+
|
13
|
+
def rails_app_files type = :app, options = {}
|
14
|
+
dir = Rails3::Assist::Artifact::Directory.send "#{type.to_s.singularize}_dir"
|
15
|
+
expr = options[:expr]
|
16
|
+
file_pattern = options[:pattern] || RYBY_FILES
|
17
|
+
pattern = "#{dir}/#{file_pattern}"
|
18
|
+
FileList[pattern].to_a.grep_it expr
|
19
|
+
end
|
20
|
+
|
21
|
+
def all_files expr=nil
|
22
|
+
pattern = "#{Rails3::Assist::Directory::Root.root_dir}/**/*.*"
|
23
|
+
FileList[pattern].to_a.grep_it expr
|
24
|
+
end
|
25
|
+
|
26
|
+
def app_files expr=nil
|
27
|
+
rails_app_files(:app).grep_it expr
|
28
|
+
end
|
29
|
+
|
30
|
+
# files_from :model, :controller, :matching => /user/
|
31
|
+
def files_from *types, &block
|
32
|
+
expr = last_option(types)[:matching]
|
33
|
+
the_files = types.inject([]) do |files, type|
|
34
|
+
method = :"#{type}_files"
|
35
|
+
files_found = send(method, expr) if respond_to?(method)
|
36
|
+
files_found = Rails3::Assist::Artifact::Files.send(method, expr) if Rails3::Assist::Artifact::Files.respond_to?(method)
|
37
|
+
files + files_found
|
38
|
+
end.compact
|
39
|
+
yield the_files if block
|
40
|
+
the_files
|
41
|
+
end
|
42
|
+
|
43
|
+
def with_files_from type, expr=nil, &block
|
44
|
+
method = "#{type}_files"
|
45
|
+
send method, expr, &block if respond_to?(method)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
[:initializer, :db, :migration].each do |name|
|
50
|
+
class_eval %{
|
51
|
+
def #{name}_files expr=nil
|
52
|
+
files = rails_app_files :#{name}, :expr => expr
|
53
|
+
yield files if block_given?
|
54
|
+
files
|
55
|
+
end
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
{:locale => :yml, :javascript => :js}.each_pair do |name, ext|
|
60
|
+
class_eval %{
|
61
|
+
def #{name}_files expr=nil
|
62
|
+
files = rails_app_files(:#{name}, :pattern => '**/*.#{ext}', :expr => expr)
|
63
|
+
yield files if block_given?
|
64
|
+
files
|
65
|
+
end
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
[:css, :sass].each do |ext|
|
70
|
+
class_eval %{
|
71
|
+
def #{ext}_files expr=nil
|
72
|
+
files = rails_app_files :stylesheets, :pattern => '**/*.#{ext}', :expr => expr
|
73
|
+
yield files if block_given?
|
74
|
+
files
|
75
|
+
end
|
76
|
+
}
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
include Methods
|
81
|
+
extend Methods
|
82
|
+
end # Files
|
83
|
+
end # App
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# open application_file
|
2
|
+
# see if there is the config.[statement] = [expr]
|
3
|
+
|
4
|
+
module RSpec::Rails::ContentMatchers
|
5
|
+
class HaveAppConfig
|
6
|
+
|
7
|
+
use_rails_file_helpers :special # TODO !!!
|
8
|
+
|
9
|
+
attr_reader :left_side, :right_side, :operator
|
10
|
+
|
11
|
+
def initialize statement_hash
|
12
|
+
@left_side, @right_side = *statement.first
|
13
|
+
@operator = statement.last[:op] || '='
|
14
|
+
end
|
15
|
+
|
16
|
+
# TODO: relative to root_path ?
|
17
|
+
def matches?(root_path=nil)
|
18
|
+
content = read_application_file
|
19
|
+
return nil if content.empty?
|
20
|
+
|
21
|
+
ls, rs, op = escape_all(left_side, right_side, operator)
|
22
|
+
(content =~ /config.#{ls}\s*#{op}\s*#{rs}/)
|
23
|
+
end
|
24
|
+
|
25
|
+
def escape_all *texts
|
26
|
+
texts.map{|t| Regexp.escape(t) }
|
27
|
+
end
|
28
|
+
|
29
|
+
def msg
|
30
|
+
"there to be the Application config statement '#{left_side} #{operator} #{right_side}' in config/application.rb"
|
31
|
+
end
|
32
|
+
|
33
|
+
def failure_message
|
34
|
+
"Expected #{msg}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def negative_failure_message
|
38
|
+
super
|
39
|
+
"Did not expect #{msg}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# config.autoload_paths += %W(#{Rails.root}/lib)
|
44
|
+
# have_app_config :autoload_paths => '%W(#{Rails.root}/lib)', :op => '+='
|
45
|
+
def have_app_config statement_hash
|
46
|
+
HaveAppConfig.new statement_hash
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
File without changes
|
data/lib/rails3_assist.rb
CHANGED
@@ -1,21 +1,30 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'require_all'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rake'
|
3
5
|
require 'active_support/inflector'
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
require 'sugar-high/alias'
|
8
|
+
require 'sugar-high/file'
|
9
|
+
require 'sugar-high/regexp'
|
10
|
+
|
11
|
+
require 'rails3_assist/namespaces'
|
12
|
+
|
13
|
+
module Rails3::Assist
|
14
|
+
def self.artifacts
|
15
|
+
[:observer, :controller, :helper, :mailer, :model, :migration, :permit]
|
16
|
+
end
|
17
|
+
|
18
|
+
class << self
|
19
|
+
attr_accessor :debug_on
|
14
20
|
end
|
15
21
|
end
|
16
22
|
|
17
|
-
require 'rails3_assist/extensions/core_ext'
|
18
23
|
require 'rails3_assist/rspec/macro'
|
24
|
+
|
19
25
|
require 'rails3_assist/app'
|
20
|
-
|
26
|
+
require 'rails3_assist/directory'
|
27
|
+
require 'rails3_assist/file'
|
28
|
+
require 'rails3_assist/files'
|
29
|
+
require 'rails3_assist/artifact'
|
21
30
|
|