localtower 0.1.3 → 0.1.4

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: 4b8f7b57103f27ce72779a5e2bb1be912c1f8b9f
4
- data.tar.gz: 016a726c3005c76ac0525f4fd4a75bd4348e3faa
3
+ metadata.gz: 3dbaecae36ac179d94fd480b4faad357771092a3
4
+ data.tar.gz: 2e1e8e8647f88a275cce4a6ec5c1e0d39d807d79
5
5
  SHA512:
6
- metadata.gz: bf534cfffb2fb0b6607b83c07afda5b416cff8a4264d6f917782337fdeeb3e3af8188e525ae670002ff87daee73db1f8915034286e671fb0437fe42e44797a56
7
- data.tar.gz: ec8fe979cb774707fbc0636307c090b7ceba5838ea94ee7223bd478c0bca4bcb9fac3caf703930c0efea43d490f5c906024bd156cc8fca617695f2e698025417
6
+ metadata.gz: 01fb89e48a72b11ba7e1e1c1dad80853a5bf4271ca10b1d97bbd8ec0040370f80f87a180c6d12704cd84e8842f32aba5415c43c26c3790004f4e0a7be9c77248
7
+ data.tar.gz: 12567d4a250b0c3a7ca9597e0926c601ff3b66e378e070000506be6a7054ed37151cb55d9f4562b25fb09fb410ab39f3aeeadc9e13484b747ba337ab103725fb
data/README.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Localtower
2
2
 
3
+ ### See the schema
4
+ ![Schema](https://raw.githubusercontent.com/damln/localtower/master/public/1_schema.png)
5
+
6
+ ### Create a model
7
+ ![Models](https://raw.githubusercontent.com/damln/localtower/master/public/2_models_1.png)
8
+
9
+ ### Create a many to many relation
10
+ ![Relations](https://raw.githubusercontent.com/damln/localtower/master/public/3_relations.png)
11
+
12
+ ### Create a migration
13
+ ![Migrations](https://raw.githubusercontent.com/damln/localtower/master/public/4_migrations.png)
3
14
 
4
15
 
5
16
  ## INSTALL
@@ -14,6 +14,7 @@
14
14
  <thead>
15
15
  <th>Action</th>
16
16
  <th>Model</th>
17
+ <th>Belongs To</th>
17
18
  <th>Column</th>
18
19
  <th>New Column Name</th>
19
20
  <th>Type</th>
@@ -32,6 +33,10 @@
32
33
  <%= select_tag "migrations[migrations][][table_name]", options_for_select(Localtower::Tools.models.collect {|p| [ p, p.table_name ] }), class: "form-control" %>
33
34
  </td>
34
35
 
36
+ <td>
37
+ <%= select_tag "migrations[migrations][][belongs_to]", options_for_select(Localtower::Tools.models.collect {|p| [ p, p.table_name ] }), class: "form-control" %>
38
+ </td>
39
+
35
40
  <td class="text-center">
36
41
  <input type="text" name="migrations[migrations][][column]" class="form-control" data-selector="column_text">
37
42
 
@@ -80,6 +80,27 @@ module Localtower
80
80
  inject_in_migration(file, line)
81
81
  end
82
82
 
83
+ def migration_belongs_to(data)
84
+ file = data["last_migration_file"]
85
+
86
+ line = " add_reference :#{data["table_name"]}, :#{data["column"]}, foreign_key: true, index: true\n"
87
+
88
+ inject_in_migration(file, line)
89
+
90
+ file = "#{Rails.root}/app/models/#{data["table_name"].underscore.singularize}.rb"
91
+ after = /class #{data["table_name"].camelize.singularize} < ApplicationRecord\n/
92
+ line1 = " belongs_to :#{data["column"].singularize.underscore}\n"
93
+
94
+ ::Localtower::Tools::ThorTools.new.insert_after_word(file, after, line1)
95
+
96
+
97
+ file = "#{Rails.root}/app/models/#{data["column"].underscore.singularize}.rb"
98
+ after = /class #{data["column"].camelize.singularize} < ApplicationRecord\n/
99
+ line1 = " has_many :#{data["table_name"].pluralize.underscore}\n"
100
+
101
+ ::Localtower::Tools::ThorTools.new.insert_after_word(file, after, line1)
102
+ end
103
+
83
104
  def migration_create_table(data)
84
105
  file = data["last_migration_file"]
85
106
 
@@ -105,13 +126,14 @@ module Localtower
105
126
  end
106
127
 
107
128
  class Migration
108
- TYPES = %w(string datetime text integer float json jsonb decimal binary boolean array references).freeze
129
+ TYPES = %w(string datetime text uuid integer float json jsonb decimal binary boolean array references).freeze
109
130
  ACTIONS = [
110
131
  'add_column',
111
132
  'remove_column',
112
133
  'rename_column',
113
134
  'change_column_type',
114
135
  'add_index_to_column',
136
+ 'belongs_to',
115
137
  # 'add_index_to_column_combined',
116
138
  'remove_index_to_column',
117
139
  # 'create_table',
@@ -161,6 +183,7 @@ end
161
183
  'rename_column' => -> { rename_column(action_line) },
162
184
  'change_column_type' => -> { change_column_type(action_line) },
163
185
  'add_index_to_column' => -> { add_index_to_column(action_line) },
186
+ 'belongs_to' => -> { belongs_to(action_line) },
164
187
  # 'add_index_to_column_combined' => -> { add_index_to_column_combined(action_line) },
165
188
  'remove_index_to_column' => -> { remove_index_to_column(action_line) },
166
189
  'create_table' => -> { create_table(action_line) },
@@ -229,6 +252,17 @@ end
229
252
  @thor.migration_add_index_to_column(data)
230
253
  end
231
254
 
255
+ def belongs_to(data)
256
+ if not data["table_name"].present? and data["belongs_to"].present?
257
+ return nil
258
+ end
259
+
260
+ data["column"] = data["belongs_to"].underscore.singularize
261
+ data['column_type'] = "references"
262
+
263
+ @thor.migration_belongs_to(data)
264
+ end
265
+
232
266
  # def add_index_to_column_combined(data)
233
267
  # @thor.migration_add_index_to_column_combined(data)
234
268
  # end
@@ -26,7 +26,7 @@ module Localtower
26
26
 
27
27
  if @opts['run_migrate']
28
28
  ::Localtower::Tools.perform_cmd('rake db:migrate', false)
29
- ::Localtower::Tools.perform_cmd('rake db:migrate RAILS_ENV=test', false)
29
+ # ::Localtower::Tools.perform_cmd('rake db:migrate RAILS_ENV=test', false)
30
30
  end
31
31
 
32
32
  self
@@ -13,7 +13,7 @@ module Localtower
13
13
 
14
14
  class << self
15
15
  def force_reload!
16
- app_folders = Dir["#{Rails.root}/app/**/*.rb"]
16
+ app_folders = Dir["#{Rails.root}/app/models/**/*.rb"]
17
17
  lib_folders = Dir["#{Rails.root}/lib/**/*.rb"]
18
18
 
19
19
  all_folders = (app_folders + lib_folders).flatten
@@ -25,15 +25,19 @@ module Localtower
25
25
  end
26
26
 
27
27
  def models
28
+ self.force_reload!
29
+
30
+ klass_parent = defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base
31
+
28
32
  Dir["#{Rails.root}/app/models/\*.rb"].map { |f|
29
33
  File.basename(f, '.*').camelize.constantize
30
- }.select { |klass| klass != ApplicationRecord }
34
+ }.select { |klass| klass != klass_parent }.select { |klass| klass.respond_to?(:columns_hash) }
31
35
  end
32
36
 
33
37
  def models_presented
38
+ self.force_reload!
39
+
34
40
  list = []
35
- files = Dir["#{Rails.root}/app/models/**/*.*"]
36
- files.each { |file| ActiveSupport::Dependencies.require_or_load(file) }
37
41
 
38
42
  self.models.each do |model|
39
43
  attributes_list = []
@@ -120,13 +124,23 @@ module Localtower
120
124
  self.perform_cmd("rails g migration #{str}", false)
121
125
 
122
126
  if not standalone
127
+ # self.perform_raw_cmd("z rake #{cmd_str}", standalone)
123
128
  self.perform_cmd('rake db:migrate')
124
- self.perform_cmd('rake db:migrate RAILS_ENV=test')
129
+ # self.perform_cmd('rake db:migrate RAILS_ENV=test')
125
130
  end
126
131
  end
127
132
 
128
133
  def perform_cmd(cmd_str, standalone = true)
129
134
  self.perform_raw_cmd("bundle exec #{cmd_str}", standalone)
135
+
136
+ # if cmd_str["rake"]
137
+ # self.perform_raw_cmd("zeus #{cmd_str}", standalone)
138
+ # elsif cmd_str["rails g migration"]
139
+ # cmd = cmd_str.split("rails g migration")[1]
140
+ # self.perform_raw_cmd("zeus generate migration #{cmd}", standalone)
141
+ # else
142
+ # self.perform_raw_cmd("bundle exec #{cmd_str}", standalone)
143
+ # end
130
144
  end
131
145
 
132
146
  def perform_raw_cmd(cmd_str, standalone = false, root_dir = false)
@@ -1,3 +1,3 @@
1
1
  module Localtower
2
- VERSION = '0.1.3'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
data/public/js/app.js CHANGED
@@ -40,6 +40,7 @@ MainApp = {
40
40
  var action_input = $tr.find("[name='migrations[migrations][][action]']");
41
41
 
42
42
  var table_name_input = $tr.find("[name='migrations[migrations][][table_name]']");
43
+ var belongs_to_input = $tr.find("[name='migrations[migrations][][belongs_to]']");
43
44
 
44
45
  var column_text_input = $tr.find("[data-selector='column_text']");
45
46
  var column_input = $tr.find("[data-selector='column_list']");
@@ -52,7 +53,7 @@ MainApp = {
52
53
  var action = action_input.val();
53
54
 
54
55
 
55
- $.each([column_text_input, column_input, new_column_name_input, column_type_input, index_input, nullable_input], function(i, el) {
56
+ $.each([belongs_to_input, column_text_input, column_input, new_column_name_input, column_type_input, index_input, nullable_input], function(i, el) {
56
57
  el.hide();
57
58
  });
58
59
 
@@ -62,6 +63,7 @@ MainApp = {
62
63
  remove_column: [column_input],
63
64
  rename_column: [column_input, new_column_name_input],
64
65
  change_column_type: [column_input, column_type_input],
66
+ belongs_to: [belongs_to_input],
65
67
  add_index_to_column: [column_input],
66
68
  remove_index_to_column: [column_input],
67
69
  drop_table: [],
@@ -4,7 +4,7 @@ PATH
4
4
  localtower (0.1.3)
5
5
  active_link_to
6
6
  pg
7
- rails (>= 5.0.1)
7
+ rails (>= 4.2.0)
8
8
  rubyzip
9
9
  sqlite3
10
10
  thor