referral_box 0.1.7 → 0.1.9
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 +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +2 -0
- data/lib/generators/referral_box/install/install_generator.rb +94 -28
- data/lib/referral_box/version.rb +1 -1
- data/logo.png +3 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d94d16e8f914150bbac4001084c46567dba26ce702c3671496f1bfd93537d5aa
|
4
|
+
data.tar.gz: 726b0ce463ca8d89d32d3087a133c38b8d30fea686841951cef5bcd7dd6df25c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05063a5582c13068d7f9ff0afe4137e9377da78b0537804c0a271f7f04811255a1784b521d8e28886d01b35491ca1f1d1c54abb26cc86a0b99771df5691516fd
|
7
|
+
data.tar.gz: 38fb4955c59317e2e362599739c75bc04684bef7b6c90cc1efff2d6ba73c63bae05bdce07754577f96ea74c5f2130decd907853a57938a47500956b62645e549
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,31 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.1.9] - 2025-01-XX
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- **Logo**: Added ReferralBox logo to the gem and README
|
14
|
+
- **Better Model Injection**: Improved generator to handle different model inheritance patterns
|
15
|
+
- **Manual Instructions**: Clear instructions when automatic model injection fails
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
- **Generator Issues**: Fixed "File unchanged" error by improving model method injection logic
|
19
|
+
- **Model Detection**: Better handling of models that inherit from different base classes
|
20
|
+
- **User Experience**: Clearer error messages and manual setup instructions
|
21
|
+
|
22
|
+
## [0.1.8] - 2025-01-XX
|
23
|
+
|
24
|
+
### Added
|
25
|
+
- **Interactive Generator**: Generator now asks for model name and confirms the choice
|
26
|
+
- **Model Detection**: Automatically detects existing models in the app
|
27
|
+
- **Safe Migrations**: Migration now checks if columns exist before adding them
|
28
|
+
- **Duplicate Prevention**: Prevents adding duplicate columns and methods
|
29
|
+
|
30
|
+
### Fixed
|
31
|
+
- **Migration Errors**: Fixed "duplicate column name" errors by adding existence checks
|
32
|
+
- **Generator Flow**: Improved user experience with interactive prompts
|
33
|
+
- **Model Flexibility**: Better support for different model names (User, Customer, Account, etc.)
|
34
|
+
|
10
35
|
## [0.1.7] - 2025-01-XX
|
11
36
|
|
12
37
|
### Added
|
data/README.md
CHANGED
@@ -11,37 +11,78 @@ module ReferralBox
|
|
11
11
|
template "initializer.rb", "config/initializers/referral_box.rb"
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
14
|
+
def ask_for_model_name
|
15
|
+
puts "\n" + "="*60
|
16
|
+
puts "ReferralBox Model Configuration"
|
17
|
+
puts "="*60
|
18
|
+
|
19
|
+
# Detect existing models
|
20
|
+
model_files = Dir.glob("app/models/*.rb")
|
21
|
+
existing_models = model_files.map { |f| File.basename(f, '.rb').classify }
|
22
|
+
|
23
|
+
if existing_models.any?
|
24
|
+
puts "\nExisting models found: #{existing_models.join(', ')}"
|
25
|
+
end
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
|
27
|
+
@model_class = ask("What is your user model class name? (e.g., User, Customer, Account, Member):", default: "User")
|
28
|
+
|
29
|
+
# Confirm the choice
|
30
|
+
puts "\nYou selected: #{@model_class}"
|
31
|
+
confirm = ask("Is this correct? (y/n):", default: "y")
|
32
|
+
|
33
|
+
unless confirm.downcase.start_with?('y')
|
34
|
+
puts "Please run the generator again with the correct model name."
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
|
38
|
+
# Update the initializer with the selected model
|
39
|
+
update_initializer_with_model(@model_class)
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_model_migration
|
43
|
+
if @model_class.present?
|
44
|
+
generate_migration = "AddReferralBoxTo#{@model_class.pluralize}"
|
45
|
+
migration_content = generate_migration_content(@model_class)
|
21
46
|
|
22
47
|
create_file "db/migrate/#{Time.current.strftime('%Y%m%d%H%M%S')}_#{generate_migration.underscore}.rb", migration_content
|
23
48
|
|
24
|
-
puts "
|
49
|
+
puts "\nMigration generated for #{@model_class} model!"
|
25
50
|
puts "Run 'rails db:migrate' to apply it."
|
26
51
|
else
|
27
|
-
puts "Warning: Could not determine model class name
|
52
|
+
puts "Warning: Could not determine model class name."
|
28
53
|
puts "Please manually create migration for your model."
|
29
54
|
end
|
30
55
|
end
|
31
56
|
|
32
57
|
def add_model_methods
|
33
|
-
model_class
|
34
|
-
|
35
|
-
if model_class.present?
|
36
|
-
model_file = "app/models/#{model_class.underscore}.rb"
|
58
|
+
if @model_class.present?
|
59
|
+
model_file = "app/models/#{@model_class.underscore}.rb"
|
37
60
|
|
38
61
|
if File.exist?(model_file)
|
39
|
-
|
40
|
-
|
62
|
+
content = File.read(model_file)
|
63
|
+
|
64
|
+
# Check if methods already exist
|
65
|
+
if content.include?('has_many :referral_box_transactions')
|
66
|
+
puts "ReferralBox methods already exist in #{@model_class} model."
|
67
|
+
else
|
68
|
+
# Try to inject after the class definition
|
69
|
+
if content.match(/class #{@model_class}\s+<\s+ApplicationRecord/)
|
70
|
+
inject_into_file model_file, after: "class #{@model_class} < ApplicationRecord" do
|
71
|
+
"\n " + generate_model_methods(@model_class)
|
72
|
+
end
|
73
|
+
puts "Added ReferralBox methods to #{@model_class} model."
|
74
|
+
elsif content.match(/class #{@model_class}\s+<\s+ActiveRecord::Base/)
|
75
|
+
inject_into_file model_file, after: "class #{@model_class} < ActiveRecord::Base" do
|
76
|
+
"\n " + generate_model_methods(@model_class)
|
77
|
+
end
|
78
|
+
puts "Added ReferralBox methods to #{@model_class} model."
|
79
|
+
else
|
80
|
+
# If we can't find the class definition, show manual instructions
|
81
|
+
show_manual_model_instructions(@model_class)
|
82
|
+
end
|
41
83
|
end
|
42
|
-
puts "Added ReferralBox methods to #{model_class} model."
|
43
84
|
else
|
44
|
-
|
85
|
+
show_manual_model_instructions(@model_class)
|
45
86
|
end
|
46
87
|
end
|
47
88
|
end
|
@@ -60,19 +101,30 @@ module ReferralBox
|
|
60
101
|
|
61
102
|
private
|
62
103
|
|
63
|
-
def
|
64
|
-
|
104
|
+
def show_manual_model_instructions(model_class)
|
105
|
+
puts "\n" + "="*60
|
106
|
+
puts "Manual Model Setup Required"
|
107
|
+
puts "="*60
|
108
|
+
puts "\nPlease manually add the following methods to your #{model_class} model:"
|
109
|
+
puts "\nFile: app/models/#{model_class.underscore}.rb"
|
110
|
+
puts "\nAdd this inside your #{model_class} class:"
|
111
|
+
puts "\n" + generate_model_methods(model_class)
|
112
|
+
puts "\n" + "="*60
|
113
|
+
end
|
114
|
+
|
115
|
+
def update_initializer_with_model(model_class)
|
65
116
|
initializer_path = "config/initializers/referral_box.rb"
|
66
117
|
|
67
118
|
if File.exist?(initializer_path)
|
68
119
|
content = File.read(initializer_path)
|
69
|
-
|
70
|
-
|
71
|
-
|
120
|
+
updated_content = content.gsub(
|
121
|
+
/config\.reference_class_name\s*=\s*['"][^'"]*['"]/,
|
122
|
+
"config.reference_class_name = '#{model_class}'"
|
123
|
+
)
|
124
|
+
|
125
|
+
File.write(initializer_path, updated_content)
|
126
|
+
puts "Updated initializer with #{model_class} model."
|
72
127
|
end
|
73
|
-
|
74
|
-
# Default to 'User' if not found
|
75
|
-
'User'
|
76
128
|
end
|
77
129
|
|
78
130
|
def generate_migration_content(model_class)
|
@@ -81,11 +133,25 @@ module ReferralBox
|
|
81
133
|
|
82
134
|
class AddReferralBoxTo#{model_class.pluralize} < ActiveRecord::Migration[#{get_rails_version}]
|
83
135
|
def change
|
84
|
-
|
85
|
-
|
86
|
-
|
136
|
+
# Add referral_code column if it doesn't exist
|
137
|
+
unless column_exists?(:#{model_class.underscore.pluralize}, :referral_code)
|
138
|
+
add_column :#{model_class.underscore.pluralize}, :referral_code, :string
|
139
|
+
end
|
140
|
+
|
141
|
+
# Add tier column if it doesn't exist
|
142
|
+
unless column_exists?(:#{model_class.underscore.pluralize}, :tier)
|
143
|
+
add_column :#{model_class.underscore.pluralize}, :tier, :string
|
144
|
+
end
|
145
|
+
|
146
|
+
# Add referrer reference if it doesn't exist
|
147
|
+
unless column_exists?(:#{model_class.underscore.pluralize}, :referrer_id)
|
148
|
+
add_reference :#{model_class.underscore.pluralize}, :referrer, null: true, foreign_key: { to_table: :#{model_class.underscore.pluralize} }
|
149
|
+
end
|
87
150
|
|
88
|
-
|
151
|
+
# Add unique index on referral_code if it doesn't exist
|
152
|
+
unless index_exists?(:#{model_class.underscore.pluralize}, :referral_code)
|
153
|
+
add_index :#{model_class.underscore.pluralize}, :referral_code, unique: true
|
154
|
+
end
|
89
155
|
end
|
90
156
|
end
|
91
157
|
MIGRATION
|
data/lib/referral_box/version.rb
CHANGED
data/logo.png
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
|
2
|
+
RequestId:0c3a4660-c01e-00b0-62e3-fecd34000000
|
3
|
+
Time:2025-07-27T10:47:25.3812938Z</Message><AuthenticationErrorDetail>Signed expiry time [Sun, 27 Jul 2025 01:33:43 GMT] must be after signed start time [Sun, 27 Jul 2025 10:47:25 GMT]</AuthenticationErrorDetail></Error>
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: referral_box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kapil Dev Pal
|
@@ -185,6 +185,7 @@ files:
|
|
185
185
|
- lib/referral_box/models/referral_log.rb
|
186
186
|
- lib/referral_box/models/transaction.rb
|
187
187
|
- lib/referral_box/version.rb
|
188
|
+
- logo.png
|
188
189
|
homepage: https://github.com/KapilDevPal/referral_box
|
189
190
|
licenses:
|
190
191
|
- MIT
|