ez 1.2.0 → 1.3.0

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: 770aabcbe8ed373f6de55df41fea16a0c5c13497
4
- data.tar.gz: dc77713cf0d05697828c687b41a07caf037dbe75
3
+ metadata.gz: 651da5699fe33ae98d63db37c12d5d75e30fdc68
4
+ data.tar.gz: 1b3d7f79c58140be5a7c1a9403b47d930b3837cb
5
5
  SHA512:
6
- metadata.gz: f8b266eb5f7dcacd3ee45ece255653e127353e38d397b299df534f1c1d0d676a149bf7d5e1dde3e1d31561fbbad08d77b3d4902cb97ca26bbdfaf2ef57c485c9
7
- data.tar.gz: 9010ac66acb8c13eeee33edb5fb992c45d8f2ff974d4b8a8b00c3c3250949c2b26b860120b4be96f51f3df8749cb9c16192773c9335f8f9277855fd3031da313
6
+ metadata.gz: d481867135942e93bd1deadca16ccb1c6400ebb5c03adaeedfac3341bcf2354e40a205c4b238fff6aa069454169712b0b74185cb3fc71fe6df5910ef1fa68f0f
7
+ data.tar.gz: 596950b0f26338731f1d02fc3284b03a397375567ae9dcf80a8a05834adf6ac6d72f47e8036bd38d47bfde73b86895af5a2c1c9b1186b5b239c9ca30de3ed7d8
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # EZ
2
2
 
3
- **Version 1.1.3**
3
+ **Version 1.3.0**
4
4
 
5
5
  *For educational purposes only.*
6
6
 
7
- Makes domain modeling in Rails more beginner-friendly by avoiding migrations.
7
+ Easy domain modeling in Rails without migrations. Applies instant schema changes based on a file named `db/models.yml`. Diffs are determined automatically and applied to the database. Embraces Rails column naming conventions by providing happy-path default types for most columns.
8
8
 
9
- Also enhances the rails console.
9
+ Also, enhances the rails console and provides extra ActiveRecord helper methods.
10
10
 
11
11
 
12
12
  ## Usage
@@ -24,33 +24,31 @@ rake db:migrate
24
24
  to generate a skeleton `db/models.yml` that you should edit.
25
25
 
26
26
 
27
- ## Summary of Best Practices
27
+ ## Get Started
28
28
 
29
29
  1. Run `rake db:migrate` to initially generate a file named `db/models.yml`.
30
30
 
31
31
  2. Use `db/models.yml` to define your schema. Database schema changes are applied directly and triggered automatically in development mode. (`rake db:migrate` will also trigger the changes). Foreign-key indexes will be generated automatically.
32
32
 
33
- 3. You can continue to use traditional Rails migrations for any additional indexes, database constraints, etc.
33
+ 3. You can still use traditional Rails migrations for any additional indexes, database constraints, etc.
34
34
 
35
- 4. Run `rake db:migrate:preview` to do a "dry run" to see what would change based your `db/models.yml` file.
35
+ 4. Run `rake db:migrate:preview` to do a "dry run" and see what would change based your `db/models.yml` file.
36
36
 
37
37
  ## Features
38
38
 
39
39
 
40
40
  ### 1. Domain Modeling Enhancements
41
41
 
42
- * Enables **instant domain modeling without migrations** by using a file named `db/models.yml`.
43
42
  * This gem enhances `db:migrate` to incorporate the `db/models.yml` file automatically.
44
43
  * Run `rake db:migrate` to initially generate a file named `db/models.yml`. It will have some self-documenting comments inside of it.
45
- * In development mode, there's no need to ever run `rake db:migrate`! Every browser request will trigger automatic table updates.
46
- * In the rails console, 'reload!' will also trigger table updates.
47
- * If you prefer, just run `rake db:migrate` whenever you modify `db/models.yml`.
44
+ * Just run `rake db:migrate` whenever you modify `db/models.yml`.
45
+ * Starting the rails console will automatically run any pending table updates, and `reload!` will also trigger table updates while inside the console.
48
46
  * `rake db:migrate` will run any pending migrations *after* any table updates from the `db/models.yml` file.
49
47
 
50
48
 
51
49
  **Syntax Guide for `db/models.yml`**
52
50
 
53
- It's just YAML and the syntax is very simple:
51
+ It's just YML and the syntax is very simple:
54
52
 
55
53
  ```
56
54
  Book:
@@ -97,7 +95,8 @@ Author
97
95
  book_count
98
96
  ```
99
97
 
100
- Finally, you can specify default values for columns in several ways. Suppose we want to make sure that `copies_on_hand` always has the value `0` for new rows. First, the fancy way:
98
+ **Default Values**
99
+ You can specify default values for columns in several ways. Suppose we want to make sure that `copies_on_hand` always has the value `0` for new rows. First, the fancy way:
101
100
 
102
101
  ```
103
102
  Book
@@ -131,7 +130,7 @@ Author
131
130
  book_count: integer default 0
132
131
  ```
133
132
 
134
- And for the extra lazy like me, you can use parentheses:
133
+ And for the extra lazy, like me, you can just use parentheses:
135
134
 
136
135
  ```
137
136
  Book
@@ -154,17 +153,19 @@ Author
154
153
  ### 2. More Model Enhancements
155
154
 
156
155
  * Adds ActiveRecord::Base `.read` method so that models have complete *CRUD*: `.create`, `.read`, `.update`, and `.delete`. When given an integer, `.read` becomes a synonym for `.find`. When given a hash, it is a synonym for `.where`.
157
- * Adds ActiveRecord::Base `.sample` method to choose a random row.
158
- * Adds ActiveRecord::Base `[id]` method as a synonym for `.find_by(id: ...)`. Especially handy in the console, i.e. `Book[5]` instead of `Book.find_by(id: 5)` and in controllers: `Book[params[:id]]` if you don't find the double bracing too harsh to look at.
156
+ * Adds `.sample` method to choose a random row.
157
+ * Adds `.to_ez' to generate a snippet from legacy models that you can paste into models.yml.
158
+
159
159
 
160
160
 
161
161
  ### 3. Beginner-friendly "It Just Works" console
162
162
 
163
+ * Starting `rails console` will automatically apply any pending database changes, followed by any traditional migrations.
163
164
  * Solves the "no connection" message in Rails >= 4.0.1 (if you try to inspect a model without making a query first) by establishing an initial connection to the development database.
164
165
  * Shows helpful instructions when console starts, including the list of model classes found in the application.
165
166
  * Uses Hirb for table-like display. (Requires Hirb ~> 0.7.1)
166
167
  * Patches Hirb to allow nice table output for `ActiveRecord::Relation` lists (i.e. result of `.all`, `.where`) and hash-like output for single ActiveRecord objects, such as the result of `.find_by(:title => 'Apollo 13')`.
167
- * `reload!` will automatically trigger the table updates from the console.
168
+ * `reload!` will also force a schema update from the console.
168
169
 
169
170
 
170
171
  ### 4. Controller and View Enhancements
@@ -150,6 +150,7 @@ module EZ
150
150
  end
151
151
 
152
152
  @spec[model][column_name] = { type: column_type, default: default_column_value}
153
+ @spec[model][column_name][:limit] = 1024 if column_type == 'binary'
153
154
  @spec[model][column_name][:index] = true if column_name =~ /_id$/
154
155
  end
155
156
  end
@@ -86,7 +86,9 @@ module EZ
86
86
  if !assume_missing
87
87
  display_change "Adding new column '#{col_name}' as #{col_type} for model #{model_name}"
88
88
  end
89
- db.add_column(table_name, col_name.to_sym, col_type.to_sym, default: col_default) unless @dry_run
89
+ opts = { default: col_default }
90
+ opts[:limit] = data[:limit] if data[:limit]
91
+ db.add_column(table_name, col_name.to_sym, col_type.to_sym, opts) unless @dry_run
90
92
  if data[:index]
91
93
  display_change " (adding database index for '#{col_name}')"
92
94
  db.add_index table_name, col_name.to_sym unless @dry_run
@@ -104,7 +106,9 @@ module EZ
104
106
  end
105
107
 
106
108
  if (db_col.type != col_type) || (db_col.default != col_default)
107
- db.change_column(table_name, col_name.to_sym, col_type.to_sym, default: col_default) unless @dry_run
109
+ opts = { default: col_default }
110
+ opts[:limit] = data[:limit] if data[:limit]
111
+ db.change_column(table_name, col_name.to_sym, col_type.to_sym, opts) unless @dry_run
108
112
  end
109
113
  end
110
114
  end
@@ -1,3 +1,3 @@
1
1
  module EZ
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ez
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Cohen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hirb
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  version: '0'
134
134
  requirements: []
135
135
  rubyforge_project:
136
- rubygems_version: 2.4.5
136
+ rubygems_version: 2.4.2
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: For educational purposes only.