ez 1.9.2 → 1.9.3

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: bb03b6da20e1afb0c548a1d8be3ba5efaaea9922
4
- data.tar.gz: 50f53f9864921ec57b2f7d3f70dfc75ec01ba486
3
+ metadata.gz: 7ac405024955a31e91958c4f679c63a062ec6d7e
4
+ data.tar.gz: e57f68f2e1a86b817bb592eac4d014334c512d41
5
5
  SHA512:
6
- metadata.gz: 284b6ce37d4950607c14298fbd63609fdcad4f6ea6db23f15f844a2765d1c288168aad84c92e59a9bed72ae6d500f660c1cf2aac324a8e91439d14f977e648dd
7
- data.tar.gz: fcb66139091f785ab8c0fd4567fc50b3216f97e4c82df61f325088ae1bc21afe37cef1ac824f491aa234f65af72b407f4e237c1b88fecdafee6c5e915cb93c70
6
+ metadata.gz: fa70cc7f7e368952a118ac0c162fb89ae71450589effb6be12917719ae88e2a7831168e36156ada6293b826fed36c0689c937d39b908f38ce936c8fc135bc895
7
+ data.tar.gz: a0838f2498ca2683405752c7167edeb1ba8ff2a70b8de12ef5042cc67a04a1d41c7f8bf42c3f3aad91e4774b1ba38ddfcca9f0ab82be409fc0b3399dc713e1d4
data/README.md CHANGED
@@ -1,56 +1,57 @@
1
1
  # EZ
2
2
 
3
- **Version 1.5.0.3**
3
+ Easy domain modeling in Rails without migrations.
4
+
5
+ **Version 1.9.3**
4
6
 
5
7
  *For educational purposes only.*
6
8
 
7
- Tested against Rails 5.1.1.
9
+ Tested against Rails 5.1.4.
8
10
 
9
11
  _NOTE: For Rails < 5.0, use version 1.3_.
10
12
 
11
- Easy domain modeling in Rails without migrations.
13
+ ### Highlights
12
14
 
13
- * Applies instant schema changes based on a file named `db/models.yml`.
14
- * Schema changes applied automatically when code is reloaded.
15
+ * Applies schema changes based on a file named `db/models.yml`.
16
+ * Schema changes are applied by running `rails server`, `rails console`, or `reload!` in the console.
15
17
  * Diffs are determined automatically and applied to the database.
16
18
  * Embraces Rails' column naming conventions by inferring columns types based on the name.
17
19
  * Enhances the Rails Console with customized AwesomePrint and Hirb integration
18
20
  * Adds two new ActiveRecord methods: `.sample(n = 1)` and `.none?`
19
21
 
20
22
 
21
- ## Usage
23
+ ### Installation
22
24
 
23
25
  ```ruby
24
26
  gem 'ez'
25
27
  ```
26
28
 
27
- Then start your server or console to force the initial generation of
28
- `db/models.yml` and a configuation file named `.ez`.
29
+ Start the server or console to force the initial generation of
30
+ `db/models.yml` and a hidden configuration file named `.ez`.
29
31
 
30
32
  Alternatively, you can run `rails db:migrate` to generate these files without running your app.
31
33
 
32
- ## Get Started
33
-
34
- 1. Use `db/models.yml` to define your schema. Database schema changes are applied directly and triggered automatically in development mode. (`rails db:migrate` will also trigger the changes). Foreign-key indexes will be generated automatically.
34
+ ### Usage
35
35
 
36
- 2. Run `rails db:migrate:preview` to do a "dry run" and see what would change based your `db/models.yml` file.
37
-
38
-
39
- 2. Use the `.ez` file to control functionality.
36
+ 1. Use `db/models.yml` to define your schema. Database schema changes are applied directly without affecting migrations. (`rails db:migrate` will also trigger the changes).
37
+ 2. Foreign-key indexes are generated automatically.
38
+ 3. Use `rails db:migrate:preview` to perform a "dry run" based your `db/models.yml` file.
39
+ 4. Use the `.ez` file to control functionality.
40
+ 5. See the section on Migrations below.
40
41
 
41
42
 
42
43
  |Config setting|Default|Description|
43
44
  |----|----|----|
44
45
  |models|true|Watches `models.yml` for changes. Set to `false` to turn off all functionality|
46
+ |timestamps|true|Generates `created_at` and `updated_at` columns on every model.
45
47
  |restful_routes|true|Adds `resources :<tablename>` to routes.rb for each model|
46
48
  |controllers|true|Generates one controller per model with 7 empty methods.
47
49
  |views|true|Generates the view folder for each model, with 7 empty views.
48
- |timestamps|true|Generates `created_at` and `updated_at` columns on every model.
49
50
 
50
51
 
51
52
  ## Syntax Guide for `db/models.yml`**
52
53
 
53
- It's just YAML. We recommend `text` instead of `string` columns but both are supported.
54
+ It's just YAML. We recommend `text` instead of `string` columns (because of recent SQLite3 changes) but both are supported.
54
55
 
55
56
  ```
56
57
  Book:
@@ -115,17 +116,33 @@ Author
115
116
  * Boolean columns are assumed to be given a default of `false` if not otherwise specified.
116
117
 
117
118
 
118
- ### 2. ActiveRecord Enhancements
119
+ ### ActiveRecord Enhancements
119
120
 
120
- * Adds `.sample` method to choose a random row.
121
- * Adds `.to_ez` to generate a snippet from legacy models that you can paste into models.yml.
121
+ * `.sample` method to choose a random row, or `.sample(5)` for five sample rows.
122
+ * `.none?` method on a collection: `Product.where(in_stock: true).none?`
123
+ * `.to_ez` to generate a snippet from legacy models that you can paste into models.yml.
122
124
 
123
125
 
124
- ### 3. Beginner-friendly "It Just Works" console
126
+ ### Beginner-friendly Rails Console
125
127
 
126
- * 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.
127
128
  * Shows helpful instructions when console starts, including the list of model classes found in the application.
128
- * Activates AwesomePrint in the Rails consol.
129
+ * 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.
130
+ * Activates AwesomePrint.
129
131
  * Uses Hirb for table-like display.
130
132
  * Configures Hirb to allow nice table output for `ActiveRecord::Relation` collections
131
133
  * Configures Hirb to produce hash-like output for single ActiveRecord objects
134
+
135
+
136
+ ### Migrations
137
+
138
+ This gem is expecting that the student will not use database migrations
139
+ to control the schema. However, it is ok to use a combination of migrations
140
+ and `models.yml`, but be aware of the following:
141
+
142
+ * If at least one migration file is detected, this gem will stop
143
+ removing tables that are removed from `models.yml` since
144
+ it's not possible to know if there's a migration for it or not.
145
+ * Where possible, it's best to translate a migration required for
146
+ a third-party gem (say, for Devise) into an entry in models.yml
147
+ so that everything is managed in one place.
148
+ Pull requests for integrating such features into `ez` are encouraged.
data/ez.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = []
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency 'awesome_print'
21
+ spec.add_runtime_dependency 'awesome_print', '~> 1.8', '>= 1.8.0'
22
22
  spec.add_runtime_dependency 'hirb', '~> 0.7'
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
data/lib/ez.rb CHANGED
@@ -7,33 +7,16 @@ require 'awesome_print'
7
7
 
8
8
  require 'hirb' if (Rails.env.development? || Rails.env.test?)
9
9
 
10
- module EZ
11
- module Console
12
- def reload!
13
- puts "Reloading code..."
14
- if Rails::VERSION::MAJOR < 5
15
- ActionDispatch::Reloader.cleanup!
16
- ActionDispatch::Reloader.prepare!
17
- else
18
- Rails.application.reloader.reload!
19
- end
20
-
21
- true
22
- end
23
- end
24
- end
25
-
26
-
27
10
  module EZ
28
11
 
29
12
  class Railtie < Rails::Railtie
13
+
30
14
  rake_tasks do
31
15
  load "tasks/ez_tasks.rake"
32
16
  Rake::Task["db:migrate"].enhance ["ez:tables"]
33
17
  end
34
18
 
35
19
  console do |app|
36
- # Rails::ConsoleMethods.send :prepend, EZ::Console
37
20
  AwesomePrint.irb!
38
21
 
39
22
  Hirb.enable(pager: false) if (Rails.env.development? || Rails.env.test?) && defined?(Hirb)
@@ -42,17 +25,18 @@ module EZ
42
25
 
43
26
  models = EZ::DomainModeler.models
44
27
  puts
28
+ puts "Rails Console"
29
+ puts "-" * 50
30
+ puts "* Type 'exit' (or press CTRL-D) when you're done."
31
+ puts "* Press Ctrl-C if things seem to get stuck."
32
+ puts "* Use the up/down arrows to repeat commands."
33
+ puts
45
34
  if models.any?
46
- puts "Models: #{models.to_sentence}" if models.any?
35
+ puts "Models: #{models.to_sentence}"
47
36
  puts
48
37
  puts "Use this console to create, read, update, and delete rows from the database."
49
- puts
38
+ puts "Or simply type the name of a model to see what columns it has."
50
39
  end
51
- puts "HINTS:"
52
- puts "* Type 'exit' (or press CTRL-D) when you're done."
53
- puts "* Press Ctrl-C if things seem to get stuck."
54
- puts "* Use the up/down arrows to repeat commands."
55
- puts "* Type the name of a Model to see what columns it has." if models.any?
56
40
  puts
57
41
  end
58
42
 
@@ -21,7 +21,14 @@ module EZ
21
21
  end
22
22
 
23
23
  def self.filename
24
- File.join(Rails.root, '.ez')
24
+ @filename = begin
25
+ n = File.join(Rails.root, '.ez')
26
+ if File.exist?(n)
27
+ n
28
+ else
29
+ File.expand_path('~/.ez')
30
+ end
31
+ end
25
32
  end
26
33
 
27
34
  def self.configuration
@@ -21,25 +21,26 @@ module EZ
21
21
  end
22
22
 
23
23
  def self.automigrate
24
- if EZ::Config.models?
24
+ return unless EZ::Config.models?
25
+
26
+ begin
25
27
  models_yml = File.join(Rails.root, 'db', 'models.yml')
26
28
  schema_rb = File.join(Rails.root, 'db', 'schema.rb')
27
29
 
28
30
  EZ::DomainModeler.generate_models_yml unless File.exist?(models_yml)
29
31
 
30
32
  if !File.exist?(schema_rb) || (File.mtime(schema_rb) < File.mtime(models_yml))
31
- puts "Updating your app based on models.yml..."
32
33
  old_level = ActiveRecord::Base.logger.level
33
- ActiveRecord::Base.logger.level = Logger::WARN
34
34
 
35
+ ActiveRecord::Base.logger.level = Logger::WARN
35
36
  EZ::DomainModeler.update_tables
36
37
  dump_schema if (Rails.env.development? || Rails.env.test?)
37
- puts "Models: #{EZ::DomainModeler.models.to_sentence}"
38
+
38
39
  ActiveRecord::Base.logger.level = old_level
40
+ EZ::RailsUpdater.update!
39
41
  end
40
-
41
- EZ::RailsUpdater.update!
42
-
42
+ rescue => e
43
+ puts "Exception: #{e}"
43
44
  end
44
45
  end
45
46
 
@@ -68,37 +69,36 @@ module EZ
68
69
  unless File.exist?(filename)
69
70
  File.open(filename, "w") do |f|
70
71
  f.puts <<-EOS
71
- # Example table for a typical Book model.
72
+ # Example:
72
73
  #
73
74
  # Book
74
75
  # title: text
75
76
  # author_id: integer
76
- # price: integer
77
77
  # summary: text
78
+ # price: integer
78
79
  # hardcover: boolean
79
80
  #
81
+ #
80
82
  # Indent consistently! Follow the above syntax exactly.
81
- # Typical column choices are: string, text, integer, boolean, date, time, and datetime.
82
83
  #
83
84
  #
84
- # About Default Values
85
- # ----------------------------------------------------
86
- # Default column values can be specified like this:
87
- # price: integer(0)
88
85
  #
89
- # If not specified, Boolean columns always default to false.
86
+ # Column choices are: text, integer, boolean, datetime, and float.
90
87
  #
91
88
  #
92
- # Convention-Based Defaults:
93
- # ----------------------------------------------------
94
- # You can omit the column type if it's a string, or if it's obviously an integer column:
89
+ # Default values can be specified like this:
95
90
  #
91
+ # price: integer(0)
92
+ #
93
+ # If not specified, Boolean columns always default to false.
94
+ #
95
+ # You can omit the column type if it's a text column or obviously an integer column:
96
96
  #
97
97
  # Book
98
98
  # title
99
99
  # author_id
100
+ # summary
100
101
  # price: integer
101
- # summary: text
102
102
  # hardcover: boolean
103
103
  #
104
104
  # Complete details are in the README file online.
@@ -143,9 +143,9 @@ module EZ
143
143
  @spec = YAML.load(s)
144
144
  parse_model_spec
145
145
 
146
- puts "@spec:"
147
- puts @spec.inspect
148
- puts "-" * 10
146
+ # puts "@spec:"
147
+ # puts @spec.inspect
148
+ # puts "-" * 10
149
149
  end
150
150
 
151
151
  def load_model_specs(filename = "db/models.yml")
@@ -173,7 +173,7 @@ module EZ
173
173
  columns['created_at'] = 'datetime'
174
174
  columns['updated_at'] = 'datetime'
175
175
  end
176
-
176
+
177
177
  columns.each do |column_name, column_type|
178
178
  interpret_column_spec column_name, column_type, model
179
179
  end
@@ -192,7 +192,7 @@ module EZ
192
192
  elsif column_name =~ /\?$/
193
193
  'boolean'
194
194
  else
195
- 'string'
195
+ 'text'
196
196
  end
197
197
  end
198
198
 
@@ -31,7 +31,7 @@ module EZ
31
31
  filename = File.join(Rails.root, 'app', 'controllers', "#{controller}_controller.rb")
32
32
  if !File.exist?(filename)
33
33
  File.open(filename, "w:utf-8") do |file|
34
- file.puts "class #{controller.classify} < ApplicationController"
34
+ file.puts "class #{"#{controller}_controller".classify} < ApplicationController"
35
35
  METHODS.each do |method|
36
36
  file.puts
37
37
  file.puts " def #{method}"
@@ -1,3 +1,3 @@
1
1
  module EZ
2
- VERSION = "1.9.2"
2
+ VERSION = "1.9.3"
3
3
  end
@@ -1,7 +1,3 @@
1
- # Rake::Task["db:migrate"].enhance do
2
- # Rake::Task["ez:resources"].invoke
3
- # end
4
-
5
1
  namespace :db do
6
2
 
7
3
  namespace :migrate do
@@ -22,7 +18,7 @@ namespace :ez do
22
18
 
23
19
  desc "Generate models.yml if it doesn't exist yet."
24
20
  task :generate_yml do
25
- EZ::DomainModeler.generate_yml
21
+ EZ::DomainModeler.generate_models_yml
26
22
  end
27
23
 
28
24
  desc "Erases all data, and builds all table schema from scratch."
metadata CHANGED
@@ -1,29 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ez
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Cohen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-03 00:00:00.000000000 Z
11
+ date: 2017-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
17
20
  - - ">="
18
21
  - !ruby/object:Gem::Version
19
- version: '0'
22
+ version: 1.8.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.8'
24
30
  - - ">="
25
31
  - !ruby/object:Gem::Version
26
- version: '0'
32
+ version: 1.8.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: hirb
29
35
  requirement: !ruby/object:Gem::Requirement