rails3_assist 0.2.5 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,77 +1,194 @@
1
1
  # Rails3 Assistant
2
2
 
3
- Includes various helpers to assist operating on a Rails 3 application, including various Rails 3 artifacts, such as migrations etc.
3
+ Includes various helpers to assist operating on a Rails 3 application.
4
4
 
5
- ## Development status
5
+ ## Install
6
6
 
7
- TODO specs: artifact
7
+ <code>gem install rails3_assist</code>
8
8
 
9
- * files
10
- * directory
11
-
12
- ## Rails Artifacts
13
-
14
- Rails assist also includes various artifact libraries to help operate on different Rails 3 artifacts.
15
- These assist libraries mainly contain some common CRUD (Create, Read, Update, Delete) operations.
16
- The same API is shared in all the artifact assist libraries.
17
- The following is a list of the main API, including an alias for each method.
18
-
19
- * create_[x] - new_[x])
20
- * insert_into_[x] - update_[x]
21
- * read_model - [x]_content
22
- * remove_[x] - delete_[x]
23
- * remove_[x]s - delete_[x]s
9
+ ## File Assistants
24
10
 
25
- Rails 3 artifacts that have a CRUD assistant:
11
+ There are file assistants for the following Rails 3 artifacts:
12
+ * locale
13
+ * javascript
14
+ * stylesheet
15
+ * controller
16
+ * helper
17
+ * view
18
+ * model
19
+ * mailer
20
+ * observer
21
+ * permit
22
+ * view
26
23
 
24
+ * [name]_file
25
+ * [name]_files
26
+ * create_[name]_file
27
+ * remove_[name]_file
28
+ * remove_all__[name]s
29
+ * remove_[name]s
30
+
31
+ Example usage:
32
+
33
+ <pre>
34
+ remove_locales 'blip.en', 'blip.dk'
35
+ remove_all_stylesheets
36
+ create_stylesheet 'my_styles.css' do
37
+ %{
38
+ .mystyle {font: bold;}
39
+ }
40
+ end
41
+ remove_stylesheet 'my_styles.css'
42
+
43
+ locale_files
44
+ locale_files 'permit.dk'
45
+ locale_files /permit/ do |files|
46
+ # ...
47
+ end
48
+
49
+ view_files :person
50
+ erb_view_files(:user).file_names.should include 'show.html.erb'
51
+ haml_view_files(:user)
52
+ </pre>
53
+
54
+ ## Directory Assistants
55
+
56
+ There are dir helpers for the following
57
+
58
+ * app
59
+ * config
60
+ * db
61
+ * public
62
+ * lib
63
+ * log
64
+ * doc
65
+ * test
66
+ * spec
67
+
68
+ * locale
69
+ * initializer
70
+ * javascript
71
+ * stylesheet
27
72
  * controller
28
73
  * helper
74
+ * view
75
+ * model
29
76
  * mailer
30
- * migration (pending!)
31
- * model (insert bug!)
32
77
  * observer
78
+ * permit
33
79
  * view
34
- * permit (NEW - used with cancan)
35
80
 
36
- ## Model
81
+ Example usage:
82
+
83
+ <pre>
84
+ config_dir
85
+ observer_dir_
86
+ db_dir :root_path => MY_RAILS_ROOT
87
+ rails_dir_for :migrations
88
+ db_dir_for :migrations
89
+ config_dir_for :initializers, :root_path => MY_RAILS_ROOT
90
+ app_dir_for :models
91
+ </pre>
92
+
93
+ ## Special Rails mutators
94
+
95
+ * insert_application_config
96
+ * insert_before_application_init
97
+ * insert_after_application_init
98
+
99
+ Special file helpers:
100
+
101
+ * application_file
102
+ * environment_file
103
+ * seed_file
37
104
 
38
- * create_model (new_model)
39
- * insert_into_model (update_model)
105
+ * read_[special]_file
106
+ * remove_[special]_file
107
+ * append_to_[special]_file
108
+ * replace_in_[special]_file :where => ... :with => ...
109
+ * remove_from_[special]_file
40
110
 
41
- Create and insert for *model* operate according to the ORM currently used.
42
- The ORM used is specified by calling <code>use_orm :[orm]</code> fx <code>use_orm :active_record</code>
111
+ Example
112
+
113
+ <pre>
114
+ remove_from_application_file /config.root = (\w+?)/
115
+ append_to_seed_file do
116
+ %{
117
+ Person.new :name => 'Mike'
118
+ }
119
+ end
120
+ </pre>
43
121
 
44
122
  ### Usage
45
123
 
46
- Set the root if not already set, then use the special assist/use methods to draw in the modules with all the goodies!
124
+ Set the root if not already set, then use the special assist methods to include the modules with all the goodies!
125
+ See the *Assistants* section below for more info on how to do this.
47
126
 
48
127
  ### Rails root
49
128
 
50
- You have to set the class variable <code>Rails::Assist::App.rails_root_dir</code> to the location of your Rails root directory if you are using this gem outside of Rails,
51
- Fx for testing purposes or something. It will default to use <code>Rails.root</code> if this class variable is not set to override it.
129
+ You have to set the class variable <code>Rails::Assist::Directory.rails_root</code> to the location of your Rails root directory if you are using this gem outside of Rails, fx for testing purposes or something.
130
+
131
+ Note: If this variable is not set, it will assume it is used in a Rails app and therefore assume the root is <code>Rails.root</code>.
52
132
 
53
- In the specs I use the *rails_root_dir* class variable to avoid having to set a Rails app specific variable, which I deemed unnecessary for most of the tests.
133
+ In the specs of this projct, I use the *rails_root* class variable to avoid having to set a Rails app specific variable, which I deemed unnecessary for most of the tests.
54
134
 
55
- ### Artifact assistants
135
+ ### Assistants
56
136
 
57
137
  Generators are often designed to create Rails 3 artifacts or update existing artifacts. It's often useful to include one or more Rails 3 artifact assistants along
58
138
  with a generator assistant (see above).
59
139
 
60
140
  This combination greatly facilitates your work in developing the generator, as much of the heavy lifting will be done for you in the assistants.
141
+
61
142
  To use a specific assistant/helper, simply call:
62
143
 
63
144
  *assist_with [list of assistant symbols]*
64
145
 
65
146
  Example:
66
147
 
67
- <code>assist_with :app, :controller, :model, :view</code>
148
+ <code>assist_with :controller, :model, :view, :permit</code>
68
149
 
69
150
  Aliases: *use_helpers* and *use_helper*
70
151
 
71
- ## TODO
152
+ Available helpers:
153
+
154
+ Artifacts
155
+ * controller
156
+ * model
157
+ * view
158
+ * helper
159
+ * observer
160
+ * mailer
161
+ * migration
162
+ * permit
163
+
164
+ Misc.
165
+ * file
166
+ * files
167
+ * directory
168
+
169
+ ### Using Assistants
170
+
171
+ <pre>
172
+ class MyGenerator < Rails::Generators:NamedBase
173
+ extend Rails3::Assist::UseMacro
174
+
175
+ use_orm :active_record
176
+ use_helpers :file, :files, :controller, :observer, :migration
177
+ ...
178
+ end
179
+ </pre>
180
+
181
+ ### Assistant in RSpec
72
182
 
73
- Refactor: split it up into smaller gems and modules to be loaded individually as the need arises.
183
+ The assistants are preconfigured to be available within RSpec constructs.
74
184
 
185
+ <pre>
186
+ describe 'My Controller' do
187
+ use_helpers :directory, :files, :helper, :mailer
188
+ ...
189
+ end
190
+ </pre>
191
+
75
192
  ## Note on Patches/Pull Requests
76
193
 
77
194
  * Fork the project.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.7
@@ -5,11 +5,20 @@ module Rails3::Assist
5
5
  module Directory
6
6
  class << self
7
7
  attr_accessor :rails_root
8
+
9
+ def method_missing(sym, *args, &block)
10
+ Rails3::Assist::Artifact::Directory.send sym
11
+ end
8
12
  end
9
13
 
10
14
  include Root
15
+ extend Root
16
+
11
17
  include App
18
+ extend App
19
+
12
20
  include Container
21
+ extend Container
13
22
 
14
23
  # dir_for helpers
15
24
  # -------------------
@@ -32,6 +32,14 @@ module Rails3::Assist::File
32
32
  def append_to_#{name}_file content=nil, &block
33
33
  File.append(#{name}_file, content, &block)
34
34
  end
35
+
36
+ def replace_in_#{name}_file options = {}, &block
37
+ File.replace_content_from(#{name}_file, options, &block)
38
+ end
39
+
40
+ def remove_from_#{name}_file content=nil, &block
41
+ File.remove_from(#{name}_file, content, &block)
42
+ end
35
43
  }
36
44
  end
37
45
  end
@@ -11,7 +11,7 @@ module Rails3::Assist
11
11
  RYBY_FILES = '**/*.rb'
12
12
 
13
13
  def rails_app_files type = :app, options = {}
14
- dir = Rails3::Assist::Artifact::Directory.send "#{type.to_s.singularize}_dir"
14
+ dir = Rails3::Assist::Directory.send "#{type.to_s.singularize}_dir"
15
15
  expr = options[:expr]
16
16
  file_pattern = options[:pattern] || RYBY_FILES
17
17
  pattern = "#{dir}/#{file_pattern}"
@@ -1,2 +1,9 @@
1
1
  require 'require_all'
2
- require_all File.dirname(__FILE__) + '/matchers'
2
+
3
+ module RSpec
4
+ module RailsApp
5
+ modules :content_matchers
6
+ end
7
+ end
8
+
9
+ # require_all File.dirname(__FILE__) + '/matchers'
data/lib/rails3_assist.rb CHANGED
@@ -20,11 +20,11 @@ module Rails3::Assist
20
20
  end
21
21
  end
22
22
 
23
- require 'rails3_assist/rspec/macro'
24
-
25
23
  require 'rails3_assist/app'
26
24
  require 'rails3_assist/directory'
27
25
  require 'rails3_assist/file'
28
26
  require 'rails3_assist/files'
29
27
  require 'rails3_assist/artifact'
30
28
 
29
+ require 'rails3_assist/rspec/configure'
30
+
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rails3_assist}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
@@ -41,8 +41,6 @@ Gem::Specification.new do |s|
41
41
  "lib/rails3_assist/files.rb",
42
42
  "lib/rails3_assist/namespaces.rb",
43
43
  "lib/rails3_assist/rspec/configure.rb",
44
- "lib/rails3_assist/rspec/matchers/have_app_config.rb",
45
- "lib/rails3_assist/rspec/matchers/have_special_file.rb",
46
44
  "rails3_assist.gemspec",
47
45
  "rails_generator.log",
48
46
  "spec/fixtures.rb",
@@ -3,11 +3,12 @@ require 'spec_helper'
3
3
  CLASS = Rails3::Assist::Artifact::Files
4
4
 
5
5
  class ArtDir
6
- include CLASS
6
+ extend Rails3::Assist::UseMacro
7
+ use_helper :files
7
8
  end
8
9
 
9
10
  describe Rails3::Assist::Artifact::Files do
10
- # use_helper :directories
11
+ use_helper :directory
11
12
 
12
13
  before do
13
14
  Rails3::Assist::Directory.rails_root = fixtures_dir
@@ -3,7 +3,8 @@ require 'spec_helper'
3
3
  CLASS = Rails3::Assist::Directory
4
4
 
5
5
  class RailsDir
6
- include CLASS
6
+ extend Rails3::Assist::UseMacro
7
+ use_helper :directory
7
8
  end
8
9
 
9
10
  describe Rails3::Assist::Directory do
@@ -16,7 +16,7 @@ describe Rails3::Assist::File do
16
16
 
17
17
  describe '#initializer_file' do
18
18
  it "should return the initializer file 'mime_type' " do
19
- CLASS.initializer_file('mime_type').should match /mime_type/
19
+ AppDir.new.initializer_file('mime_type').should match /mime_type/
20
20
  end
21
21
  end
22
22
 
@@ -3,7 +3,8 @@ require 'spec_helper'
3
3
  CLASS = Rails3::Assist::Files
4
4
 
5
5
  class AppDir
6
- include CLASS
6
+ extend Rails3::Assist::UseMacro
7
+ use_helper :files
7
8
  end
8
9
 
9
10
  describe Rails3::Assist::Files do
@@ -15,7 +16,7 @@ describe Rails3::Assist::Files do
15
16
 
16
17
  describe '#rails_app_files' do
17
18
  it "should return all :app files using default pattern" do
18
- CLASS.rails_app_files(:model)
19
+ AppDir.new.rails_app_files(:model)
19
20
  end
20
21
  end
21
22
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 7
9
+ version: 0.2.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -113,8 +113,6 @@ files:
113
113
  - lib/rails3_assist/files.rb
114
114
  - lib/rails3_assist/namespaces.rb
115
115
  - lib/rails3_assist/rspec/configure.rb
116
- - lib/rails3_assist/rspec/matchers/have_app_config.rb
117
- - lib/rails3_assist/rspec/matchers/have_special_file.rb
118
116
  - rails3_assist.gemspec
119
117
  - rails_generator.log
120
118
  - spec/fixtures.rb
@@ -1,49 +0,0 @@
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