effective_developer 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a6c65c15c6025e2d82b06fd85be1dedf34a3b23
4
- data.tar.gz: 9fad65447322c44cac74cfa244304877b2dd468d
3
+ metadata.gz: 40d2df5dba437c7112b719f129fb5304d88fd3b5
4
+ data.tar.gz: f485802d6fbf8ae8ae1375478650b20d56e381aa
5
5
  SHA512:
6
- metadata.gz: db915fe8e34c03a300ce5e5d12f917793415df03305d885743eb8b88080de5125b3f010f049f7ab6852dacc7bf54c5fa58a51d1a77e630139c7af40080a80ffb
7
- data.tar.gz: 5d8004e9236644ac16e6e80b699f2e9e1e735101552f783d996694b0c0caa461dc59ead50b2f2980f6789481c09bfdd0327eabceae6f869cff9d4a6ce770e231
6
+ metadata.gz: 0ceb56e3450b4ea6a447294289f3d9f9e8825dc2ac2cd569b3748278798fc1ff83b90da973776f5196b452a78235423f167c9318c9602e29b028779f390f5b7d
7
+ data.tar.gz: 187897199ea333c4d9423a724e74a5b39d0697b4e55f8321fea23a30f0ba8ec4bb003151880a015b715249901525b9c8074d3b7e1616c6a464f96e8b49d0588a
@@ -0,0 +1,60 @@
1
+ module Effective
2
+ class Migrator
3
+ attr_accessor :resource # The class level effective_resource do ... end object
4
+
5
+ def initialize(obj)
6
+ @resource = (obj.kind_of?(Effective::Resource) ? obj: Effective::Resource.new(obj))
7
+
8
+ unless @resource.respond_to?(:model) && @resource.model.present?
9
+ raise 'expected effective_resource or klass to have an effective_resource do ... end block defined'
10
+ end
11
+ end
12
+
13
+ # Writes database migrations automatically based on effective_resources do ... end block
14
+ def migrate!
15
+ table_attributes = resource.table_attributes
16
+ model_attributes = resource.model_attributes
17
+
18
+ table_keys = table_attributes.keys
19
+ model_keys = model_attributes.keys
20
+
21
+ # Create table
22
+ if table_keys.blank?
23
+ Rails.logger.info "effective_developer migrate #{resource.plural_name}: create table"
24
+ return rails_migrate("create_#{resource.plural_name}", model_attributes)
25
+ end
26
+
27
+ # Fields are not in database, but present in model.rb
28
+ if(add_keys = (model_keys - table_keys)).present?
29
+ Rails.logger.info "effective_developer migrate #{resource.plural_name}: add #{add_keys.to_sentence}"
30
+ rails_migrate("add_fields_to_#{resource.plural_name}", model_attributes.slice(*add_keys))
31
+ end
32
+
33
+ # Fields are in database, but no longer in our effective_resource do block
34
+ if (remove_keys = (table_keys - model_keys)).present?
35
+ Rails.logger.info "effective_developer migrate #{resource.plural_name}: remove #{remove_keys.to_sentence}"
36
+ rails_migrate("remove_fields_from_#{resource.plural_name}", table_attributes.slice(*remove_keys))
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def rails_migrate(filename, attributes)
43
+ invokable = attributes.map { |name, (type, _)| "#{name}:#{type}" }
44
+
45
+ pending = (ActiveRecord::Migration.check_pending! rescue true)
46
+ ActiveRecord::Tasks::DatabaseTasks.migrate if pending
47
+
48
+ # Can't get this to work
49
+ # Rails.logger.info "INVOKING!!!!!"
50
+ # binding.pry
51
+ # Rails::Generators.invoke('migration', [filename] + invokable, behavior: :invoke, destination_root: Rails.root, migration_paths: ['db/migrate'])
52
+
53
+ system("rails generate migration #{filename} #{invokable.join(' ')}")
54
+ ActiveRecord::Tasks::DatabaseTasks.migrate
55
+
56
+ true
57
+ end
58
+
59
+ end
60
+ end
@@ -11,6 +11,7 @@ module EffectiveDeveloper
11
11
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
12
12
  initializer 'effective_developer.effective_resources' do |app|
13
13
  ActiveSupport.on_load :effective_resource do
14
+ #Effective::Migrator.new(self).migrate!
14
15
  end
15
16
  end
16
17
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
@@ -58,7 +58,6 @@ module Effective
58
58
  klass_attributes = resource.klass_attributes(all: all)
59
59
 
60
60
  if klass_attributes.blank?
61
-
62
61
  if ActiveRecord::Migration.respond_to?(:check_pending!)
63
62
  pending = (ActiveRecord::Migration.check_pending! rescue true)
64
63
  else
@@ -73,7 +72,7 @@ module Effective
73
72
  klass_attributes = resource.klass_attributes(all: all)
74
73
  end
75
74
 
76
- klass_attributes.presence || resource.model_attributes
75
+ klass_attributes.presence || resource.model_attributes(all: all)
77
76
  end
78
77
 
79
78
  end
@@ -27,7 +27,7 @@ module Effective
27
27
  elsif resource.klass_attributes.present?
28
28
  raise 'klass_attributes already exist. We cant migrate (yet). Exiting.'
29
29
  elsif resource.model_attributes.present?
30
- Rails::Generators.invoke('migration', ["create_#{plural_name}"] + invokable(resource.belong_tos_attributes) + (invokable(resource.model_attributes) | timestamps))
30
+ Rails::Generators.invoke('migration', ["create_#{plural_name}"] + invokable(resource.model_attributes))
31
31
  else
32
32
  raise 'You need to specify some attributes or have a model file present'
33
33
  end
@@ -62,7 +62,7 @@ module Effective
62
62
  say_status(:skipped, :form, :yellow) and return
63
63
  end
64
64
 
65
- Rails::Generators.invoke('effective:form', [name] + invokable(invoked_attributes))
65
+ Rails::Generators.invoke('effective:form', [name] + invoked_attributes_args)
66
66
  end
67
67
 
68
68
  end
@@ -1,24 +1,27 @@
1
1
  class <%= resource.namespaced_class_name.pluralize %>Datatable < Effective::Datatable
2
2
 
3
+ bulk_actions do
4
+ bulk_action 'Delete selected', <%= [resource.namespaces, resource, 'path'].flatten.compact.join('_') %>(:ids), data: { method: :delete, confirm: 'Really delete selected?' }
5
+ end
6
+
3
7
  datatable do
4
- length 25
5
- order :<%= (attributes[:updated_at] ? :updated_at : attributes.keys.first) %>
8
+ order :updated_at
9
+
10
+ bulk_actions_col
6
11
 
7
- <% if attributes[:updated_at] -%>
8
12
  col :updated_at, visible: false
9
- <% end -%>
10
- <% if attributes[:created_at] -%>
11
13
  col :created_at, visible: false
12
- <% end -%>
13
14
  col :id, visible: false
14
15
 
16
+ <% if resource.belong_tos.present? || resource.has_anys.present? -%>
15
17
  <% resource.belong_tos.each do |reference| -%>
16
18
  col :<%= reference.name %>
17
19
  <% end -%>
18
- <% resource.nested_resources.each do |reference| -%>
20
+ <% resource.has_anys.each do |reference| -%>
19
21
  col :<%= reference.name %>
20
22
  <% end -%>
21
23
 
24
+ <% end -%>
22
25
  <% attributes.except(:created_at, :updated_at, :id).each do |name, _| -%>
23
26
  col :<%= name %>
24
27
  <% end -%>
@@ -8,9 +8,11 @@ class <%= resource.class_name %> < <%= parent_class_name.classify %>
8
8
  <% invoked_attributes.each do |name, (type, _)| -%>
9
9
  <%= name.to_s.ljust(max_attribute_name_length) %> :<%= type %>
10
10
  <% end -%>
11
+
12
+ timestamps
11
13
  end
12
14
 
13
- scope :deep, -> { <%= resource.class_name %>.all }
15
+ scope :deep, -> { all }
14
16
 
15
17
  <% invoked_attributes.each do |name, (type, _)| -%>
16
18
  validates :<%= name %>, presence: true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_developer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-03 00:00:00.000000000 Z
11
+ date: 2018-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -50,6 +50,7 @@ files:
50
50
  - Rakefile
51
51
  - app/models/effective/code_writer.rb
52
52
  - app/models/effective/csv_importer.rb
53
+ - app/models/effective/migrator.rb
53
54
  - config/effective_developer.rb
54
55
  - lib/effective_developer.rb
55
56
  - lib/effective_developer/engine.rb
@@ -117,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
118
  version: '0'
118
119
  requirements: []
119
120
  rubyforge_project:
120
- rubygems_version: 2.5.2.3
121
+ rubygems_version: 2.4.5.1
121
122
  signing_key:
122
123
  specification_version: 4
123
124
  summary: Provides some quality of life developer tools.