sugar-high 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,6 +1,6 @@
1
1
  # Sugar high!
2
2
 
3
- Named in honor of the bailouts after 2008 crisis which led to a temporary 'sugar-high' in the markets. Inspired by the 'zucker' project.
3
+ Inspired by the 'zucker' project.
4
4
 
5
5
  ## Install
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.6
1
+ 0.3.7
@@ -76,6 +76,11 @@ class String
76
76
  def valid_file_command?
77
77
  self.to_sym.valid_file_command?
78
78
  end
79
+
80
+ def new_file
81
+ return File.new(self) if File.exist?(self)
82
+ File.open(self, 'w')
83
+ end
79
84
  end
80
85
 
81
86
  class Symbol
@@ -135,22 +135,28 @@ class File
135
135
  else
136
136
  [ :after, options[:after] ]
137
137
  end
138
-
139
138
 
140
139
  marker = Insert.get_marker marker
141
-
142
- return nil if !(File.new(file.path).read =~ /#{Regexp.escape(marker.to_s)}/)
140
+ marker_found = (File.new(file.path).read =~ /#{marker}/)
141
+ return nil if !marker_found
143
142
 
144
143
  Mutate.mutate_file file.path, marker, place do
145
144
  content
146
145
  end
147
146
  end
148
147
 
148
+ module EscapedString
149
+ def escaped?
150
+ true
151
+ end
152
+ end
153
+
149
154
  module Insert
150
155
  def self.get_marker marker
156
+ return marker if marker.respond_to?(:escaped?) && marker.escaped?
151
157
  marker = case marker
152
158
  when String
153
- Regexp.escape(marker)
159
+ Regexp.escape(marker).extend(EscapedString)
154
160
  when Regexp
155
161
  marker.source
156
162
  end
@@ -179,8 +185,12 @@ class File
179
185
  File.open(file, 'wb') { |file| file.write(content) }
180
186
  return
181
187
  end
182
-
183
- replace_in_file file, /(#{Regexp.escape(marker.to_s)})/mi do |match|
188
+
189
+ marker = Insert.get_marker marker
190
+ marker_found = (File.new(file.path).read =~ /#{marker}/)
191
+ return nil if !marker_found
192
+
193
+ replace_in_file file, /(#{marker})/mi do |match|
184
194
  place == :after ? "#{match}\n #{yield}" : "#{yield}\n #{match}"
185
195
  end
186
196
  end
@@ -0,0 +1,8 @@
1
+ s = %q{content: Fixtures::Application.routes.draw do
2
+ resources :users}
3
+
4
+ marker = 'routes.draw do'
5
+
6
+ puts "esc marker: #{Regexp.escape(marker.to_s)}"
7
+
8
+ puts (s =~ /#{Regexp.escape(marker.to_s)}/)
@@ -0,0 +1,63 @@
1
+ Fixtures::Application.routes.draw do
2
+
3
+
4
+
5
+ resources :users
6
+
7
+ # The priority is based upon order of creation:
8
+ # first created -> highest priority.
9
+
10
+ # Sample of regular route:
11
+ # match 'products/:id' => 'catalog#view'
12
+ # Keep in mind you can assign values other than :controller and :action
13
+
14
+ # Sample of named route:
15
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
16
+ # This route can be invoked with purchase_url(:id => product.id)
17
+
18
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
19
+ # resources :products
20
+
21
+ # Sample resource route with options:
22
+ # resources :products do
23
+ # member do
24
+ # get 'short'
25
+ # post 'toggle'
26
+ # end
27
+ #
28
+ # collection do
29
+ # get 'sold'
30
+ # end
31
+ # end
32
+
33
+ # Sample resource route with sub-resources:
34
+ # resources :products do
35
+ # resources :comments, :sales
36
+ # resource :seller
37
+ # end
38
+
39
+ # Sample resource route with more complex sub-resources
40
+ # resources :products do
41
+ # resources :comments
42
+ # resources :sales do
43
+ # get 'recent', :on => :collection
44
+ # end
45
+ # end
46
+
47
+ # Sample resource route within a namespace:
48
+ # namespace :admin do
49
+ # # Directs /admin/products/* to Admin::ProductsController
50
+ # # (app/controllers/admin/products_controller.rb)
51
+ # resources :products
52
+ # end
53
+
54
+ # You can have the root of your site routed with "root"
55
+ # just remember to delete public/index.html.
56
+ # root :to => "welcome#index"
57
+
58
+ # See how all your routes lay out with "rake routes"
59
+
60
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
61
+ # Note: This route will make all actions in every controller accessible via GET requests.
62
+ # match ':controller(/:action(/:id(.:format)))'
63
+ end
@@ -6,7 +6,8 @@ describe "SugarHigh::File" do
6
6
  let(:non_empty_file) { fixture_file 'non-empty.txt'}
7
7
  let(:class_file) { fixture_file 'class_file.rb'}
8
8
  let(:replace_file) { fixture_file 'file.txt' }
9
- let(:file_to_delete) { fixture_file 'file_to_delete.txt' }
9
+ let(:file_to_delete) { fixture_file 'file_to_delete.txt' }
10
+ let(:routes_file) { fixture_file 'routes_file.rb' }
10
11
 
11
12
  after do
12
13
  File.overwrite class_file do
@@ -292,5 +293,14 @@ end}
292
293
  File.read(class_file).should match /end\s+# Hello\s+end/
293
294
  File.remove_content_from class_file, :content => ' # Hello'
294
295
  end
296
+
297
+ it "should insert devise routes statement as first route statement" do
298
+ File.insert_into routes_file, :after => 'routes.draw do' do
299
+ 'devise :users'
300
+ end
301
+ puts File.read(routes_file)
302
+ File.read(routes_file).should match /routes.draw\s+do\s+devise :users/
303
+ File.remove_content_from routes_file, :content => 'devise :users'
304
+ end
295
305
  end
296
306
  end
@@ -123,6 +123,21 @@ describe "SugarHigh" do
123
123
  Dir.glob(expr).file_names('txt').should include('empty', 'non-empty')
124
124
  end
125
125
  end
126
- end
126
+ end
127
+
128
+ describe "String" do
129
+ describe '#new_file' do
130
+ let(:replace_file) { fixture_file 'file.txt' }
131
+
132
+ after :each do
133
+ File.delete replace_file if File.file?(replace_file)
134
+ end
135
+
136
+ it "should return all file names of an array of paths to files" do
137
+ replace_file.new_file
138
+ File.exist?(replace_file).should be_true
139
+ end
140
+ end
141
+ end
127
142
  end
128
143
 
data/sugar-high.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.3.6"
8
+ s.version = "0.3.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"]
@@ -42,9 +42,11 @@ Gem::Specification.new do |s|
42
42
  "lib/sugar-high/rspec/configure.rb",
43
43
  "lib/sugar-high/rspec/matchers/have_aliases.rb",
44
44
  "lib/sugar-high/string.rb",
45
+ "sandbox/test_routes_mutate.rb",
45
46
  "spec/fixtures/class_file.rb",
46
47
  "spec/fixtures/empty.txt",
47
48
  "spec/fixtures/non-empty.txt",
49
+ "spec/fixtures/routes_file.rb",
48
50
  "spec/fixtures/search_file.txt",
49
51
  "spec/spec_helper.rb",
50
52
  "spec/sugar-high/alias_spec.rb",
@@ -69,6 +71,7 @@ Gem::Specification.new do |s|
69
71
  s.summary = %q{Ruby convenience sugar packs!}
70
72
  s.test_files = [
71
73
  "spec/fixtures/class_file.rb",
74
+ "spec/fixtures/routes_file.rb",
72
75
  "spec/spec_helper.rb",
73
76
  "spec/sugar-high/alias_spec.rb",
74
77
  "spec/sugar-high/arguments_spec.rb",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugar-high
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
17
- requirement: &2154945320 !ruby/object:Gem::Requirement
17
+ requirement: &2158375700 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 2.4.1
23
23
  type: :development
24
24
  prerelease: false
25
- version_requirements: *2154945320
25
+ version_requirements: *2158375700
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: require_all
28
- requirement: &2154944800 !ruby/object:Gem::Requirement
28
+ requirement: &2158375100 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 1.2.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2154944800
36
+ version_requirements: *2158375100
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: mocha
39
- requirement: &2154944120 !ruby/object:Gem::Requirement
39
+ requirement: &2158374580 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,7 +44,7 @@ dependencies:
44
44
  version: 0.9.8
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *2154944120
47
+ version_requirements: *2158374580
48
48
  description: More Ruby sugar - inspired by the 'zuker' project
49
49
  email: kmandrup@gmail.com
50
50
  executables: []
@@ -78,9 +78,11 @@ files:
78
78
  - lib/sugar-high/rspec/configure.rb
79
79
  - lib/sugar-high/rspec/matchers/have_aliases.rb
80
80
  - lib/sugar-high/string.rb
81
+ - sandbox/test_routes_mutate.rb
81
82
  - spec/fixtures/class_file.rb
82
83
  - spec/fixtures/empty.txt
83
84
  - spec/fixtures/non-empty.txt
85
+ - spec/fixtures/routes_file.rb
84
86
  - spec/fixtures/search_file.txt
85
87
  - spec/spec_helper.rb
86
88
  - spec/sugar-high/alias_spec.rb
@@ -125,6 +127,7 @@ specification_version: 3
125
127
  summary: Ruby convenience sugar packs!
126
128
  test_files:
127
129
  - spec/fixtures/class_file.rb
130
+ - spec/fixtures/routes_file.rb
128
131
  - spec/spec_helper.rb
129
132
  - spec/sugar-high/alias_spec.rb
130
133
  - spec/sugar-high/arguments_spec.rb