rails_assist 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,23 +2,23 @@ module RailsAssist::Directory
2
2
  module Root
3
3
  module Methods
4
4
  def root_directories
5
- [:app, :config, :db, :public, :lib, :log, :doc, :test, :spec]
5
+ [:app, :config, :db, :public, :lib, :log, :doc, :test, :spec]
6
6
  end
7
7
 
8
8
  def root_dirpath options={}
9
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
10
+ dir = options[:root_path] if options
11
11
  dir ||= RailsAssist::Directory.rails_root || Rails.root
12
12
  raise "You must set the Rails app root dir: RailsAssist::App.root_dir = '/my/root/dir'" if !dir
13
13
  dir.to_s.path
14
14
  end
15
-
16
- def root_dir options={}
15
+
16
+ def root_dir options={}
17
17
  root_dirpath(options).dir
18
- end
19
- end
20
-
18
+ end
19
+ end
20
+
21
21
  include Methods
22
22
  extend Methods
23
23
  end
24
- end
24
+ end
@@ -1,18 +1,17 @@
1
1
  require_all File.dirname(__FILE__) + '/file'
2
- # require 'sugar-high/file'
3
2
 
4
3
  module RailsAssist
5
4
  module File
6
5
  module Methods
7
- {:initializer => 'rb', :db => 'rb', :migration => 'rb', :locale => 'yml', :javascript => 'js', :stylesheet => 'css', :config => '.rb', :db => '.rb'}.each_pair do |name, ext|
6
+ {:config => 'yml', :initializer => 'rb', :db => 'rb', :migration => 'rb', :locale => 'yml', :coffee => 'coffee', :javascript => 'js', :stylesheet => 'css', :config => '.rb', :db => '.rb'}.each_pair do |name, ext|
8
7
  plural_name = name.to_s.pluralize
9
8
  pure_ext = ext.gsub /^\./, ''
10
- class_eval %{
9
+ class_eval %{
11
10
  def #{name}_file? name
12
11
  name = name.as_filename
13
- name = (name =~ /.rb$/) ? name : "\#{name}.#{pure_ext}"
12
+ name = (name =~ /.rb$/) ? name : "\#{name}.#{pure_ext}"
14
13
  #{name}_file(name)
15
- end
14
+ end
16
15
  alias_method :has_#{name}_file?, :#{name}_file?
17
16
 
18
17
  def #{name}_files? *names
@@ -20,44 +19,46 @@ module RailsAssist
20
19
  return false if !#{name}_file?(name)
21
20
  end
22
21
  true
23
- end
24
-
22
+ end
23
+
25
24
  def #{name}_filepath name
26
25
  name = name.as_filename
27
26
  name = (name =~ /.rb$/) ? name : "\#{name}.#{pure_ext}"
28
- [RailsAssist::Artifact::Directory.#{name}_dirpath, name].file_join
29
- end
27
+ [RailsAssist::Directory.#{name}_dirpath, name].file_join
28
+ end
30
29
 
31
30
  def #{name}_file name
32
- name = name.as_filename
31
+ name = name.as_filename
33
32
  #{name}_filepath(name).new_file
34
- end
33
+ end
35
34
 
36
35
  def create_#{name} name, &block
37
- name = name.as_filename
36
+ name = name.as_filename
38
37
 
39
38
  # create dir for artifact if it doesn't exist
40
- RailsAssist::App.create_empty_tmp :#{name} if !RailsAssist::Artifact::Directory.#{name}_dir
39
+ path = RailsAssist::Directory.#{name}_dirpath
40
+ RailsAssist::App.create_empty_tmp(:#{name}) if !::File.directory?(path)
41
41
 
42
42
  #{name}_file(name).overwrite do
43
43
  yield
44
44
  end
45
45
  end
46
+ alias_method :create_#{name}_file, :create_#{name}
46
47
 
47
- def read_#{name} name
48
- name = name.as_filename
48
+ def read_#{name} name
49
+ name = name.as_filename
49
50
  #{name}_file(name).read_content
50
51
  end
51
52
  alias_method :read_#{name}_file, :read_#{name}
52
53
 
53
54
  def replace_#{name}_content name, args = {}, &block
54
- name = name.as_filename
55
+ name = name.as_filename
55
56
  if !(args.kind_of?(Hash) && args[:where])
56
57
  raise ArgumentError, "#replace_#{name}_content Must take a hash argument with a :where option that is the content to be matched and replaced"
57
- end
58
+ end
58
59
 
59
60
  replace_content = block ? yield : args[:with]
60
- if !replace_content
61
+ if !replace_content
61
62
  raise ArgumentError, "#replace_#{name}_content Must take a block or a :with hash option that is the content to replace with"
62
63
  end
63
64
 
@@ -65,27 +66,30 @@ module RailsAssist
65
66
  end
66
67
 
67
68
  def remove_all_#{plural_name}
68
- return if !(RailsAssist::Artifact::Directory.#{name}_dir.path.directory?) # bug?
69
+ path = RailsAssist::Directory.#{name}_dirpath
70
+ return if !::File.directory?(path)
69
71
  #{name}_files.delete_all!
70
72
  end
71
73
 
72
74
  def remove_#{plural_name} *names
73
- return remove_all_#{plural_name} if names.empty?
75
+ return remove_all_#{plural_name} if names.empty?
74
76
  names.to_filenames.each do |name|
75
77
  name = (name =~ /.rb$/) ? name : "\#{name}.#{pure_ext}"
76
78
  #{name}_file(name).delete!
77
79
  end
78
80
  end
79
- alias_method :remove_#{name}, :remove_#{plural_name}
81
+ alias_method :remove_#{name}, :remove_#{plural_name}
82
+ alias_method :remove_#{name}_file, :remove_#{name}
83
+ alias_method :remove_#{plural_name}_files, :remove_#{name}
80
84
  }
81
85
  end
82
86
  end
83
87
 
84
88
  include Special
85
89
  extend Special
86
-
90
+
87
91
  include Methods
88
92
  extend Methods
89
93
  end
90
- end
94
+ end
91
95
 
@@ -6,7 +6,7 @@ module RailsAssist::File
6
6
  def insert_application_config statement=nil, &block
7
7
  statement = block ? yield : "config.#{statement}"
8
8
  application_file.insert statement, :after => 'Rails::Application'
9
- end
9
+ end
10
10
  end
11
11
  include Methods
12
12
  extend Methods
@@ -9,8 +9,8 @@ module RailsAssist::File
9
9
  end
10
10
 
11
11
  def insert_application_init place, statement=nil, &block
12
- statement = block ? yield : statement
12
+ statement = block ? yield : statement
13
13
  environment_file.insert statement, place => /\w+#{Regexp.escape('::Application.initialize!')}/
14
- end
14
+ end
15
15
  end
16
- end
16
+ end
@@ -16,7 +16,7 @@ module RailsAssist::File
16
16
  def gem_filepath
17
17
  [RailsAssist::Directory::Root.root_dirpath, 'Gemfile'].file_join
18
18
  end
19
-
19
+
20
20
  def gem_file
21
21
  raise "No Gemfile found at #{gem_filepath}" if !File.exist? gem_filepath
22
22
  gem_filepath.new_file
@@ -12,7 +12,7 @@ module RailsAssist::File
12
12
  statement = block ? yield : route_stmt
13
13
  routes_file.insert statement, :before_last => 'end'
14
14
  end
15
-
15
+
16
16
  alias_method :insert_as_last_route_statement, :insert_last_in_routes
17
17
  end
18
18
  end
@@ -1,7 +1,7 @@
1
1
  require_all File.dirname(__FILE__)
2
2
 
3
3
  module RailsAssist::File
4
- module Special
4
+ module Special
5
5
  module Methods
6
6
  # application_file, environment_file
7
7
  [:application, :environment, :routes, :boot].each do |name|
@@ -14,7 +14,7 @@ module RailsAssist::File
14
14
  #{name}_filepath.file
15
15
  end
16
16
  }
17
- end
17
+ end
18
18
 
19
19
  def database_filepath
20
20
  [RailsAssist::Directory.config_dir.path, 'database.yml'].file_join
@@ -33,11 +33,11 @@ module RailsAssist::File
33
33
  raise "No Seed file found at #{seed_filepath}" if !File.exist? seed_filepath
34
34
  seed_filepath.new_file
35
35
  end
36
-
36
+
37
37
  # read_application_file
38
38
  # append_to_application_file
39
39
  [:application, :environment, :seed, :gem, :routes, :boot, :database].each do |name|
40
- class_eval %{
40
+ class_eval %{
41
41
  def read_#{name}_file
42
42
  #{name}_file.read_content
43
43
  end
@@ -60,19 +60,19 @@ module RailsAssist::File
60
60
  }
61
61
  end
62
62
  end
63
-
63
+
64
64
  include Methods
65
65
  extend Methods
66
-
66
+
67
67
  include RailsAssist::File::Application
68
68
  include RailsAssist::File::Environment
69
69
  include RailsAssist::File::Gemfile
70
- include RailsAssist::File::Routes
70
+ include RailsAssist::File::Routes
71
71
 
72
72
  extend RailsAssist::File::Application
73
73
  extend RailsAssist::File::Environment
74
74
  extend RailsAssist::File::Gemfile
75
- extend RailsAssist::File::Routes
75
+ extend RailsAssist::File::Routes
76
76
 
77
77
  end
78
78
  end
@@ -25,7 +25,7 @@ module RailsAssist
25
25
 
26
26
  def all_filepaths expr=nil
27
27
  pattern = "#{RailsAssist::Directory::Root.root_dirpath}/**/*.*"
28
- FileList[pattern].to_a.grep_it expr
28
+ FileList[pattern].to_a.grep_it expr
29
29
  end
30
30
 
31
31
  def all_files expr=nil
@@ -82,7 +82,7 @@ module RailsAssist
82
82
  }
83
83
  end
84
84
 
85
- {:locale => :yml, :javascript => :js}.each_pair do |name, ext|
85
+ {:config => :yml, :locale => :yml, :javascript => :js, :coffee => :coffee}.each_pair do |name, ext|
86
86
  class_eval %{
87
87
  def #{name}_filepaths expr=nil
88
88
  filepaths = rails_app_files(:#{name}, :pattern => '**/*.#{ext}', :expr => expr)
@@ -19,9 +19,9 @@ module RailsAssist
19
19
  end
20
20
  end
21
21
  end
22
-
23
- def assist_with *types
24
- types.each{|type| use_helper type}
22
+
23
+ def assist_with *types
24
+ types.each{|type| use_helper type}
25
25
  end
26
26
  alias_method :load_helpers, :assist_with
27
27
  alias_method :use_helpers, :assist_with
@@ -33,7 +33,7 @@ module RailsAssist
33
33
  include module_name.constantize
34
34
  if [:files, :directory].include? type
35
35
  module_name = "RailsAssist::Artifact::#{type.to_s.camelize}"
36
- include module_name.constantize
36
+ include module_name.constantize
37
37
  end
38
38
  rescue
39
39
  raise ArgumentError, "Unregistered RailsAssist library: #{type}, #{module_name}"
@@ -51,18 +51,18 @@ module RailsAssist
51
51
  end
52
52
  end
53
53
  end
54
-
54
+
55
55
  def use_helper type
56
56
  if type == :special
57
57
  class_eval do
58
58
  include "RailsAssist::File::Special".constantize
59
- end
59
+ end
60
60
  return
61
61
  end
62
62
 
63
- return rails_assist(type) if [:file, :files, :directory, :app].include?(type)
63
+ return rails_assist(type) if [:file, :files, :directory, :app].include?(type)
64
64
  artifact_assist(type)
65
- end
65
+ end
66
66
  alias_method :load_helper, :use_helper
67
- end
68
- end
67
+ end
68
+ end
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{rails_assist}
8
- s.version = "0.5.2"
7
+ s.name = "rails_assist"
8
+ s.version = "0.5.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = [%q{Kristian Mandrup}]
12
- s.date = %q{2011-08-24}
13
- s.description = %q{Basic file operation helpers for working with Rails 3 artifacts}
14
- s.email = %q{kmandrup@gmail.com}
11
+ s.authors = ["Kristian Mandrup"]
12
+ s.date = "2011-09-21"
13
+ s.description = "Basic file operation helpers for working with Rails 3 artifacts"
14
+ s.email = "kmandrup@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.markdown"
@@ -132,10 +132,10 @@ Gem::Specification.new do |s|
132
132
  "spec/rails_assist_spec.rb",
133
133
  "spec/spec_helper.rb"
134
134
  ]
135
- s.homepage = %q{http://github.com/kristianmandrup/rails-assist}
136
- s.require_paths = [%q{lib}]
137
- s.rubygems_version = %q{1.8.8}
138
- s.summary = %q{File operation helpers for Rails 3 artifacts}
135
+ s.homepage = "http://github.com/kristianmandrup/rails-assist"
136
+ s.require_paths = ["lib"]
137
+ s.rubygems_version = "1.8.10"
138
+ s.summary = "File operation helpers for Rails 3 artifacts"
139
139
 
140
140
  if s.respond_to? :specification_version then
141
141
  s.specification_version = 3
@@ -9,8 +9,8 @@ end
9
9
  describe RailsAssist::Artifact::Directory do
10
10
  # use_helper :directories
11
11
 
12
- before do
13
- RailsAssist::Directory.rails_root = fixtures_dir
12
+ before do
13
+ RailsAssist::Directory.rails_root = fixtures_dir
14
14
  @test = ArtDir.new
15
15
  end
16
16
 
@@ -23,7 +23,7 @@ describe RailsAssist::Artifact::Directory do
23
23
  @test.#{name}_dir.path.should match /app\/\#{name}/
24
24
  end
25
25
  end
26
- }
26
+ }
27
27
  end
28
28
 
29
29
  describe '#observer_dir' do
@@ -32,14 +32,14 @@ describe RailsAssist::Artifact::Directory do
32
32
  @test.observer_dirpath.should match /app\/models/
33
33
  end
34
34
  end
35
-
35
+
36
36
  describe '#migration_dir' do
37
37
  it "should return migration directory name" do
38
38
  CLASS.migration_dir.path.should match /db\/migrate/
39
39
  @test.migration_dirpath.should match /db\/migrate/
40
40
  end
41
- end
42
-
41
+ end
42
+
43
43
  [:initializer, :locale].each do |name|
44
44
  eval %{
45
45
  describe '##{name}_dir' do
@@ -48,9 +48,9 @@ describe RailsAssist::Artifact::Directory do
48
48
  @test.#{name}_dirpath.should match /config\/\#{name}/
49
49
  end
50
50
  end
51
- }
51
+ }
52
52
  end
53
-
53
+
54
54
  [:stylesheet, :javascript].each do |name|
55
55
  eval %{
56
56
  describe '##{name}_dir' do
@@ -59,7 +59,6 @@ describe RailsAssist::Artifact::Directory do
59
59
  @test.#{name}_dirpath.should match /public\/\#{name}/
60
60
  end
61
61
  end
62
- }
62
+ }
63
63
  end
64
-
65
64
  end
@@ -4,7 +4,7 @@ CLASS = RailsAssist::Artifact::Files
4
4
 
5
5
  class ArtDir
6
6
  extend RailsAssist::UseMacro
7
- use_helper :files
7
+ use_helper :files
8
8
  end
9
9
 
10
10
  describe RailsAssist::Artifact::Files do
@@ -17,61 +17,61 @@ describe RailsAssist::Artifact::Files do
17
17
  @test = ArtDir.new
18
18
  end
19
19
 
20
- describe '#model_files' do
21
- it "should return :model files" do
20
+ describe '#model_files' do
21
+ it "should return :model files" do
22
22
  @test.model_files.file_names.should include 'user.rb'
23
23
  end
24
24
  end
25
25
 
26
- describe '#mailer_files' do
26
+ describe '#mailer_files' do
27
27
  it "should return :mailer files" do
28
28
  @test.mailer_files.file_names.should include 'user_mailer.rb'
29
29
  end
30
30
  end
31
31
 
32
- describe '#observer_files' do
32
+ describe '#observer_files' do
33
33
  it "should return :observer files" do
34
34
  @test.observer_files.file_names.should include 'user_observer.rb'
35
35
  end
36
36
  end
37
37
 
38
- describe '#permit_files' do
38
+ describe '#permit_files' do
39
39
  it "should return :permit files" do
40
40
  @test.permit_files.file_names.should include 'user_permit.rb'
41
41
  end
42
42
  end
43
43
 
44
- describe '#license_files' do
44
+ describe '#license_files' do
45
45
  it "should return :license files" do
46
46
  @test.license_files.file_names.should include 'blogging_license.rb'
47
47
  end
48
48
  end
49
49
 
50
- describe '#validator_files' do
50
+ describe '#validator_files' do
51
51
  it "should return :validator files" do
52
52
  @test.validator_files.file_names.should include 'email_validator.rb'
53
53
  end
54
54
  end
55
-
56
- describe '#helper_files' do
55
+
56
+ describe '#helper_files' do
57
57
  it "should return :helper files" do
58
58
  @test.helper_files.file_names.should include 'users_helper.rb'
59
59
  end
60
60
  end
61
-
62
- describe '#controller_files' do
61
+
62
+ describe '#controller_files' do
63
63
  it "should return :controller files" do
64
64
  @test.controller_files.file_names.should include 'users_controller.rb'
65
65
  end
66
66
  end
67
-
68
- describe '#view_files' do
67
+
68
+ describe '#view_files' do
69
69
  it "should return :view files" do
70
70
  @test.view_files(:user).file_names.should include 'show.html.erb'
71
71
  end
72
72
  end
73
73
 
74
- describe '#erb_view_files' do
74
+ describe '#erb_view_files' do
75
75
  it "should return erb :view files" do
76
76
  @test.erb_view_files(:user).file_names.should include 'show.html.erb'
77
77
  end