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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b232d0c39b152774ce3e521e1bfd5b49e12f4403b913391fdbdc0ef91684c07a
4
- data.tar.gz: 8623def044d02bcfe7aaac01382c25bcac0a78fc87c9cda64f24cba20825cd4f
3
+ metadata.gz: d94d16e8f914150bbac4001084c46567dba26ce702c3671496f1bfd93537d5aa
4
+ data.tar.gz: 726b0ce463ca8d89d32d3087a133c38b8d30fea686841951cef5bcd7dd6df25c
5
5
  SHA512:
6
- metadata.gz: 15df1bb9559552c3648c30b667c73649b3af655296eb2206e4519779685d0d56733580d4f7d65395245911c6799985a2d432f74ade66652eea35f7f9c65c0d98
7
- data.tar.gz: 1831e708802b59d48cfa08611c0fcc444a96307f42d5e3cdd840052b855449d503e978931b6605d35a406cd0f987cb420e91d4bf7a04935c5881338113258f6f
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
@@ -1,5 +1,7 @@
1
1
  # ReferralBox 📦
2
2
 
3
+ ![ReferralBox Logo](logo.png)
4
+
3
5
  A flexible Ruby gem for building loyalty and referral systems in Rails apps.
4
6
 
5
7
  * 🎁 Reward users with points based on their activity
@@ -11,37 +11,78 @@ module ReferralBox
11
11
  template "initializer.rb", "config/initializers/referral_box.rb"
12
12
  end
13
13
 
14
- def add_model_migration
15
- # Read the configuration to determine the model class name
16
- model_class = get_model_class_name
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
- if model_class.present?
19
- generate_migration = "AddReferralBoxTo#{model_class.pluralize}"
20
- migration_content = generate_migration_content(model_class)
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 "Migration generated for #{model_class} model!"
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 from configuration."
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 = get_model_class_name
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
- inject_into_file model_file, after: "class #{model_class} < ApplicationRecord" do
40
- "\n " + generate_model_methods(model_class)
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
- puts "Warning: #{model_file} not found. Please manually add ReferralBox methods to your #{model_class} model."
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 get_model_class_name
64
- # Try to read from existing initializer first
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
- if match = content.match(/config\.reference_class_name\s*=\s*['"]([^'"]+)['"]/)
70
- return match[1]
71
- end
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
- add_column :#{model_class.underscore.pluralize}, :referral_code, :string
85
- add_column :#{model_class.underscore.pluralize}, :tier, :string
86
- add_reference :#{model_class.underscore.pluralize}, :referrer, null: true, foreign_key: { to_table: :#{model_class.underscore.pluralize} }
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
- add_index :#{model_class.underscore.pluralize}, :referral_code, unique: true
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReferralBox
4
- VERSION = "0.1.7"
4
+ VERSION = "0.1.9"
5
5
  end
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.7
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