onotole 1.2.6 → 1.2.7

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: cba30776c63c5220840dec9829dacfb4bddc821c
4
- data.tar.gz: f1a229f67bf23a592879ac48f1e66cec772f5534
3
+ metadata.gz: 3ed38623e2c23934c719c6ac10948a8ef180fb22
4
+ data.tar.gz: 0edf421b48ca2d6bdd3ad0319550544de078130a
5
5
  SHA512:
6
- metadata.gz: 485bb102cd07549c81ac0807e7e98b17b6609e4bc63bfd191015680c12d6d831c7e875d39c46cf16e16cf940a3e4971392256bb60b6cd967e61b14f6ab066a6a
7
- data.tar.gz: 7afa3b764db7b01070293b77dae62e6b59e96c629fdf98db456f846129be4425123c727844050f7bc9908d7f90e5b6481922b7d36cd7d670ae27908fac99ce37
6
+ metadata.gz: 73aae5a47a32ae3ffec342661e729cc75fb246567a12a457211f8b3447f90b2ea92383041f82d9608bb24069f7185bc939302bafe5ed9bdc178988ab0e5716aa
7
+ data.tar.gz: 5628a8a56133950bb53957eec4ac0a6a45474817b1a5c3423fe5be368f6b8ddd741b4c56408a0782d3d26b4f198dfb754f6d465ff18e7ce74bb91f42b6f11f52
data/README.md CHANGED
@@ -356,6 +356,7 @@ improvement
356
356
  * Made seeds organization for easy splitting data from scratch
357
357
  * `Carrierwave` may be integrated with `mini_magick` and `ckeditor`, depend on
358
358
  user choice
359
+ * Ability to use `AbstractModel` for easy code extension
359
360
 
360
361
  ## Heroku
361
362
 
@@ -29,6 +29,7 @@ module Onotole
29
29
  :normalize,
30
30
  :tinymce,
31
31
  :rubocop,
32
+ :abstract_model_wrapper,
32
33
  :create_github_repo]
33
34
  install_queue.each { |g| send "after_install_#{g}" if user_choose? g }
34
35
  delete_comments
@@ -352,5 +353,18 @@ DATA
352
353
  def after_install_sitemap_generator
353
354
  bundle_command 'exec sitemap:install'
354
355
  end
356
+
357
+ def after_install_abstract_model_wrapper
358
+ path = 'lib/rails/generators/active_record/model'
359
+ run "mkdir -p #{path}"
360
+ copy_file 'model_generator.rb', "#{path}/model_generator.rb"
361
+ File.open('app/models/abstract_model.rb', 'w') do |f|
362
+ f.puts <<-ABSTRACT
363
+ class AbstractModel < ActiveRecord::Base
364
+ self.abstract_class = true
365
+ end
366
+ ABSTRACT
367
+ end
368
+ end
355
369
  end
356
370
  end
@@ -164,6 +164,13 @@ module Onotole
164
164
  # gem_description)) unless options[gem_name]
165
165
  # end
166
166
 
167
+ # TODO: move all this to other module
168
+ def users_abstract_model_wrapper_choice
169
+ variants = { none: 'No', abstract_model_wrapper: 'Yes' }
170
+ sel = choice 'Create abstract model wrapper for all models? ', variants
171
+ add_to_user_choise(sel) unless sel == :none
172
+ end
173
+
167
174
  def users_init_commit_choice
168
175
  variants = { none: 'No', gitcommit: 'Yes' }
169
176
  sel = choice 'Make init commit in the end? ', variants
@@ -16,6 +16,7 @@ module Onotole
16
16
 
17
17
  choose_undroup_gems
18
18
  ask_cleanup_commens
19
+ users_abstract_model_wrapper_choice
19
20
  users_init_commit_choice
20
21
  add_github_repo_creation_choice
21
22
  setup_default_gems
@@ -2,5 +2,5 @@
2
2
  module Onotole
3
3
  RAILS_VERSION = '~> 4.2.0'
4
4
  RUBY_VERSION = IO.read("#{File.dirname(__FILE__)}/../../.ruby-version").strip
5
- VERSION = '1.2.6'
5
+ VERSION = '1.2.7'
6
6
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require 'rails/generators/active_record'
3
+ module ActiveRecord
4
+ module Generators # :nodoc:
5
+ class ModelGenerator < Base # :nodoc:
6
+ argument :attributes, type: :array, default: [], banner: 'field[:type][:index] field[:type][:index]'
7
+
8
+ check_class_collision
9
+
10
+ class_option :migration, type: :boolean
11
+ class_option :timestamps, type: :boolean
12
+ class_option :parent, type: :string, desc: 'The parent class for the generated model'
13
+ class_option :indexes, type: :boolean, default: true, desc: 'Add indexes for references and belongs_to columns'
14
+
15
+ # creates the migration file for the model.
16
+
17
+ def create_migration_file
18
+ return unless options[:migration] && options[:parent].nil?
19
+ attributes.each { |a| a.attr_options.delete(:index) if a.reference? && !a.has_index? } if options[:indexes] == false
20
+ migration_template '../../migration/templates/create_table_migration.rb', "db/migrate/create_#{table_name}.rb"
21
+ end
22
+
23
+ def create_model_file
24
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
25
+ end
26
+
27
+ def create_module_file
28
+ return if regular_class_path.empty?
29
+ template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
30
+ end
31
+
32
+ def attributes_with_index
33
+ attributes.select { |a| !a.reference? && a.has_index? }
34
+ end
35
+
36
+ def accessible_attributes
37
+ attributes.reject(&:reference?)
38
+ end
39
+
40
+ hook_for :test_framework
41
+
42
+ protected
43
+
44
+ # Used by the migration template to determine the parent name of the model
45
+ def parent_class_name
46
+ options[:parent] || 'AbstractModel'
47
+ end
48
+ end
49
+ end
50
+ end
data/templates/support.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
  Dir[Rails.root.join('app/support/**/*.rb'),
3
- Rails.root.join('lib/**/*.rb')].each { |file| require_dependency file }
3
+ Rails.root.join('lib/*.rb')].each { |file| require_dependency file }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onotole
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - kvokka
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-24 00:00:00.000000000 Z
12
+ date: 2016-04-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -165,6 +165,7 @@ files:
165
165
  - templates/json_encoding.rb
166
166
  - templates/kaminari.rb
167
167
  - templates/kill_postgress_conections.rake
168
+ - templates/model_generator.rb
168
169
  - templates/newrelic.yml.erb
169
170
  - templates/onotole_layout.html.erb.erb
170
171
  - templates/onotole_overcommit.yml