effective_developer 0.0.7 → 0.0.8

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: 6afcc37e01e11a752f1fa16ea168e739886571a5
4
- data.tar.gz: 1f79a862bbaeaec604384015649860c8fc3ca53d
3
+ metadata.gz: f8689f1bc4992384e17f61c4d8c65dc4c9eff7d8
4
+ data.tar.gz: a0f2a455a5bf32d0284deebbd5761ec246e146e0
5
5
  SHA512:
6
- metadata.gz: 90ce51e217dab774391c2f2e697951a594383738b61b1c1473291804daadbb9dc88409932925faeb000e8abea7248a5a224e7e0bb8f543cfeea564c9e6be2deb
7
- data.tar.gz: ce87d2c69e4844d62226ada1b014698269121d3db47265d0170e202ccba8ca168e2d77b4c18272357b01858bd3bdb773e89a180a9df0ba41f3ccc245b7ae60bd
6
+ metadata.gz: 10cc81aa4428dc08fe8c2f94e9e63702d8ee95e7316b3f4ff9a6dd7cffd06a407e6e22f95233b4f292e2e02dc893fa84f1e2c515627741abcb481961c7cde5dc
7
+ data.tar.gz: 0c6397219c15e4256b563d251c0d53bdb3ce20b1977ebeb719cd67bce70c0b5f99e718431c0aadb6e594d8be60d30a0b102d05509ec60e3a9ff82a27fdd638da
data/README.md CHANGED
@@ -208,12 +208,27 @@ end
208
208
 
209
209
  Override `before_import()` or `after_import()` to run code before or after the import.
210
210
 
211
- ## License
211
+ # Scaffolding
212
+
213
+ Scaffolding is the fastest way to build a rails app. Take advantage of scaffolding.
214
+
215
+
216
+ ```ruby
217
+ rails generate scaffold product name:string # active_record, test_unit, resource_route, scaffold_controller, haml, test_unit, helper, assets
218
+ rails generate scaffold_controller product # haml, test_unit, helper,
219
+ rails generate model product # active_record, test_unit
220
+ rails generate active_record:model product # test_unit
221
+ rails generate resource_route product
222
+ rails generate test_unit:model product
223
+ rails generate mailer product
224
+ rails generate job product
225
+ ```
212
226
 
213
- MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
214
227
 
215
- Code and Effect is the product arm of [AgileStyle](http://www.agilestyle.com/), an Edmonton-based shop that specializes in building custom web applications with Ruby on Rails.
216
228
 
229
+ ## License
230
+
231
+ MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
217
232
 
218
233
  ## Contributing
219
234
 
@@ -0,0 +1,13 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= class_name %>Controller < ApplicationController
7
+ <% actions.each do |action| -%>
8
+ def <%= action %>
9
+ end
10
+ <%= "\n" unless action == actions.last -%>
11
+ <% end -%>
12
+ end
13
+ <% end -%>
@@ -0,0 +1,14 @@
1
+ module Effective
2
+ module Datatables
3
+ class <%= class_name %> < Effective::Datatable
4
+
5
+ datatable do
6
+ <% attributes.each do |attribute| %>
7
+ table_column :<%= attribute.name -%>
8
+ <% end %>
9
+ actions_column
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ <% module_namespacing do -%>
2
+ class <%= class_name %> < <%= parent_class_name.classify %>
3
+ <% attributes.select(&:reference?).each do |attribute| -%>
4
+ belongs_to :<%= attribute.name %><%= ', polymorphic: true' if attribute.polymorphic? %><%= ', required: true' if attribute.required? %>
5
+ <% end -%>
6
+ <% attributes.select(&:token?).each do |attribute| -%>
7
+ has_secure_token<% if attribute.name != "token" %> :<%= attribute.name %><% end %>
8
+ <% end -%>
9
+ <% if attributes.any?(&:password_digest?) -%>
10
+ has_secure_password
11
+ <% end -%>
12
+ end
13
+ <% end -%>
14
+
15
+ MINE
@@ -0,0 +1,15 @@
1
+ = form_for @<%= singular_table_name %> do |f|
2
+ - if @<%= singular_table_name %>.errors.any?
3
+ #error_explanation
4
+ %h2= "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
5
+ %ul
6
+ - @<%= singular_table_name %>.errors.full_messages.each do |msg|
7
+ %li= msg
8
+
9
+ <% for attribute in attributes -%>
10
+ .field
11
+ = f.label :<%= attribute.name %>
12
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
13
+ <% end -%>
14
+ .actions
15
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ %h1 Editing <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', @<%= singular_table_name %>
6
+ \|
7
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,25 @@
1
+ %h1 Listing <%= plural_table_name %>
2
+
3
+ %table
4
+ %thead
5
+ %tr
6
+ <% for attribute in attributes -%>
7
+ %th <%= attribute.human_name %>
8
+ <% end -%>
9
+ %th
10
+ %th
11
+ %th
12
+
13
+ %tbody
14
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
15
+ %tr
16
+ <% for attribute in attributes -%>
17
+ %td= <%= singular_table_name %>.<%= attribute.name %>
18
+ <% end -%>
19
+ %td= link_to 'Show', <%= singular_table_name %>
20
+ %td= link_to 'Edit', edit_<%= singular_table_name %>_path(<%= singular_table_name %>)
21
+ %td= link_to 'Destroy', <%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' }
22
+
23
+ %br
24
+
25
+ = link_to 'New <%= human_name %>', new_<%= singular_table_name %>_path
@@ -0,0 +1,5 @@
1
+ %h1 New <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', <%= index_helper %>_path
@@ -0,0 +1,11 @@
1
+ %p#notice= notice
2
+
3
+ <% for attribute in attributes -%>
4
+ %p
5
+ %b <%= attribute.human_name %>:
6
+ = @<%= singular_table_name %>.<%= attribute.name %>
7
+ <% end -%>
8
+
9
+ = link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
10
+ \|
11
+ = link_to 'Back', <%= index_helper %>_path
@@ -1,4 +1,2 @@
1
- # EffectiveDeveloper Rails Engine
2
-
3
1
  EffectiveDeveloper.setup do |config|
4
2
  end
@@ -1,3 +1,4 @@
1
+ require 'generators/effective/helpers'
1
2
  require 'effective_developer/engine'
2
3
  require 'effective_developer/version'
3
4
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDeveloper
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
@@ -0,0 +1,35 @@
1
+ # rails generate effective:controller NAME [action action] [options]
2
+
3
+ module Effective
4
+ module Generators
5
+ class ControllerGenerator < Rails::Generators::NamedBase
6
+ include Helpers
7
+
8
+ source_root File.expand_path(('../' * 4) + 'app/scaffolds', __FILE__)
9
+
10
+ desc 'Creates a controller in your app/controllers folder.'
11
+
12
+ argument :actions, type: :array, default: ['crud'], banner: 'action action'
13
+ class_option :attributes, type: :array, default: [], desc: 'Included permitted params, otherwise read from model'
14
+
15
+ attr_accessor :attributes
16
+
17
+ def initialize(args, *options)
18
+ if options.kind_of?(Array) && options.second.kind_of?(Hash)
19
+ self.attributes = options.second.delete(:attributes)
20
+ end
21
+
22
+ super
23
+ end
24
+
25
+ def assign_actions
26
+ @actions = invoked_actions
27
+ end
28
+
29
+ def create_controller
30
+ template 'controllers/controller.rb', File.join('app/controllers', class_path, "#{file_name}_controller.rb")
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ # rails generate effective:datatable NAME [field[:type] field[:type]] [options]
2
+
3
+ module Effective
4
+ module Generators
5
+ class DatatableGenerator < Rails::Generators::NamedBase
6
+ include Helpers
7
+
8
+ source_root File.expand_path(('../' * 4) + 'app/scaffolds', __FILE__)
9
+
10
+ desc 'Creates an Effective::Datatable in your app/effective/datatables folder.'
11
+
12
+ argument :attributes, type: :array, default: [], banner: 'field[:type] field[:type]'
13
+
14
+ def create_datatable
15
+ template 'datatables/datatable.rb', File.join('app/models/effective/datatables', class_path, "#{file_name}.rb")
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,31 @@
1
+ module Effective
2
+ module Generators
3
+ module Helpers
4
+
5
+ protected
6
+
7
+ def invoked_attributes
8
+ _attributes = (respond_to?(:attributes) ? attributes : Array(options.attributes).compact)
9
+ _attributes.map { |att| "#{att.name}:#{att.type}" }
10
+ end
11
+
12
+ def invoked_actions
13
+ _actions = (respond_to?(:actions) ? actions : options.actions)
14
+ _actions = Array(_actions).flat_map { |arg| arg.gsub('[', '').gsub(']', '').split(',') }
15
+
16
+ case _actions
17
+ when ['crud']
18
+ %w(index new create show edit update destroy)
19
+ else
20
+ _actions
21
+ end
22
+ end
23
+
24
+ # Used by model and datatable
25
+ def parent_class_name
26
+ options[:parent] || 'ApplicationRecord'
27
+ end
28
+
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ # rails generate effective:migration NAME [field[:type] field[:type]] [options]
2
+
3
+ module Effective
4
+ module Generators
5
+ class MigrationGenerator < Rails::Generators::NamedBase
6
+ include Helpers
7
+
8
+ source_root File.expand_path(('../' * 4) + 'app/scaffolds', __FILE__)
9
+
10
+ desc 'Creates a migration.'
11
+
12
+ argument :attributes, type: :array, default: [], banner: 'field[:type] field[:type]'
13
+
14
+ def create_migration
15
+ Rails::Generators.invoke('migration', ["create_#{file_name.pluralize}"] + invoked_attributes)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # rails generate effective:model NAME [field[:type] field[:type]] [options]
2
+
3
+ module Effective
4
+ module Generators
5
+ class ModelGenerator < Rails::Generators::NamedBase
6
+ include Helpers
7
+
8
+ source_root File.expand_path(('../' * 4) + 'app/scaffolds', __FILE__)
9
+
10
+ desc 'Creates a model in your app/models folder.'
11
+
12
+ argument :attributes, type: :array, default: [], banner: 'field[:type] field[:type]'
13
+
14
+ def create_model
15
+ template 'models/model.rb', File.join('app/models', class_path, "#{file_name}.rb")
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # rails generate effective:route NAME [action action] [options]
2
+
3
+ module Effective
4
+ module Generators
5
+ class RouteGenerator < Rails::Generators::NamedBase
6
+ include Helpers
7
+
8
+ source_root File.expand_path(('../' * 4) + 'app/scaffolds', __FILE__)
9
+
10
+ desc 'Creates a route.'
11
+
12
+ argument :actions, type: :array, default: ['crud'], banner: 'action action'
13
+
14
+ def create_route
15
+ Rails::Generators.invoke('resource_route', [name])
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,85 @@
1
+ # rails generate effective:scaffold NAME [field[:type] field[:type]] [options]
2
+
3
+ # rails generate effective:scaffold Thing
4
+ # rails generate effective:scaffold admin/thing name:string details:text --actions index show edit update
5
+ # rails generate effective:scaffold admin/thing name:string details:text
6
+
7
+ module Effective
8
+ module Generators
9
+ class ScaffoldGenerator < Rails::Generators::NamedBase
10
+ include Helpers
11
+
12
+ source_root File.expand_path(('../' * 4) + 'app/scaffolds', __FILE__)
13
+
14
+ desc 'Creates an Effective Scaffold'
15
+
16
+ argument :attributes, type: :array, default: [], banner: 'field[:type] field[:type]'
17
+ class_option :actions, type: :array, default: ['crud'], desc: 'Included actions', banner: 'index show'
18
+
19
+ def create_migration
20
+ Rails::Generators.invoke('effective:migration', [name] + invoked_attributes)
21
+ end
22
+
23
+ def create_model
24
+ Rails::Generators.invoke('effective:model', [name] + invoked_attributes)
25
+ end
26
+
27
+ def create_datatable
28
+ Rails::Generators.invoke('effective:datatable', [name] + invoked_attributes)
29
+ end
30
+
31
+ def create_routes
32
+ Rails::Generators.invoke('effective:route', [name] + invoked_actions)
33
+ end
34
+
35
+ def create_controller
36
+ Rails::Generators.invoke('effective:controller', [name] + invoked_actions, attributes: invoked_attributes)
37
+ end
38
+
39
+ def create_views
40
+ Rails::Generators.invoke('effective:view', [name] + invoked_actions, attributes: invoked_attributes)
41
+ end
42
+
43
+ end
44
+ end
45
+ end
46
+
47
+ # class_name
48
+ # class_path
49
+ # file_path
50
+
51
+
52
+
53
+ # require "rails/generators/rails/resource/resource_generator"
54
+
55
+ # module Effective
56
+ # module Generators
57
+ # class ScaffoldGenerator < ResourceGenerator # :nodoc:
58
+ # remove_hook_for :resource_controller
59
+ # remove_class_option :actions
60
+
61
+ # class_option :stylesheets, type: :boolean, desc: "Generate Stylesheets"
62
+ # class_option :stylesheet_engine, desc: "Engine for Stylesheets"
63
+ # class_option :assets, type: :boolean
64
+ # class_option :resource_route, type: :boolean
65
+ # class_option :scaffold_stylesheet, type: :boolean
66
+
67
+ # def handle_skip
68
+ # @options = @options.merge(stylesheets: false) unless options[:assets]
69
+ # @options = @options.merge(stylesheet_engine: false) unless options[:stylesheets] && options[:scaffold_stylesheet]
70
+ # end
71
+
72
+ # hook_for :scaffold_controller, required: true
73
+
74
+ # hook_for :assets do |assets|
75
+ # invoke assets, [controller_name]
76
+ # end
77
+
78
+ # hook_for :stylesheet_engine do |stylesheet_engine|
79
+ # if behavior == :invoke
80
+ # invoke stylesheet_engine, [controller_name]
81
+ # end
82
+ # end
83
+ # end
84
+ # end
85
+ # end
@@ -0,0 +1,40 @@
1
+ # rails generate effective:view NAME [index show] [options]
2
+
3
+ module Effective
4
+ module Generators
5
+ class ViewGenerator < Rails::Generators::NamedBase
6
+ include Helpers
7
+ source_root File.expand_path(('../' * 4) + 'app/scaffolds', __FILE__)
8
+
9
+ desc 'Creates one or more views in your app/views folder.'
10
+
11
+ argument :actions, type: :array, default: ['crud'], banner: 'index show'
12
+ class_option :attributes, type: :array, default: [], desc: 'Included form attributes, otherwise read from model'
13
+
14
+ attr_accessor :attributes
15
+
16
+ def initialize(args, *options)
17
+ if options.kind_of?(Array) && options.second.kind_of?(Hash)
18
+ self.attributes = options.second.delete(:attributes)
19
+ end
20
+
21
+ super
22
+ end
23
+
24
+ def create_views
25
+ (invoked_actions & available_actions).each do |action|
26
+ filename = "#{action}.html.haml"
27
+
28
+ template "views/#{filename}", File.join('app/views', file_path, filename)
29
+ end
30
+ end
31
+
32
+ protected
33
+
34
+ def available_actions
35
+ %w(index new show edit)
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -7,6 +7,7 @@ module CsvImporters
7
7
  end
8
8
 
9
9
  def process_row
10
+ # assign_columns(<%= klass %>.new).save!
10
11
  raise 'todo'
11
12
  end
12
13
  end
@@ -84,7 +84,7 @@ namespace :csv do
84
84
  path = Rails.root.to_s + '/tmp/csv_exports/'
85
85
  FileUtils.mkdir_p(path) unless File.directory?(path)
86
86
 
87
- (ActiveRecord::Base.connection.tables - ['schema_migrations']).each do |table|
87
+ (ActiveRecord::Base.connection.tables - ['schema_migrations', 'ar_internal_metadata']).each do |table|
88
88
  records = ActiveRecord::Base.connection.exec_query("SELECT * FROM #{table} ORDER BY id")
89
89
 
90
90
  CSV.open(path + "#{table}.csv", 'wb') do |csv|
@@ -10,12 +10,12 @@ namespace :pg do
10
10
  puts "=== Pulling remote '#{args.remote}' database into latest.dump"
11
11
 
12
12
  Bundler.with_clean_env do
13
- unless system("heroku pg:backups capture --remote #{args.remote}")
13
+ unless system("heroku pg:backups:capture --remote #{args.remote}")
14
14
  puts "Error capturing heroku backup"
15
15
  exit
16
16
  end
17
17
 
18
- if system("curl -o latest.dump `heroku pg:backups public-url --remote #{args.remote}`")
18
+ if system("curl -o latest.dump `heroku pg:backups:public-url --remote #{args.remote}`")
19
19
  puts "Downloading database completed"
20
20
  else
21
21
  puts "Error downloading database"
@@ -71,19 +71,19 @@ namespace :pg do
71
71
  puts "=== Cloning remote '#{args.source_remote}' to '#{args.target_remote}'"
72
72
 
73
73
  Bundler.with_clean_env do
74
- unless system("heroku pg:backups capture --remote #{args.source_remote}")
74
+ unless system("heroku pg:backups:capture --remote #{args.source_remote}")
75
75
  puts "Error capturing heroku backup"
76
76
  exit
77
77
  end
78
78
 
79
- url = (`heroku pg:backups public-url --remote #{args.source_remote}`).chomp
79
+ url = (`heroku pg:backups:public-url --remote #{args.source_remote}`).chomp
80
80
 
81
81
  unless (url || '').length > 0
82
82
  puts "Error reading public-url from remote #{args.source_remote}"
83
83
  exit
84
84
  end
85
85
 
86
- unless system("heroku pg:backups restore '#{url}' DATABASE_URL --remote #{args.target_remote}")
86
+ unless system("heroku pg:backups:restore '#{url}' DATABASE_URL --remote #{args.target_remote}")
87
87
  puts "Error cloning heroku backup"
88
88
  exit
89
89
  end
@@ -0,0 +1,30 @@
1
+ # bundle exec rake validate
2
+ # bundle exec rake validate[user]
3
+
4
+ desc 'Validates all records of the given ActiveRecord model, defaults to all'
5
+ task :validate, [:model] => :environment do |t, args|
6
+ args.with_defaults(:model => 'all')
7
+
8
+ Rails.application.eager_load!
9
+ klasses = ActiveRecord::Base.descendants.sort { |a, b| a.name <=> b.name }
10
+
11
+ if args.model != 'all'
12
+ klasses.delete_if { |klass| klass.name.downcase != args.model.singularize.downcase }
13
+ end
14
+
15
+ klasses.each do |klass|
16
+ invalids = klass.unscoped.order(:id).map do |resource|
17
+ [resource.id, '(' + resource.errors.map { |key, value| "#{key}: #{value}"}.join(', ') + ')'] unless resource.valid?
18
+ end.compact
19
+
20
+ if invalids.present?
21
+ puts "#{klass.name}: #{invalids.length} invalid records"
22
+ invalids.each { |invalid| puts invalid.join(' ') }
23
+ puts "Invalid #{klass.name} records: #{invalids.map { |invalid| invalid.first }.join(',')}"
24
+ else
25
+ puts "#{klass.name}: all records valid"
26
+ end
27
+ end
28
+
29
+
30
+ end
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.0.7
4
+ version: 0.0.8
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: 2016-09-27 00:00:00.000000000 Z
11
+ date: 2016-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -36,15 +36,32 @@ files:
36
36
  - Rakefile
37
37
  - app/models/effective/access_denied.rb
38
38
  - app/models/effective/csv_importer.rb
39
+ - app/scaffolds/controllers/controller.rb
40
+ - app/scaffolds/datatables/datatable.rb
41
+ - app/scaffolds/models/model.rb
42
+ - app/scaffolds/views/_form.html.haml
43
+ - app/scaffolds/views/edit.html.haml
44
+ - app/scaffolds/views/index.html.haml
45
+ - app/scaffolds/views/new.html.haml
46
+ - app/scaffolds/views/show.html.haml
39
47
  - config/effective_developer.rb
40
48
  - lib/effective_developer.rb
41
49
  - lib/effective_developer/engine.rb
42
50
  - lib/effective_developer/version.rb
51
+ - lib/generators/effective/controller_generator.rb
52
+ - lib/generators/effective/datatable_generator.rb
53
+ - lib/generators/effective/helpers.rb
54
+ - lib/generators/effective/migration_generator.rb
55
+ - lib/generators/effective/model_generator.rb
56
+ - lib/generators/effective/route_generator.rb
57
+ - lib/generators/effective/scaffold_generator.rb
58
+ - lib/generators/effective/view_generator.rb
43
59
  - lib/generators/effective_developer/csv_importer.rb.erb
44
60
  - lib/generators/effective_developer/install_generator.rb
45
61
  - lib/tasks/effective_csv_importer.rake
46
62
  - lib/tasks/pg_pull.rake
47
63
  - lib/tasks/reset_pk_sequence.rake
64
+ - lib/tasks/validate.rake
48
65
  homepage: https://github.com/code-and-effect/effective_developer
49
66
  licenses:
50
67
  - MIT