balaclava 1.2.0 → 1.3.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 615a1a59eb68a74aebbc7149a5031fcb484a028fd3f0ad6484656ba4b27f2d28
|
4
|
+
data.tar.gz: 6418767ed946a5bfcd6ac90b75e96e063fa1aa203a2a284570fb19a5612eeb22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4fc67434b1f8d510735819dc4bfbe850043444c45d018df9b9f3e0b1f1f339754de2f3675c08e3a437ffe766ee71f69d5e859ec8101b3aa7f90899cb0e926eb1
|
7
|
+
data.tar.gz: 31f3c1771641fa2c01eb699efd427d785b1b4d6d0b722853e863d2c3eb69c5e8b0205756f3d15ff9200882338fd0a3050271a490154dae1afe25f8eaafb0a70d
|
data/lib/balaclava/version.rb
CHANGED
@@ -1,47 +1,61 @@
|
|
1
|
-
require 'rails/generators/active_record'
|
2
|
-
require 'rails/generators/named_base'
|
3
1
|
require 'rails/generators/base'
|
4
2
|
require 'thor/shell'
|
5
3
|
|
6
4
|
module Balaclava
|
7
5
|
module Generators
|
8
|
-
|
9
|
-
# necessary configuration files, models, migrations, and mailers.
|
10
|
-
class InstallGenerator < Rails::Generators::NamedBase
|
6
|
+
class InstallGenerator < Rails::Generators::Base
|
11
7
|
include Thor::Shell
|
8
|
+
|
12
9
|
source_root File.expand_path('templates', __dir__)
|
13
10
|
|
14
11
|
desc "Generates Balaclava configuration files, models, and migrations."
|
15
12
|
|
16
|
-
|
13
|
+
def install
|
14
|
+
ensure_active_record_loaded
|
15
|
+
ask_for_user_model_name
|
16
|
+
create_initializer_file
|
17
|
+
create_model_file
|
18
|
+
create_migration
|
19
|
+
create_mailer
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Ensures ActiveRecord is loaded before proceeding with generator tasks.
|
25
|
+
def ensure_active_record_loaded
|
26
|
+
unless defined?(ActiveRecord)
|
27
|
+
require 'active_record'
|
28
|
+
end
|
29
|
+
puts "ActiveRecord loaded: #{defined?(ActiveRecord)}"
|
30
|
+
end
|
31
|
+
|
17
32
|
def ask_for_user_model_name
|
18
|
-
|
19
|
-
@user_model_name = 'User'
|
33
|
+
answer = ask("What is the name of your user model? [Leave blank for Default: User]")
|
34
|
+
@user_model_name = answer.blank? ? 'User' : answer
|
20
35
|
end
|
21
36
|
|
22
|
-
# Creates an initializer file for Balaclava.
|
23
37
|
def create_initializer_file
|
24
38
|
template 'initializer.rb', 'config/initializers/balaclava.rb'
|
25
39
|
end
|
26
40
|
|
27
|
-
# Generates a model file within the application's models directory.
|
28
41
|
def create_model_file
|
29
|
-
|
42
|
+
@class_name = @user_model_name.camelize # Convert the model name to CamelCase
|
43
|
+
template 'model.rb', File.join('app/models', "#{@user_model_name.underscore}.rb")
|
30
44
|
end
|
31
45
|
|
32
|
-
# Creates a migration file for Balaclava users.
|
33
46
|
def create_migration
|
34
|
-
|
47
|
+
timestamp = Time.now.utc.strftime("%Y%m%d%H%M%S")
|
48
|
+
@migration_filename = "#{timestamp}_create_#{ @user_model_name.underscore.pluralize}.rb"
|
49
|
+
@table_name = @user_model_name.underscore.pluralize
|
50
|
+
@migration_class_name = "Create#{ @user_model_name.camelize.pluralize}"
|
51
|
+
|
52
|
+
template 'migration.rb', File.join('db/migrate', @migration_filename)
|
35
53
|
end
|
36
54
|
|
37
|
-
# Generates a mailer file for Balaclava.
|
38
55
|
def create_mailer
|
39
56
|
template 'mailer.rb', 'app/mailers/balaclava_mailer.rb'
|
40
57
|
end
|
41
58
|
|
42
|
-
private
|
43
|
-
|
44
|
-
# Determines the Rails migration version syntax based on the Rails version.
|
45
59
|
def migration_version
|
46
60
|
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" if Gem::Version.new(Rails.version) >= Gem::Version.new('5.0.0')
|
47
61
|
end
|
@@ -1,12 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
class CreateBalaclavaUsers < ActiveRecord::Migration<%= migration_version %>
|
1
|
+
class <%= @migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
|
4
2
|
def change
|
5
|
-
create_table
|
3
|
+
create_table :<%= @table_name %> do |t|
|
6
4
|
t.string :email
|
7
5
|
t.timestamps
|
8
6
|
end
|
9
7
|
|
10
|
-
add_index
|
8
|
+
add_index :<%= @table_name %>, :email, unique: true
|
11
9
|
end
|
12
10
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
class <%= class_name %> < ApplicationRecord
|
1
|
+
class <%= @class_name %> < ApplicationRecord
|
2
2
|
|
3
|
-
end
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: balaclava
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sante
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mail
|