ar_to_ar 0.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +32 -0
- data/Rakefile +10 -0
- data/ar_to_ar.gemspec +26 -0
- data/bin/ar_to_ar +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/ar_to_ar.rb +59 -0
- data/lib/ar_to_ar/application_record_template.rb +3 -0
- data/lib/ar_to_ar/version.rb +3 -0
- metadata +104 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 023afa7b960f5c98a1053679f99163deb1b21232
|
4
|
+
data.tar.gz: f2d265e1e86a508388d37d9edb7de026eb450a30
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 065b7546a7ec128daf3d5ecca46f52477789b7f3aeded17d0d1704002e0b9fb13e1188a559a7048cd5ec50eba72cb577217734fb615852a81cde68bf7cb8e9a6
|
7
|
+
data.tar.gz: 0636ab8ca453529e6877ff72c0a0f3d90333b158af9a13e3b4284ca07e37a3828f7c2840bd4627d071cb59cea64cc7af751f9f00848a80914372ebcfc0b65937
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Rishi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# ArToAr
|
2
|
+
|
3
|
+
One of the notable changes in Rails 5 is that models now inherit from ApplicationRecord instead of ActiveRecord::Base. So this gem helps you avoid the manual labour of changing each and every model in your rails project. Instead just use the command line tool available through this gem.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'ar_to_ar'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install ar_to_ar
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Run this command on the terminal at the root of your Rails project.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
ar_to_ar
|
27
|
+
```
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/rishijain/ar_to_ar.
|
32
|
+
|
data/Rakefile
ADDED
data/ar_to_ar.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ar_to_ar/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ar_to_ar"
|
8
|
+
spec.version = ArToAr::VERSION
|
9
|
+
spec.authors = ["Rishi Jain"]
|
10
|
+
spec.email = ["rishi@joshsoftware.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Change ActiveRecord to ApplicationRecord}
|
13
|
+
spec.description = %q{When migrating to Rails 5, all models needs to be changed and application_record.rb needs to be added}
|
14
|
+
spec.homepage = "https://github.com/rishijain/ar_to_ar"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "bin"
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "minitest", '~> 0'
|
24
|
+
|
25
|
+
spec.license = 'MIT'
|
26
|
+
end
|
data/bin/ar_to_ar
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "ar_to_ar"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/ar_to_ar.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "ar_to_ar/version"
|
2
|
+
require "fileutils"
|
3
|
+
|
4
|
+
|
5
|
+
module ArToAr
|
6
|
+
class ActiveRecordToApplicationRecord
|
7
|
+
|
8
|
+
def initialize look_up_path=nil
|
9
|
+
@current_path = look_up_path || Dir.pwd
|
10
|
+
@all_file_names = Dir["#{@current_path}/app/models/*.rb"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def start!
|
14
|
+
@all_file_names.each do |file_name|
|
15
|
+
matched_line = new_line = nil
|
16
|
+
matched_line = find_matched_line file_name
|
17
|
+
next if matched_line.nil?
|
18
|
+
model_name = find_model_name matched_line
|
19
|
+
new_content = get_new_content model_name
|
20
|
+
replace_content file_name, matched_line, new_content
|
21
|
+
end
|
22
|
+
|
23
|
+
copy_application_record_template
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
#this method finds the line in app/models/*.rb which matches
|
29
|
+
#class ModelName < ActiveRecord::Base
|
30
|
+
def find_matched_line(file_path)
|
31
|
+
File.open(file_path, "r++") do |file|
|
32
|
+
return file.find { |line| line.match /(class(.+)<\s*ActiveRecord::Base)/ }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
#line_of_interest is basically line of format
|
37
|
+
#class ModelName < ActiveRecord::Base
|
38
|
+
#this gets returned by find_matched_line method
|
39
|
+
def find_model_name line_of_interest
|
40
|
+
model_name = line_of_interest.split('class ').last.split('<')[0]
|
41
|
+
model_name = model_name.strip if model_name
|
42
|
+
model_name
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_new_content model_name
|
46
|
+
"class #{model_name} < ApplicationRecord\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
def replace_content file_path, old_content, new_content
|
50
|
+
file_text = File.read file_path
|
51
|
+
sub_content = file_text.gsub old_content, new_content
|
52
|
+
File.open(file_path, "w") {|file| file.puts sub_content}
|
53
|
+
end
|
54
|
+
|
55
|
+
def copy_application_record_template
|
56
|
+
FileUtils.cp "#{File.expand_path(File.dirname(__FILE__))}/ar_to_ar/application_record_template.rb", "#{@current_path}/app/models/application_record.rb"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ar_to_ar
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rishi Jain
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: When migrating to Rails 5, all models needs to be changed and application_record.rb
|
56
|
+
needs to be added
|
57
|
+
email:
|
58
|
+
- rishi@joshsoftware.com
|
59
|
+
executables:
|
60
|
+
- ar_to_ar
|
61
|
+
- console
|
62
|
+
- setup
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- .travis.yml
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- ar_to_ar.gemspec
|
73
|
+
- bin/ar_to_ar
|
74
|
+
- bin/console
|
75
|
+
- bin/setup
|
76
|
+
- lib/ar_to_ar.rb
|
77
|
+
- lib/ar_to_ar/application_record_template.rb
|
78
|
+
- lib/ar_to_ar/version.rb
|
79
|
+
homepage: https://github.com/rishijain/ar_to_ar
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.2.2
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Change ActiveRecord to ApplicationRecord
|
103
|
+
test_files: []
|
104
|
+
has_rdoc:
|