welcome_application_record 1.0.0 → 1.0.1
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/lib/welcome_application_record.rb +12 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7c3032723eaef29004f7ca22fa3c195138220f3
|
4
|
+
data.tar.gz: 71b8365183a75ac778b3dd4ed456e0573a67df45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31e3ecc68e76dd08517f6ed7591b739e5c858f7bf9a87ce7cc51973dea022dfc1a73b253e6e35cb494f627023a97fb04b8658b9b6c4388b778b743ba95a3aaf9
|
7
|
+
data.tar.gz: 5cb7562b0755ef0924b32c9d713955ef29558a96716d40ffa6e2217cc141a47ee199c91ac4df18008bcd28487146b99debb99f479bc110ee0c6fa83acebc7e9a
|
@@ -1,14 +1,23 @@
|
|
1
1
|
class WelcomeApplicationRecord
|
2
2
|
def self.perform
|
3
|
-
|
4
|
-
|
5
|
-
File.open("#{
|
3
|
+
project_path = `pwd`
|
4
|
+
project_path = project_path.delete("\n")
|
5
|
+
File.open("#{project_path}/app/models/application_record.rb", "w") do |f|
|
6
6
|
f << "class ApplicationRecord < ActiveRecord::Base\n"
|
7
7
|
f << " self.abstract_class = true\n"
|
8
8
|
f << "end"
|
9
9
|
end
|
10
|
+
|
11
|
+
model_files = Dir["#{project_path}/app/models/*.rb"]
|
12
|
+
model_files.each do |file_path|
|
13
|
+
current_content = File.read(file_path)
|
14
|
+
replace_content = current_content.gsub("< ActiveRecord::Base", "< ApplicationRecord")
|
15
|
+
File.open(file_path, "w"){|f| f.puts(replace_content)}
|
16
|
+
end
|
17
|
+
|
10
18
|
system "echo", "-e", "\e[92mYour ApplicationRecord was successfully created!"
|
11
19
|
rescue Exception => e
|
12
20
|
system "echo", "-e", "\e[91m#{e.message}"
|
21
|
+
system "echo", "-e", "\e[91mMake sure you're in the right place and your project have /app/models directory!"
|
13
22
|
end
|
14
23
|
end
|