scenic 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a764a03ca4024bdd13deea0c9a18251b91e664e1
4
- data.tar.gz: be3c32867baca5e7c3887372d25f3a40d1f93dd3
3
+ metadata.gz: 12cc4c93551c150598dd616a1174245760aac19e
4
+ data.tar.gz: b108ebf2b5d3b3e4d2d3e70410233773ce09481d
5
5
  SHA512:
6
- metadata.gz: 9afab6aedec2d7167737a4879e8a7f79f3511dc10d0d0b980790cd827035ccec6697c0fb61c401305190f353e72d21543ad2699552ea5eafe7ae0e33877bff68
7
- data.tar.gz: da72e6957c563eca8c01601ac99a1876d7b48f1767d55d327b5c60ae8acf53853cda13a4b6b1c8d99af72ec9864fa2d90425afc71e41cd5bdb481cebbe251cc9
6
+ metadata.gz: be0ede1893de56e1b53309b4cb8bdb035e9e03b573252390214a448c85a6d8bb6e9cd3b0f85a3b0bb8438442497dd24c29a959e6429e74e7fe9e0a272cefc09d
7
+ data.tar.gz: c4753f41f39bb769246e6793e426a63e899bc0873f74b685dd6644755a6fabc4e6ab4edfe996bd1c631e3735d44c4ab5826daa73b73073191a73091a6a2867e0
data/NEWS.md CHANGED
@@ -1,8 +1,6 @@
1
- * Teach view generator to update existing views [683361d](https://github.com/thoughtbot/scenic/commit/683361d59410f46aba508a3ceb850161dd0be027)
2
-
3
-
4
- *Caleb Thompson*
1
+ New in 0.2.1
2
+ * View generator will now create `db/views` directory if necessary
5
3
 
4
+ New in 0.2.0
5
+ * Teach view generator to update existing views [683361d](https://github.com/thoughtbot/scenic/commit/683361d59410f46aba508a3ceb850161dd0be027)
6
6
  * Raise an error if view definition is empty. [PR #38](https://github.com/thoughtbot/scenic/issues/38)
7
-
8
- *Caleb Thompson*
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ![Boston cityscape - it's scenic](http://www.california-tour.com/blog/wp-content/uploads/2011/11/skyline-boats-shutterstock-superreduced.jpg)
4
4
 
5
+ **Scenic (v0.2.0) is in an early stage of development. While it hasn't been
6
+ tested in an actual application, we are relatively confident in its readiness
7
+ and value, and stand ready to help resolve any issues it may have**
8
+
5
9
  ## Description
6
10
 
7
11
  Scenic adds methods to ActiveRecord::Migration to create and manage database
@@ -16,7 +20,7 @@ get full SQL syntax highlighting support in the editor of your choice.
16
20
  ## Great, how do I create a view?
17
21
 
18
22
  You've got this great idea for a view you'd like to call `searches`. Create a
19
- definition file at `db/views/searches_v1.sql` which contains the query you'd
23
+ definition file at `db/views/searches_v01.sql` which contains the query you'd
20
24
  like to build your view with. Perhaps that looks something like this:
21
25
 
22
26
  ```sql
@@ -49,7 +53,7 @@ reversible and it will be dumped into your `schema.rb` file.
49
53
 
50
54
  ## Cool, but what if I need to change that view?
51
55
 
52
- Add the new query to `db/views/searches_v2.sql` and generate a new migration with
56
+ Add the new query to `db/views/searches_v02.sql` and generate a new migration with
53
57
  the following `change` method:
54
58
 
55
59
  ```ruby
@@ -77,6 +81,44 @@ class Search < ActiveRecord::Base
77
81
  end
78
82
  ```
79
83
 
84
+ ## Can you make this easier?
85
+
86
+ Sure thing. How about some generators?
87
+
88
+ ### Model generator
89
+
90
+ The `scenic:model` generator builds you a model, view, and migration from
91
+ scratch. `db/views/[model]_v01.sql` wil be an empty file that you fill in only
92
+ the [query] portion of the view with.
93
+
94
+ [query]: http://www.postgresql.org/docs/current/static/sql-createview.html
95
+
96
+ ```
97
+ $ rails generate scenic:model search
98
+ create app/models/search.rb
99
+ create db/views/searches_v01.sql
100
+ create db/migrate/[TIMESTAMP]_create_searches.rb
101
+ ```
102
+
103
+ ### View generator
104
+
105
+ The `scenic:view` generator is functionally equivalent to `scenic:model` except
106
+ that it doesn't create the model. Convenient.
107
+
108
+ ```
109
+ $ rails generate scenic:view search
110
+ create db/views/searches_v01.sql
111
+ create db/migrate/[TIMESTAMP]_create_searches.rb
112
+ ```
113
+
114
+ Subsequent invocations will create updated view versions and update migrations:
115
+
116
+ ```
117
+ rails generate scenic:view search
118
+ create db/views/searches_v02.sql
119
+ create db/migrate/[TIMESTAMP]_update_searches_to_version_2.rb
120
+ ```
121
+
80
122
  ## I don't need this view anymore. Make it go away.
81
123
 
82
124
  We give you `drop_view` too:
@@ -86,11 +128,3 @@ def change
86
128
  drop_view :searches, revert_to_version: 2
87
129
  end
88
130
  ```
89
-
90
- ## Can you make this easier?
91
-
92
- Yeah, we're working on it. We're going to provide some generators that will take
93
- some of the busy work of file creation away. We'll create the SQL file, the
94
- migration, and optionally the model for you.
95
-
96
- Check out the issue tracker for our other plans.
@@ -7,6 +7,12 @@ module Scenic
7
7
  include Rails::Generators::Migration
8
8
  source_root File.expand_path("../templates", __FILE__)
9
9
 
10
+ def create_views_directory
11
+ unless views_directory_path.exist?
12
+ empty_directory(views_directory_path)
13
+ end
14
+ end
15
+
10
16
  def create_view_definition
11
17
  create_file definition.path
12
18
  end
@@ -32,7 +38,7 @@ module Scenic
32
38
  no_tasks do
33
39
  def previous_version
34
40
  @previous_version ||=
35
- Dir.entries(Rails.root.join(*%w(db views)))
41
+ Dir.entries(views_directory_path)
36
42
  .map { |name| version_regex.match(name).try(:[], "version").to_i }
37
43
  .max
38
44
  end
@@ -52,6 +58,10 @@ module Scenic
52
58
 
53
59
  private
54
60
 
61
+ def views_directory_path
62
+ @views_directory_path ||= Rails.root.join(*%w(db views))
63
+ end
64
+
55
65
  def version_regex
56
66
  /\A#{plural_file_name}_v(?<version>\d+)\.sql\z/
57
67
  end
@@ -1,3 +1,3 @@
1
1
  module Scenic
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "ammeter/rspec/generator/example.rb"
2
2
  require "ammeter/rspec/generator/matchers.rb"
3
+ require "ammeter/init"
3
4
 
4
5
  RSpec.configure do |config|
5
6
  config.before(:example, :generator) do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scenic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Derek Prior
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-11 00:00:00.000000000 Z
12
+ date: 2015-01-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -186,7 +186,6 @@ files:
186
186
  - spec/dummy/config/environments/development.rb
187
187
  - spec/dummy/config/environments/test.rb
188
188
  - spec/dummy/db/migrate/.keep
189
- - spec/dummy/db/views/.keep
190
189
  - spec/generators/scenic/model/model_generator_spec.rb
191
190
  - spec/generators/scenic/view/view_generator_spec.rb
192
191
  - spec/integration/revert_spec.rb
@@ -220,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
219
  version: '0'
221
220
  requirements: []
222
221
  rubyforge_project:
223
- rubygems_version: 2.2.2
222
+ rubygems_version: 2.4.5
224
223
  signing_key:
225
224
  specification_version: 4
226
225
  summary: Support for database views in Rails migrations
@@ -238,7 +237,6 @@ test_files:
238
237
  - spec/dummy/config/environments/development.rb
239
238
  - spec/dummy/config/environments/test.rb
240
239
  - spec/dummy/db/migrate/.keep
241
- - spec/dummy/db/views/.keep
242
240
  - spec/generators/scenic/model/model_generator_spec.rb
243
241
  - spec/generators/scenic/view/view_generator_spec.rb
244
242
  - spec/integration/revert_spec.rb
File without changes