inline_forms_installer 8.0.3 → 8.1.0

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
  SHA256:
3
- metadata.gz: 91d4fdc2c47dbae9f0fb05f32157e77326029df28eae8c529655779d417d791a
4
- data.tar.gz: d21272dbbdd19be64fd742f267054fca738afc40cffbda9cbfe74dfb1bf2982a
3
+ metadata.gz: 05c7f9da56bb038f34b0f8619f3a94a7ef74cda07eba0c72a6ea9e03458e1c0e
4
+ data.tar.gz: 37cabf1e8475f659b12a8f075efd809b5205af4b2bdf83db3d80a46a4d70bec5
5
5
  SHA512:
6
- metadata.gz: 51085fde767560341594f9d3c3da50b8a6085b06bfef3a3ba4826e63a21de5f5278d43fdee437b1e6c45f44738bb81b3fc7e3cde5bd471dee6fe5581a7bb0bcf
7
- data.tar.gz: 1f4f9a714507ac6ba8658418a0586d1f006591f3ea9ffe6a0f655390211e7ea090a74c35f5f18cf8bbf61bbbd5b2a4fa0f52cf4f17ba223aba0b6c6f6bb8ba60
6
+ metadata.gz: fc3a508903eee6c51a65e6258fd4888923684bd178fbdca29a7f2481db41857c1a9ffbe2fb1e2ea4f225f3bee2092ea9bb3f406f782409b8f8b301f81522b86e
7
+ data.tar.gz: 853891dd6b7bce30674ddba3f7deeaa54659eb53ddf79253b5bba4f0513a4cc090f083410e1f89c82344c528f2facb6663d84a94c6829d73643c87fa05a17ed1
@@ -22,6 +22,7 @@ module InlineFormsInstaller
22
22
  method_option :email, :aliases => "-e", :default => "admin@example.com", :desc => "specify admin email"
23
23
  method_option :password, :aliases => "-p", :default => "admin999", :desc => "specify admin password"
24
24
  method_option :skiprvm, :aliases => "--no-rvm", :type => :boolean, :default => false, :desc => "install inline_forms without RVM"
25
+ method_option :user_model, :aliases => "-U", :default => "User", :banner => "CLASS", :desc => "Devise model class (e.g. Member); Warden scope stays :user (current_user)"
25
26
 
26
27
  def create(app_name)
27
28
  def self.skiprvm
@@ -59,6 +60,13 @@ module InlineFormsInstaller
59
60
  exit 1
60
61
  end
61
62
 
63
+ begin
64
+ user_model_cfg = InlineFormsInstaller::UserModelConfig.from_name(options[:user_model].to_s)
65
+ rescue ArgumentError => e
66
+ say "Error: #{e.message}", :red
67
+ exit 1
68
+ end
69
+
62
70
  inline_forms_version = InlineFormsInstaller.inline_forms_version
63
71
  # The Gemfile pins `gem "inline_forms", "~> 8"`, so Bundler resolves the
64
72
  # highest 8.x available on RubyGems at install time. The
@@ -67,7 +75,8 @@ module InlineFormsInstaller
67
75
  # report the constraint instead of a misleading exact version, and let
68
76
  # `print_create_summary` read the actual locked versions from the
69
77
  # generated app's Gemfile.lock once `bundle install` is done.
70
- say "Creating #{app_name} (inline_forms ~> 8) with development database #{database}...", :green
78
+ user_model_note = user_model_cfg.default? ? "" : " (auth model: #{user_model_cfg.class_name})"
79
+ say "Creating #{app_name} (inline_forms ~> 8) with development database #{database}#{user_model_note}...", :green
71
80
 
72
81
  regex = /\A[0-9a-zA-Z][0-9a-zA-Z_-]+[0-9a-zA-Z]\Z/
73
82
  if !regex.match(app_name)
@@ -3,6 +3,7 @@ require "shellwords"
3
3
  INSTALLER_ROOT = File.expand_path(ENV.fetch("INLINE_FORMS_INSTALLER_ROOT", File.expand_path("..", __dir__)))
4
4
  INLINE_FORMS_ROOT = File.expand_path(ENV.fetch("INLINE_FORMS_ROOT", INSTALLER_ROOT))
5
5
  require File.join(INSTALLER_ROOT, "lib", "inline_forms_installer", "create_log")
6
+ require File.join(INSTALLER_ROOT, "lib", "inline_forms_installer", "user_model_config")
6
7
 
7
8
  def use_app_rvm_gemset!
8
9
  return if ENV["skiprvm"] == "true"
@@ -262,11 +263,16 @@ say "\n *** Please make sure to create a mysql production database and use 'rail
262
263
  say "- Devise install..."
263
264
  run "bundle exec rails g devise:install"
264
265
 
266
+ user_cfg = InlineFormsInstaller::UserModelConfig.from_env
267
+ unless user_cfg.default?
268
+ say "- Auth model #{user_cfg.class_name} (#{user_cfg.table_name} table; Warden scope :user → current_user)", :green
269
+ end
270
+
265
271
  say "- Create Devise route and add path_prefix..."
266
272
 
267
273
  route <<-ROUTE.strip_heredoc
268
- devise_for :users, :path_prefix => 'auth'
269
- resources :users do
274
+ #{user_cfg.devise_route_line}
275
+ resources :#{user_cfg.plural_route} do
270
276
  post 'revert', :on => :member
271
277
  get 'list_versions', :on => :member
272
278
  end
@@ -278,11 +284,11 @@ sleep 1 # to get unique migration number
278
284
  create_file "db/migrate/" +
279
285
  Time.now.utc.strftime("%Y%m%d%H%M%S") +
280
286
  "_" +
281
- "devise_create_users.rb", <<-DEVISE_MIGRATION.strip_heredoc
282
- class DeviseCreateUsers < ActiveRecord::Migration[8.0]
287
+ "#{user_cfg.devise_migration_basename}.rb", <<-DEVISE_MIGRATION.strip_heredoc
288
+ class #{user_cfg.devise_migration_class} < ActiveRecord::Migration[8.0]
283
289
 
284
290
  def change
285
- create_table(:users) do |t|
291
+ create_table(:#{user_cfg.table_name}) do |t|
286
292
  ## Database authenticatable
287
293
  t.string :email, null: false, default: ""
288
294
  t.string :encrypted_password, null: false, default: ""
@@ -318,24 +324,24 @@ class DeviseCreateUsers < ActiveRecord::Migration[8.0]
318
324
  t.timestamps
319
325
  end
320
326
 
321
- add_index :users, :email, unique: true
322
- add_index :users, :reset_password_token, unique: true
323
- # add_index :users, :confirmation_token, unique: true
324
- # add_index :users, :unlock_token, unique: true
327
+ add_index :#{user_cfg.table_name}, :email, unique: true
328
+ add_index :#{user_cfg.table_name}, :reset_password_token, unique: true
329
+ # add_index :#{user_cfg.table_name}, :confirmation_token, unique: true
330
+ # add_index :#{user_cfg.table_name}, :unlock_token, unique: true
325
331
  end
326
332
  end
327
333
  DEVISE_MIGRATION
328
334
 
329
- say "- Create User Controller..."
330
- create_file "app/controllers/users_controller.rb", <<-USERS_CONTROLLER.strip_heredoc
331
- class UsersController < InlineFormsController
332
- set_tab :user
335
+ say "- Create #{user_cfg.class_name} controller..."
336
+ create_file user_cfg.controller_path, <<-USERS_CONTROLLER.strip_heredoc
337
+ class #{user_cfg.controller_name} < InlineFormsController
338
+ set_tab :#{user_cfg.tab_key}
333
339
  end
334
340
  USERS_CONTROLLER
335
341
 
336
- say "- Create User Model..."
337
- create_file "app/models/user.rb", <<-USER_MODEL.strip_heredoc
338
- class User < ApplicationRecord
342
+ say "- Create #{user_cfg.class_name} model..."
343
+ create_file user_cfg.model_path, <<-USER_MODEL.strip_heredoc
344
+ class #{user_cfg.class_name} < ApplicationRecord
339
345
 
340
346
  # devise options
341
347
  devise :database_authenticatable
@@ -350,8 +356,6 @@ create_file "app/models/user.rb", <<-USER_MODEL.strip_heredoc
350
356
  # devise :timeoutable
351
357
  # devise :omniauthable
352
358
 
353
- # Setup accessible (or protected) attributes for your model
354
- attr_writer :inline_forms_attribute_list
355
359
  #attr_accessible :email, :password, :locale, :remember_me
356
360
 
357
361
  belongs_to :locale
@@ -360,13 +364,10 @@ create_file "app/models/user.rb", <<-USER_MODEL.strip_heredoc
360
364
  # validations
361
365
  validates :name, :presence => true
362
366
 
363
- default_scope {order :name}
364
-
365
- # pagination
366
- attr_reader :per_page
367
- @per_page = 7
368
-
369
- has_paper_trail on: [:create, :update, :destroy]
367
+ # Default ordering for inline_forms list views (and any explicit caller
368
+ # via `#{user_cfg.class_name}.inline_forms_list`). Avoids `default_scope`
369
+ # so callers can `unscope`/`reorder` cleanly when needed.
370
+ scope :inline_forms_list, -> { order(:name, :id) }
370
371
 
371
372
  def _presentation
372
373
  "\#{name}"
@@ -400,49 +401,41 @@ create_file "app/models/user.rb", <<-USER_MODEL.strip_heredoc
400
401
  ]
401
402
  end
402
403
 
403
- def self.not_accessible_through_html?
404
- false
405
- end
406
-
407
- def self.order_by_clause
408
- nil
409
- end
410
-
411
404
  end
412
405
  USER_MODEL
413
406
 
414
407
  # Create Locales
415
408
  say "- Create locales"
416
- generate "inline_forms", "Locale name:string title:string users:has_many _enabled:yes _presentation:\#{title}"
409
+ generate "inline_forms", "Locale name:string title:string #{user_cfg.table_name}:has_many _enabled:yes _list_order:title _presentation:\#{title}"
417
410
  append_to_file "db/seeds.rb", "Locale.create({ id: 1, name: 'en', title: 'English' })\n"
418
411
 
419
412
  # Create Roles
420
413
  say "- Create roles"
421
- generate "inline_forms", "Role name:string description:text users:has_and_belongs_to_many _enabled:yes _presentation:\#{name}"
414
+ generate "inline_forms", "Role name:string description:text #{user_cfg.table_name}:has_and_belongs_to_many _enabled:yes _list_order:name _presentation:\#{name}"
422
415
  append_to_file "db/seeds.rb", "Role.create({ id: 1, name: 'superadmin', description: 'Super Admin can access all.' })\n"
423
416
 
424
417
  # Create Admin User
425
418
 
426
- say "- Adding admin user with email: #{ENV['email']}, password: #{ENV['password']} to seeds.rb"
427
- append_to_file "db/seeds.rb", "User.create({ id: 1, email: '#{ENV['email']}', locale_id: 1, name: 'Admin', password: '#{ENV['password']}', password_confirmation: '#{ENV['password']}' })\n"
419
+ say "- Adding admin #{user_cfg.class_name.downcase} with email: #{ENV['email']}, password: #{ENV['password']} to seeds.rb"
420
+ append_to_file "db/seeds.rb", "#{user_cfg.class_name}.create({ id: 1, email: '#{ENV['email']}', locale_id: 1, name: 'Admin', password: '#{ENV['password']}', password_confirmation: '#{ENV['password']}' })\n"
428
421
 
429
422
 
430
423
  sleep 1 # to get unique migration number
431
424
  create_file "db/migrate/" +
432
425
  Time.now.utc.strftime("%Y%m%d%H%M%S") +
433
426
  "_" +
434
- "inline_forms_create_join_table_user_role.rb", <<-ROLES_MIGRATION.strip_heredoc
435
- class InlineFormsCreateJoinTableUserRole < ActiveRecord::Migration[8.0]
427
+ "#{user_cfg.join_migration_basename}.rb", <<-ROLES_MIGRATION.strip_heredoc
428
+ class #{user_cfg.join_migration_class} < ActiveRecord::Migration[8.0]
436
429
  def self.up
437
- create_table :roles_users, :id => false, :force => true do |t|
430
+ create_table :#{user_cfg.join_table}, :id => false, :force => true do |t|
438
431
  t.integer :role_id
439
- t.integer :user_id
432
+ t.integer :#{user_cfg.foreign_key}
440
433
  end
441
- execute 'INSERT INTO roles_users VALUES (1,1);'
434
+ execute 'INSERT INTO #{user_cfg.join_table} VALUES (1,1);'
442
435
  end
443
436
 
444
437
  def self.down
445
- drop_table roles_users
438
+ drop_table #{user_cfg.join_table}
446
439
  end
447
440
  end
448
441
  ROLES_MIGRATION
@@ -457,7 +450,7 @@ copy_file File.join(INLINE_FORMS_ROOT, 'lib/generators/assets/stylesheets/inline
457
450
  say "- Sprockets: link inline_forms_devise.css (logical path; dartsass:install drops link_directory ../stylesheets)..."
458
451
  append_to_file "app/assets/config/manifest.js", "//= link inline_forms_devise.css\n"
459
452
 
460
- say "- Add human_attribute_name in app/models/application_record.rb"
453
+ say "- Install ApplicationRecord (PaperTrail, pagination, inline_forms defaults)..."
461
454
  remove_file 'app/models/application_record.rb' # the one that 'rails new' created
462
455
  copy_file File.join(INLINE_FORMS_ROOT, 'lib/generators/templates/application_record.rb'), "app/models/application_record.rb"
463
456
 
@@ -611,7 +604,7 @@ create_file "app/models/ability.rb", <<-END_ABILITY.strip_heredoc
611
604
  def initialize(user)
612
605
  # See the wiki for details: https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
613
606
 
614
- user ||= User.new # guest user
607
+ user ||= #{user_cfg.class_name}.new # guest user
615
608
 
616
609
  # use this if you get stuck:
617
610
  # if user.id == 1 #quick hack
@@ -712,14 +705,14 @@ git commit: " -a -m 'Initial Commit'"
712
705
  # example
713
706
  if ENV['install_example'] == 'true'
714
707
  say "\nInstalling example application..."
715
- run 'bundle exec rails g inline_forms Photo name:string caption:string image:image_field description:rich_text apartment:belongs_to _presentation:\'#{name}\''
708
+ run 'bundle exec rails g inline_forms Photo name:string caption:string image:image_field description:rich_text apartment:belongs_to _list_order:name _presentation:\'#{name}\''
716
709
  run 'bundle exec rails generate uploader Image'
717
- run 'bundle exec rails g inline_forms Apartment name:string title:string opening_date:date description:rich_text photos:has_many photos:associated _enabled:yes _presentation:\'#{name}\''
710
+ run 'bundle exec rails g inline_forms Apartment name:string title:string opening_date:date description:rich_text photos:has_many photos:associated _enabled:yes _list_order:name _list_search:name _presentation:\'#{name}\''
718
711
 
719
712
  say "- Apartment name is required..."
720
713
  inject_into_file "app/models/apartment.rb",
721
714
  "\n validates :name, presence: true\n",
722
- after: " has_paper_trail on: [:create, :update, :destroy]\n"
715
+ after: "class Apartment < ApplicationRecord\n"
723
716
 
724
717
  # CarrierWave + PaperTrail history.
725
718
  # PaperTrail snapshots the column scalar (the stored filename) on update,
@@ -784,20 +777,7 @@ if ENV['install_example'] == 'true'
784
777
  end
785
778
 
786
779
  say "- Lower Photo.per_page so the seeded gallery paginates..."
787
- # The model template (lib/generators/templates/model.erb) emits
788
- # attr_reader :per_page
789
- # @per_page = 7
790
- # which is a long-standing typo: `attr_reader :per_page` defines an
791
- # *instance* method, then `@per_page = 7` (executed in the class body)
792
- # actively *clobbers* the class-level per_page that will_paginate
793
- # exposes via `class_attribute :per_page` (its singleton-ivar storage
794
- # also lives on `@per_page`). Net effect: nothing reads 7 anywhere,
795
- # and the class-level per_page silently reverts to will_paginate's
796
- # 30-default. Replace the pair on Photo with a real `self.per_page = 5`
797
- # so the seeded gallery (12 photos) actually paginates 5/5/2.
798
- gsub_file "app/models/photo.rb",
799
- /^\s*attr_reader\s+:per_page\s*\n\s*@per_page\s*=\s*\d+\s*\n/,
800
- " self.per_page = 5\n"
780
+ inject_into_class "app/models/photo.rb", "Photo", " self.per_page = 5\n"
801
781
 
802
782
  run 'bundle exec rake db:migrate'
803
783
 
@@ -849,12 +829,12 @@ if ENV['install_example'] == 'true'
849
829
  # shared first field. See OwnersController override below.
850
830
  say "- Generating Owner model (has_many apartments)..."
851
831
  sleep 1
852
- run %q{bundle exec rails g inline_forms Owner name:string birthdate:date address:string city:string country:string apartments:has_many apartments:associated _enabled:yes _presentation:'#{name}'}
832
+ run %q{bundle exec rails g inline_forms Owner name:string birthdate:date address:string city:string country:string apartments:has_many apartments:associated _enabled:yes _list_order:name _list_search:name _presentation:'#{name}'}
853
833
 
854
834
  say "- Owner name is required..."
855
835
  inject_into_file "app/models/owner.rb",
856
836
  "\n validates :name, presence: true\n",
857
- after: " has_paper_trail on: [:create, :update, :destroy]\n"
837
+ after: "class Owner < ApplicationRecord\n"
858
838
 
859
839
  say "- Adding owner_id to apartments + belongs_to :owner..."
860
840
  sleep 1
@@ -869,7 +849,7 @@ if ENV['install_example'] == 'true'
869
849
 
870
850
  inject_into_file "app/models/apartment.rb",
871
851
  " belongs_to :owner, optional: true\n",
872
- after: " has_paper_trail on: [:create, :update, :destroy]\n"
852
+ after: "class Apartment < ApplicationRecord\n"
873
853
 
874
854
  # Insert the :owner dropdown row at the top of Apartment's attribute list
875
855
  # so it appears above :name in the inline panel.
@@ -1060,9 +1040,10 @@ if ENV['install_example'] == 'true'
1060
1040
  route "root :to => 'apartments#index'"
1061
1041
 
1062
1042
  example_tests_root = File.join(INSTALLER_ROOT, "lib/installer_templates/example_app_tests")
1043
+ example_user_cfg = InlineFormsInstaller::UserModelConfig.from_env
1063
1044
  Dir.glob(File.join(example_tests_root, "**", "*.rb")).sort.each do |abs|
1064
1045
  rel = abs.delete_prefix(example_tests_root + File::SEPARATOR).tr("\\", "/")
1065
- create_file rel, File.read(abs)
1046
+ create_file rel, example_user_cfg.adapt_example_test_source(File.read(abs))
1066
1047
  end
1067
1048
 
1068
1049
  say "- Running example regression tests (bundle exec rails test)..."
@@ -0,0 +1,104 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require "active_support/core_ext/string/inflections"
3
+
4
+ module InlineFormsInstaller
5
+ # Devise mapping stays on :users (Warden scope :user → current_user in inline_forms).
6
+ # A custom class (e.g. Member) uses members table, /members routes, and
7
+ # devise_for :users, class_name: "Member", path: "members".
8
+ class UserModelConfig
9
+ DEFAULT_CLASS = "User"
10
+
11
+ def self.from_env(env = ENV)
12
+ from_name(env["user_model"].to_s.strip)
13
+ end
14
+
15
+ def self.from_name(name)
16
+ name = DEFAULT_CLASS if name.empty?
17
+ new(name)
18
+ end
19
+
20
+ def initialize(class_name)
21
+ unless class_name.match?(/\A[A-Z][A-Za-z0-9]*\z/)
22
+ raise ArgumentError, "user model must be a Ruby constant (e.g. User, Member)"
23
+ end
24
+
25
+ @class_name = class_name
26
+ end
27
+
28
+ attr_reader :class_name
29
+
30
+ def default?
31
+ class_name == DEFAULT_CLASS
32
+ end
33
+
34
+ def table_name
35
+ class_name.tableize
36
+ end
37
+
38
+ def plural_route
39
+ table_name
40
+ end
41
+
42
+ def foreign_key
43
+ "#{class_name.underscore}_id"
44
+ end
45
+
46
+ # Rails HABTM join table: plural model names in lexical order (roles_users, members_roles).
47
+ def join_table
48
+ return "roles_users" if default?
49
+
50
+ [table_name, "roles"].sort.join("_")
51
+ end
52
+
53
+ def controller_name
54
+ "#{class_name.pluralize}Controller"
55
+ end
56
+
57
+ def controller_path
58
+ "app/controllers/#{table_name}_controller.rb"
59
+ end
60
+
61
+ def model_path
62
+ "app/models/#{class_name.underscore}.rb"
63
+ end
64
+
65
+ def tab_key
66
+ class_name.underscore.to_sym
67
+ end
68
+
69
+ def devise_migration_basename
70
+ "devise_create_#{table_name}"
71
+ end
72
+
73
+ def devise_migration_class
74
+ "DeviseCreate#{class_name.pluralize}"
75
+ end
76
+
77
+ def join_migration_basename
78
+ "inline_forms_create_join_table_#{class_name.underscore}_role"
79
+ end
80
+
81
+ def join_migration_class
82
+ "InlineFormsCreateJoinTable#{class_name}Role"
83
+ end
84
+
85
+ def devise_route_line
86
+ if default?
87
+ "devise_for :users, :path_prefix => 'auth'"
88
+ else
89
+ "devise_for :users, class_name: \"#{class_name}\", path: \"#{plural_route}\", path_prefix: 'auth'"
90
+ end
91
+ end
92
+
93
+ def sign_in_path_fragment
94
+ "/auth/#{default? ? 'users' : plural_route}/sign_in"
95
+ end
96
+
97
+ def adapt_example_test_source(content)
98
+ return content if default?
99
+
100
+ content = content.gsub("User", class_name)
101
+ content.gsub(%r{/auth/users/sign_in}, sign_in_path_fragment)
102
+ end
103
+ end
104
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding : utf-8 -*-
2
2
  module InlineFormsInstaller
3
- VERSION = "8.0.3"
3
+ VERSION = "8.1.0"
4
4
 
5
5
  # Written into generated apps' `.ruby-version` (must match gemspec `required_ruby_version`).
6
6
  TARGET_RUBY_VERSION = "ruby-4.0.4"
@@ -79,4 +79,5 @@ module InlineFormsInstaller
79
79
  end
80
80
  end
81
81
 
82
+ require "inline_forms_installer/user_model_config"
82
83
  require "inline_forms_installer/creator"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_forms_installer
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.0.3
4
+ version: 8.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ace Suares
@@ -81,6 +81,7 @@ files:
81
81
  - lib/inline_forms_installer/create_log.rb
82
82
  - lib/inline_forms_installer/creator.rb
83
83
  - lib/inline_forms_installer/installer_core.rb
84
+ - lib/inline_forms_installer/user_model_config.rb
84
85
  - lib/inline_forms_installer/version.rb
85
86
  - lib/installer_templates/capistrano/Capfile
86
87
  - lib/installer_templates/capistrano/deploy.rb