effective_developer 0.2.2 → 0.2.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: ce1975bd0775294de65297b619248e266ab88a87
4
- data.tar.gz: 34efafaa3dce62af63bcb3571e72383dbb8fd065
3
+ metadata.gz: f41039ceac09c55fe7ae821452bc2d570bb2279c
4
+ data.tar.gz: 4078bf19bfc90c29a6e67253ed1cbb3d54cef519
5
5
  SHA512:
6
- metadata.gz: 3dd047b0be47a0266fc26d71ae6b127dc4e56d363303eb1a0426e36d1a2c69f65018c119f904a3c5525454adddc2df5e417ec6056f0c86ad617688cc280227c6
7
- data.tar.gz: 4ad38f81ea47ee63c013932cb6fd23e4d730839b11357d27b9a218ee8fc1a7658a15275635dd97df33f337cacead0dfa13619a48ac63f1a599bed8ef2726f998
6
+ metadata.gz: e776f703a4753b14d2b507be9c1beb72e7024879241fbfd2016dd0879efce73355f18a779a7fd8b9b782d3eb9ab675f8bcd243eb9e4ef6d6bc71b0c1077e3bc5
7
+ data.tar.gz: 46fcc829aa004135e7412f919e385335ae5e33a6102551674d3a7034a3ec32fd034ae4944b188e6f191cdd6ec6b6dc1f55ce701f38794f8d1d8de153b4f8e8ca
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
@@ -21,8 +21,7 @@ module Effective
21
21
 
22
22
  def create_ability
23
23
  unless File.exists?('app/models/ability.rb')
24
- say_status :skipped, :ability, :yellow
25
- return
24
+ say_status(:skipped, :ability, :yellow) and return
26
25
  end
27
26
 
28
27
  Effective::CodeWriter.new('app/models/ability.rb') do |w|
@@ -30,6 +30,15 @@ module Effective
30
30
  say_status :invoke, :controller, :white
31
31
  end
32
32
 
33
+ # Find if effective_resources is in the app's Gemfile
34
+ def enable_effective_resources
35
+ self.class.send(:attr_reader, :use_effective_resources)
36
+
37
+ Effective::CodeWriter.new('Gemfile') do |w|
38
+ @use_effective_resources = w.find { |line| line.include?('effective_resources') }.present?
39
+ end
40
+ end
41
+
33
42
  def create_controller
34
43
  template 'controllers/controller.rb', resource.controller_file
35
44
  end
@@ -28,6 +28,10 @@ module Effective
28
28
  end
29
29
 
30
30
  def create_datatable
31
+ unless defined?(EffectiveDatatables)
32
+ say_status(:skipped, :datatable, :yellow) and return
33
+ end
34
+
31
35
  template 'datatables/datatable.rb', resource.datatable_file
32
36
  end
33
37
 
@@ -40,7 +40,7 @@ module Effective
40
40
 
41
41
  class_eval { attr_accessor :nested_resource }
42
42
 
43
- resource.nested_resources.each do |_, nested_resource|
43
+ resource.nested_resources.each do |nested_resource|
44
44
  @nested_resource = nested_resource
45
45
  template 'forms/tabpanel/_tab_nested_resource.html.haml', resource.view_file("form_#{nested_resource.plural_name}", partial: true)
46
46
  template 'forms/fields/_nested_resource_fields.html.haml', File.join('app/views', resource.namespace.to_s, (resource.namespace.present? ? '' : resource.class_path), nested_resource.name.to_s.underscore.pluralize, '_fields.html.haml')
@@ -61,10 +61,10 @@ module Effective
61
61
  b = binding
62
62
 
63
63
  partial = case attribute
64
- when ActiveRecord::Reflection::BelongsToReflection
64
+ when (ActiveRecord::Reflection::BelongsToReflection rescue false)
65
65
  b.local_variable_set(:reference, attribute)
66
66
  'belongs_to'
67
- when ActiveRecord::Reflection::HasManyReflection
67
+ when (ActiveRecord::Reflection::HasManyReflection rescue false)
68
68
  b.local_variable_set(:nested_resource, attribute)
69
69
  'nested_resource'
70
70
  when Effective::Resource
@@ -1,11 +1,11 @@
1
1
  class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.namespace.try(:classify).presence, ApplicationController].compact.join('::') %>
2
2
  before_action :authenticate_user! # Devise enforce user is present
3
3
 
4
- <% if defined?(EffectiveResources) -%>
4
+ <% if use_effective_resources -%>
5
5
  include Effective::CrudController
6
6
 
7
7
  <% end -%>
8
- <% if actions.delete('index') && !defined?(EffectiveResources) -%>
8
+ <% if actions.delete('index') && !use_effective_resources -%>
9
9
  def index
10
10
  @page_title = '<%= resource.plural_name.titleize %>'
11
11
  authorize! :index, <%= resource.class_name %>
@@ -14,7 +14,7 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
14
14
  end
15
15
 
16
16
  <% end -%>
17
- <% if actions.delete('new') && !defined?(EffectiveResources) -%>
17
+ <% if actions.delete('new') && !use_effective_resources -%>
18
18
  def new
19
19
  @<%= resource.name %> = <%= resource.class_name %>.new
20
20
 
@@ -23,7 +23,7 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
23
23
  end
24
24
 
25
25
  <% end -%>
26
- <% if actions.delete('create') && !defined?(EffectiveResources) -%>
26
+ <% if actions.delete('create') && !use_effective_resources -%>
27
27
  def create
28
28
  @<%= resource.name %> = <%= resource.class_name %>.new(<%= resource.name %>_params)
29
29
 
@@ -40,7 +40,7 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
40
40
  end
41
41
 
42
42
  <% end -%>
43
- <% if actions.delete('show') && !defined?(EffectiveResources) -%>
43
+ <% if actions.delete('show') && !use_effective_resources -%>
44
44
  def show
45
45
  @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
46
46
 
@@ -49,7 +49,7 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
49
49
  end
50
50
 
51
51
  <% end -%>
52
- <% if actions.delete('edit') && !defined?(EffectiveResources) -%>
52
+ <% if actions.delete('edit') && !use_effective_resources -%>
53
53
  def edit
54
54
  @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
55
55
 
@@ -58,7 +58,7 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
58
58
  end
59
59
 
60
60
  <% end -%>
61
- <% if actions.delete('update') && !defined?(EffectiveResources) -%>
61
+ <% if actions.delete('update') && !use_effective_resources -%>
62
62
  def update
63
63
  @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
64
64
 
@@ -75,7 +75,7 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
75
75
  end
76
76
 
77
77
  <% end -%>
78
- <% if actions.delete('destroy') && !defined?(EffectiveResources) -%>
78
+ <% if actions.delete('destroy') && !use_effective_resources -%>
79
79
  def destroy
80
80
  @<%= resource.name %> = <%= resource.class_name %>.find(params[:id])
81
81
  authorize! :destroy, @<%= resource.name %>
@@ -121,13 +121,14 @@ class <%= resource.namespaced_class_name.pluralize %>Controller < <%= [resource.
121
121
  <% attributes.each_slice(8).with_index do |slice, index| -%>
122
122
  <%= slice.map { |att| permitted_param_for(att.name) }.join(', ') %><%= ',' if (((index+1) * 8) < attributes.length || resource.nested_resources.present?) %>
123
123
  <% end -%>
124
- <% resource.nested_resources.each_with_index do |(_, nested_resource), index| -%>
125
- <%= nested_resource.name %>_attributes: [:id, :_destroy, <%= (nested_resource.belong_tos_attributes + nested_resource.attributes).map { |att| ':' + att.name.to_s }.join(', ') %>]<%= ',' if index < resource.nested_resources.length-1 %>
124
+ <% resource.nested_resources.each_with_index do |nested_resource, index| -%>
125
+ <% nested = Effective::Resource.new(nested_resource) -%>
126
+ <%= nested.name %>_attributes: [:id, :_destroy, <%= (nested.belong_tos_attributes + nested.attributes).map { |att| ':' + att.name.to_s }.join(', ') %>]<%= ',' if index < resource.nested_resources.length-1 %>
126
127
  <% end -%>
127
128
  )
128
129
  end
129
130
 
130
- <% if !defined?(EffectiveResources) -%>
131
+ <% if !use_effective_resources -%>
131
132
  def redirect_path
132
133
  case params[:commit].to_s
133
134
  when 'Save'
@@ -5,7 +5,7 @@
5
5
  %a{'data-toggle': 'tab', role: 'tab', 'aria-controls': '<%= resource.name %>-tab', href: '#<%= resource.name %>-tab'}
6
6
  <%= resource.human_name.titleize %>
7
7
 
8
- <% resource.nested_resources.each do |_, nested_resource| -%>
8
+ <% resource.nested_resources.each do |nested_resource| -%>
9
9
  %li{role: 'presentation'}
10
10
  %a{'data-toggle': 'tab', role: 'tab', 'aria-controls': '<%= nested_resource.plural_name %>-tab', href: '#<%= nested_resource.plural_name %>-tab'}
11
11
  <%= nested_resource.plural_name.titleize %>
@@ -15,7 +15,7 @@
15
15
  #<%= resource.name %>-tab.tab-pane.active{role: 'tabpanel'}
16
16
  = render 'form_<%= resource.name %>', f: f
17
17
 
18
- <% resource.nested_resources.each do |_, nested_resource| -%>
18
+ <% resource.nested_resources.each do |nested_resource| -%>
19
19
  #<%= nested_resource.plural_name %>-tab.tab-pane{role: 'tabpanel'}
20
20
  = render 'form_<%= nested_resource.plural_name %>', f: f
21
21
  <% end -%>
@@ -5,8 +5,12 @@
5
5
  %p.text-right= link_to 'New <%= resource.human_name %>', <%= resource.new_path %>, class: 'btn btn-primary'
6
6
 
7
7
  <% end -%>
8
+ <% if defined?(EffectiveDatatables) -%>
8
9
  - if @datatable.present?
9
10
  = render_datatable_scopes(@datatable)
10
11
  = render_datatable(@datatable)
11
12
  - else
12
13
  %p There are no <%= resource.plural_name %>.
14
+ <% else %>
15
+ = render @<%= resource.plural_name %>
16
+ <% end %>
@@ -6,7 +6,7 @@ task :validate, [:model] => :environment do |t, args|
6
6
  args.with_defaults(:model => 'all')
7
7
 
8
8
  Rails.application.eager_load!
9
- klasses = ActiveRecord::Base.descendants.sort { |a, b| a.name <=> b.name }
9
+ klasses = ActiveRecord::Base.descendants.reject { |klass| klass.abstract_class? }.sort { |a, b| a.name <=> b.name }
10
10
 
11
11
  if args.model != 'all'
12
12
  klasses.delete_if { |klass| klass.name.downcase != args.model.singularize.downcase }
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.2.2
4
+ version: 0.2.3
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: 2017-01-29 00:00:00.000000000 Z
11
+ date: 2017-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails