ez 0.9.0 → 0.9.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: 16c7b16c893b65e45e3261b8c9e71c7bf14da0c6
4
- data.tar.gz: 546f01535e552ed763b5487176109c1b853f872a
3
+ metadata.gz: 4bbacb9af6fd2f80c8aed574c56265d9f7e9af8c
4
+ data.tar.gz: 529687c8f65652ff1c9133d0fee355cd0204cd67
5
5
  SHA512:
6
- metadata.gz: 3212cb743e5346d611dd94a02aaa798e1bce0f5939debd000e326d810ac3349a7e9c4fabfc8051e40054ce87bac8fc69dc7642e255e7ad49512ff8f61f3415fe
7
- data.tar.gz: 06ee3f279e4d1b6385b026ba0e10b3c3b7335b6d324913072164d04b7fc6a35ffbcf80c7b081d8b7d9bb90ecff09bcc824db36b5ea3dc15c58e2ba477e0d589a
6
+ metadata.gz: c36d5521426c59b5f9fbf483bedd3cff07fc24f404556f868fffc6bc402a00d2152bbd97c70bf32f3da08f2c26b88686fe1d63c25449afc6a6ab6eb13ca9fd18
7
+ data.tar.gz: 9dd7a0f3d63031b615be468a56a45b34319ed02226314f98e132338dde81ce5b9a0bf6cb5f1d372702e582aae1e66deb69ad45075ce9b229a8b5df6a55194b9c
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 'hirb', '~> 0.7.1'
21
+ spec.add_development_dependency 'hirb', '~> 0.7.1'
22
22
 
23
23
  spec.add_development_dependency "bundler", "~> 1.3"
24
24
  spec.add_development_dependency "rake", '~> 10.0', '>= 10.0.0'
data/lib/ez.rb CHANGED
@@ -1,12 +1,14 @@
1
1
  require "ez/version"
2
- require 'ez/dispatcher.rb'
3
- require 'ez/mapper.rb'
2
+ # require 'ez/dispatcher.rb'
3
+ # require 'ez/mapper.rb'
4
+ # require 'ez/controller.rb'
5
+
4
6
  require 'ez/apis.rb'
5
7
  require 'ez/domain_modeler.rb'
6
- # require 'ez/controller.rb'
7
8
  require 'ez/model.rb'
8
9
  require 'ez/view_helpers.rb'
9
- require 'hirb'
10
+
11
+ require 'hirb' if Rails.env.development?
10
12
 
11
13
  module EZ
12
14
  class Railtie < Rails::Railtie
@@ -14,9 +16,8 @@ module EZ
14
16
  load "tasks/ez_tasks.rake"
15
17
  end
16
18
 
17
- console do
18
- Hirb.enable if Rails.env.development? && defined?(Hirb)
19
- # context.back_trace_limit = 0
19
+ console do |app|
20
+ Hirb.enable(pager: false) if Rails.env.development? && defined?(Hirb)
20
21
 
21
22
  I18n.enforce_available_locales = false
22
23
  puts "Welcome to the Rails Console."
@@ -1,26 +1,26 @@
1
- # module ActionController
2
- # class Base
1
+ module ActionController
2
+ class Base
3
3
 
4
- # helper_method :current_user
5
- # helper_method :user_signed_in?
4
+ helper_method :current_user
5
+ helper_method :user_signed_in?
6
6
 
7
- # def user_signed_in?
8
- # session[:user_id].present?
9
- # end
7
+ def user_signed_in?
8
+ session[:user_id].present?
9
+ end
10
10
 
11
- # def sign_in_as(user)
12
- # @current_user = user
13
- # session[:user_id] = user.try(:id)
14
- # user
15
- # end
11
+ def sign_in_as(user)
12
+ @current_user = user
13
+ session[:user_id] = user.try(:id)
14
+ user
15
+ end
16
16
 
17
- # def sign_out
18
- # sign_in_as nil
19
- # end
17
+ def sign_out
18
+ sign_in_as nil
19
+ end
20
20
 
21
- # def current_user(klass = User)
22
- # @current_user ||= klass.send(:find_by, id: session[:user_id])
23
- # end
21
+ def current_user(klass = User)
22
+ @current_user ||= klass.send(:find_by, id: session[:user_id])
23
+ end
24
24
 
25
- # end
26
- # end
25
+ end
26
+ end
@@ -23,7 +23,7 @@ module EZ
23
23
  @spec[model] = []
24
24
  columns.each do |column|
25
25
  if column.is_a?(String) || column.is_a?(Symbol)
26
- if column.to_s =~ /_id$/
26
+ if column.to_s =~ /_id$/ || column.to_s =~ /_count$/
27
27
  @spec[model] << { column.to_s => 'integer' }
28
28
  elsif column.to_s =~ /_at$/
29
29
  @spec[model] << { column.to_s => 'datetime' }
@@ -35,7 +35,7 @@ module EZ
35
35
  elsif column.is_a?(Hash) && column.keys.count == 1
36
36
  @spec[model] << { column.keys.first.to_s => column.values.first.to_s }
37
37
  else
38
- raise "Bad syntax."
38
+ raise "Bad syntax around `#{column.inspect}`"
39
39
  end
40
40
  end
41
41
  end
@@ -17,9 +17,18 @@ module EZ
17
17
 
18
18
  add_missing_schema
19
19
  remove_dead_schema
20
- update_schema_version
21
20
 
22
- puts "Everything is up-to-date." unless @changed
21
+ if @changed
22
+ update_schema_version
23
+ else
24
+ puts "Everything is up-to-date."
25
+ end
26
+
27
+ return @changed
28
+
29
+ rescue => e
30
+ puts e.message
31
+ false
23
32
  end
24
33
 
25
34
 
@@ -50,40 +59,50 @@ module EZ
50
59
  @changed = true
51
60
  end
52
61
 
53
- def add_missing_columns(model_name, columns)
62
+ def add_missing_columns(model_name, columns, assume_missing = false)
54
63
  table_name = model_name.tableize
55
64
  columns.each do |column|
56
65
  col_name = column.keys.first
57
66
  col_type = column[col_name]
58
- if db.column_exists?(table_name, col_name.to_sym)
67
+ if !assume_missing && db.column_exists?(table_name, col_name.to_sym)
59
68
  unless db.column_exists?(table_name, col_name.to_sym, col_type.to_sym)
60
69
  display_change "Changing column type for '#{col_name}' to #{col_type}"
61
70
  db.change_column(table_name, col_name.to_sym, col_type.to_sym)
71
+ if col_name.to_s =~ /_id$/
72
+ display_change " (adding foreign_key index for '#{col_name}')"
73
+ db.add_index table_name, col_name.to_sym
74
+ end
62
75
  end
63
76
  else
64
- display_change "Adding new column '#{col_name}' as #{col_type} for model #{model_name}"
77
+ if !assume_missing
78
+ display_change "Adding new column '#{col_name}' as #{col_type} for model #{model_name}"
79
+ end
65
80
  options = {}
66
81
  options[:default] = false if col_type.to_sym == :boolean
67
- db.add_column(table_name, col_name.to_sym, col_type.to_sym)
82
+ db.add_column(table_name, col_name.to_sym, col_type.to_sym, options)
83
+ if col_name.to_s =~ /_id$/
84
+ display_change " (adding foreign_key index for '#{col_name}')"
85
+ db.add_index table_name, col_name.to_sym
86
+ end
68
87
  end
69
88
  end
70
89
  end
71
90
 
72
91
  def add_model(model_name, columns)
73
92
  table_name = model_name.tableize
74
- display_change "Defining model #{model_name}..."
75
- ActiveRecord::Schema.define do
76
- create_table table_name do |t|
77
- columns.each do |column|
78
- name = column.keys.first
79
- col_type = column[name]
80
- options = {}
81
- options[:default] = false if col_type.to_sym == :boolean
82
- t.send(col_type, name, options)
83
- end
84
- # t.timestamps
85
- end
86
- end
93
+ display_change "Defining new table for model '#{model_name}'."
94
+ db.create_table table_name
95
+ add_missing_columns model_name, columns, true
96
+ # columns.each do |column|
97
+ # name = column.keys.first
98
+ # col_type = column[name]
99
+ # options = {}
100
+ # options[:default] = false if col_type.to_sym == :boolean
101
+ # t.send(col_type, name, options)
102
+ # end
103
+ # # t.timestamps
104
+ # end
105
+ # end
87
106
  filename = "app/models/#{model_name.underscore}.rb"
88
107
  unless Rails.env.production? || File.exists?(filename)
89
108
  display_change "Creating new model file: #{filename}"
@@ -109,7 +128,9 @@ module EZ
109
128
  end
110
129
  dead_columns = columns - spec_columns
111
130
  if dead_columns.any?
112
- display_change "Removing unused columns: #{dead_columns.to_sentence} for model #{model_name}"
131
+ dead_columns.each do |dead_column_name|
132
+ display_change "Removing unused column '#{dead_column_name}' from model '#{model_name}'"
133
+ end
113
134
  db.remove_columns(table_name, *dead_columns)
114
135
  end
115
136
  end
@@ -117,8 +138,8 @@ module EZ
117
138
  end
118
139
 
119
140
  def update_schema_version
120
- @db.initialize_schema_migrations_table
121
- @db.assume_migrated_upto_version(Time.now.strftime("%Y%m%d%H%M%S"))
141
+ db.initialize_schema_migrations_table
142
+ db.assume_migrated_upto_version(Time.now.utc.strftime("%Y%m%d%H%M%S"))
122
143
  end
123
144
 
124
145
  def remove_dead_tables
@@ -1,3 +1,3 @@
1
1
  module EZ
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
@@ -2,7 +2,9 @@ namespace :ez do
2
2
 
3
3
  desc "Generate models.yml if it doesn't exist yet."
4
4
  task :generate_yml do
5
- File.open("db/models.yml", "w") do |f|
5
+ filename = "db/models.yml"
6
+ unless File.exist?(filename)
7
+ File.open(filename, "w") do |f|
6
8
  f.puts <<-EOS
7
9
  # Example table for a typical Book model.
8
10
  #
@@ -18,26 +20,27 @@ namespace :ez do
18
20
  # You can have as many models as you want in this file.
19
21
  EOS
20
22
  end
23
+ end
21
24
  end
22
25
 
23
- desc "Reset the database schema and data from scratch."
26
+ desc "Erases all data, and builds all table schema from scratch."
24
27
  task :reset_tables => ['db:drop', :tables] do
25
28
  end
26
29
 
27
30
 
28
31
  desc "Attempts to update the database schema and model files with minimal data loss."
29
- task :tables => :environment do
32
+ task :tables => [:environment, 'db:migrate'] do
30
33
  if File.exists?('db/models.yml')
31
- EZ::DomainModeler.update_tables
32
- Rake::Task["db:schema:dump"].invoke unless Rails.env.production?
34
+ if EZ::DomainModeler.update_tables
35
+ Rake::Task["db:schema:dump"].invoke unless Rails.env.production?
36
+ end
33
37
  else
34
- emit_help_page
35
38
  Rake::Task["ez:generate_yml"].invoke
39
+ emit_help_page
36
40
  end
37
41
  end
38
42
 
39
43
  def emit_help_page
40
- puts "To get started, edit the db/models.yml file to describe your table schema."
41
-
44
+ puts "You can now edit the db/models.yml file to describe your table schema."
42
45
  end
43
46
  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: 0.9.0
4
+ version: 0.9.1
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-05-22 00:00:00.000000000 Z
11
+ date: 2014-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hirb
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: 0.7.1
20
- type: :runtime
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements: