ez 0.7.0 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -4
- data/lib/ez.rb +12 -1
- data/lib/ez/domain_modeler.rb +9 -1
- data/lib/ez/model.rb +10 -0
- data/lib/ez/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 030d63b20bce2d402a1c86b25d29347a8f054148
|
4
|
+
data.tar.gz: 9a2769fc8082c0f6e91777742d8cf17f30f4efaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8faeaa0c83a003fe4dae72571b8dba53e5dab4b1b2dd7b52615a702df0b4e592f5a5d1c2adb2431890309fd085b37f38b2b43cf616781b8f3a4fbd75b4a7871
|
7
|
+
data.tar.gz: 6374410d74cf294069485f1d09192f83cb66deb8ade16b250f6c771342af008e4f7d1861e1a95c8268fb4fd0d330f13ca89d08f671a269e1383ed66bd84dd4a3
|
data/README.md
CHANGED
@@ -25,8 +25,13 @@ gem 'ez', group: 'development'
|
|
25
25
|
|
26
26
|
* Run `rake ez:generate_yml` to generate a file named `db/models.yml`. It will have some self-documenting comments inside of it. This file is also automatically generated if you run `rake ez:tables` without an existing `models.yml` first.
|
27
27
|
* Enables instant modeling without migrations via `models.yml` and `rake ez:tables`. If things get messed up, use `rake ez:reset_tables` to drop the entire db first.
|
28
|
+
* Columns default to type `string` if none is provided and the column name doesn't have a recognized suffix.
|
29
|
+
* Column names ending in `_id` are assumed to be of type `integer`.
|
30
|
+
* Column names ending in `_at` are assumed to be of type `datetime`.
|
31
|
+
* Column names ending in `_on` are assumed to be of type `date`.
|
32
|
+
* Boolean columns are assumed to be given a default of `false`.
|
28
33
|
* Adds ActiveRecord::Base `.read` method to provide symmetry with `.create`, `.update`, and `.delete`
|
29
|
-
* Adds ActiveRecord::Base `.sample` method to choose a random row
|
34
|
+
* Adds ActiveRecord::Base `.sample` method to choose a random row.
|
30
35
|
|
31
36
|
### 4. Controller and View Enhancements
|
32
37
|
|
@@ -34,6 +39,3 @@ gem 'ez', group: 'development'
|
|
34
39
|
* Built-in view helper `<%= weather %>` and `EZ.weather` for classroom demo of a JSON API, to get quick hash and avoid gory details. (Relies on http://openweathermap.org). Default location is Evanston. Can pass location: `<%= weather('San Diego, CA') %>`. The `<%= weather %>` helper just delegates to `EZ.weather`.
|
35
40
|
* Adds controller and view helpers `current_user`, `user_signed_in?`, `sign_in_as`, and `sign_out` to avoid cookies/session hash details
|
36
41
|
* Adds view helper `map` to display a quick static map of any address. Example: `<%= map('Millenium Park, Chicago, IL') %>`
|
37
|
-
|
38
|
-
|
39
|
-
|
data/lib/ez.rb
CHANGED
@@ -6,15 +6,18 @@ require 'ez/domain_modeler.rb'
|
|
6
6
|
require 'ez/controller.rb'
|
7
7
|
require 'ez/model.rb'
|
8
8
|
require 'ez/view_helpers.rb'
|
9
|
+
require 'hirb'
|
9
10
|
|
10
11
|
module EZ
|
11
12
|
class Railtie < Rails::Railtie
|
12
13
|
rake_tasks do
|
13
14
|
load "tasks/ez_tasks.rake"
|
14
15
|
end
|
16
|
+
|
15
17
|
console do
|
16
18
|
Hirb.enable if defined?(Hirb)
|
17
19
|
|
20
|
+
|
18
21
|
I18n.enforce_available_locales = false
|
19
22
|
puts "Welcome to the Rails Console."
|
20
23
|
puts "-" * 60
|
@@ -26,7 +29,7 @@ module EZ
|
|
26
29
|
puts
|
27
30
|
puts "Models: #{models.to_sentence}"
|
28
31
|
puts
|
29
|
-
puts "HINTS:
|
32
|
+
puts "HINTS:"
|
30
33
|
puts "* Type 'exit' (or press Ctrl-D) to when you're done."
|
31
34
|
puts "* Press Ctrl-C if things seem to get stuck."
|
32
35
|
puts "* Use the up/down arrows to repeat commands."
|
@@ -42,6 +45,14 @@ module EZ
|
|
42
45
|
include EZ::ViewHelpers
|
43
46
|
end
|
44
47
|
|
48
|
+
# tables = ActiveRecord::Base.connection.tables - ['schema_migrations']
|
49
|
+
# models.each { |m| m.constantize.magic_associations }
|
50
|
+
# Rails.application.routes.draw do
|
51
|
+
# tables.each do |table_name|
|
52
|
+
# resources table_name.to_sym
|
53
|
+
# end
|
54
|
+
# end
|
55
|
+
|
45
56
|
module ::Hirb
|
46
57
|
# A Formatter object formats an output object (using Formatter.format_output) into a string based on the views defined
|
47
58
|
# for its class and/or ancestry.
|
data/lib/ez/domain_modeler.rb
CHANGED
@@ -23,7 +23,15 @@ module EZ
|
|
23
23
|
@spec[model] = []
|
24
24
|
columns.each do |column|
|
25
25
|
if column.is_a?(String) || column.is_a?(Symbol)
|
26
|
-
|
26
|
+
if column.to_s =~ /_id$/
|
27
|
+
@spec[model] << { column.to_s => 'integer' }
|
28
|
+
elsif column.to_s =~ /_at$/
|
29
|
+
@spec[model] << { column.to_s => 'datetime' }
|
30
|
+
elsif column.to_s =~ /_on$/
|
31
|
+
@spec[model] << { column.to_s => 'date' }
|
32
|
+
else
|
33
|
+
@spec[model] << { column.to_s => 'string' }
|
34
|
+
end
|
27
35
|
elsif column.is_a?(Hash) && column.keys.count == 1
|
28
36
|
@spec[model] << { column.keys.first.to_s => column.values.first.to_s }
|
29
37
|
else
|
data/lib/ez/model.rb
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
class ActiveRecord::Base
|
2
2
|
|
3
|
+
def self.magic_associations
|
4
|
+
x = self.column_names.select { |n| n.ends_with? '_id' }
|
5
|
+
|
6
|
+
x.each do |fk|
|
7
|
+
assoc_name = fk[0, fk.length - 3]
|
8
|
+
belongs_to assoc_name.to_sym
|
9
|
+
assoc_name.classify.constantize.send(:has_many, self.name.underscore.pluralize.to_sym, dependent: :destroy)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
3
13
|
def inspect
|
4
14
|
"#<#{self.class.name} #{attributes}>"
|
5
15
|
end
|
data/lib/ez/version.rb
CHANGED
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: 0.
|
4
|
+
version: 0.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Cohen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hirb
|