Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rails 6 #80

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b83d54c
fake rows
cj Mar 8, 2014
237d497
change gem name
cj Jul 8, 2014
5522357
restores the original name of gem
bernespinoza Sep 18, 2018
9decd04
Merge pull request #1 from acdcorp/feature/rollback-name
bernespinoza Sep 18, 2018
78dd600
adds columns type support for active_record 4.2.x or superior. Fixes …
bernespinoza Sep 18, 2018
5d7a7eb
Merge pull request #2 from acdcorp/feature/support_active_record_type
bernespinoza Sep 18, 2018
a3a8bdc
bumps acdcorp version to 0.3.8
bernespinoza Sep 18, 2018
1492972
Merge pull request #3 from acdcorp/feature/bump-version-to-0.3.8
bernespinoza Sep 18, 2018
90e777b
set activerecord version to latest/stable 4.2 and refactors Gemfile a…
bernespinoza Sep 18, 2018
addf16d
documented activerecord support version by branches
bernespinoza Sep 18, 2018
0128e0c
Merge pull request #4 from acdcorp/feature/activerecord-version
bernespinoza Sep 18, 2018
3c34401
bumps mini_record version to 0.3.9
bernespinoza Sep 18, 2018
624c89b
Merge pull request #5 from acdcorp/feature/bumps-to-0.3.9
bernespinoza Sep 18, 2018
4279918
updates the branch name for 0.3 stable version
bernespinoza Sep 18, 2018
d2f4670
Merge pull request #6 from acdcorp/feature/fix-stable-branch-description
bernespinoza Sep 18, 2018
7d377fb
bumps version to 0.3.10
bernespinoza Sep 18, 2018
6229c3e
Merge pull request #7 from acdcorp/feature/bumps-to-v0.3.10
bernespinoza Sep 18, 2018
e261e64
updates activerecord version to 4.2.11
bernespinoza Mar 24, 2021
4ed5c17
Merge pull request #8 from acdcorp/feature/active-record-latest
bernespinoza Mar 31, 2021
0d5e5e9
fixes readme file and versions instructions
bernespinoza Mar 31, 2021
10c8441
Merge pull request #9 from acdcorp/feature/fix-readme-file
bernespinoza Mar 31, 2021
e1091a8
adds support for active record 6.1
bernespinoza Aug 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
source "http://rubygems.org"

# Specify your gem's dependencies in mini_record.gemspec
gem 'rake'
gem 'minitest'
gem 'sqlite3'
gem 'mysql2'
gem 'mysql'
gem 'pg'
gem 'activerecord', '<= 3.2'

group :test do
gem 'foreigner', '>= 1.4.2'
end

gemspec
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,31 @@ class Fox < ActiveRecord::Base
end
```

## Versions

### ActiveRecord 4.0.5 or lower

If you are using ruby 2.1 and activerecord lower than or equal to 4.0.5 please
use [fork-stable](https://github.com/acdcorp/mini_record/tree/fork-stable) or
[0.3.7 tag/version](https://github.com/acdcorp/mini_record/tree/v0.3.7)

### ActiveRecord >= 4.0.5 <= 4.2.10 and Ruby >= 2.3

Please use this branch [0.3-acdcorp-stable](https://github.com/acdcorp/mini_record/tree/0.3-acdcorp-stable)


### ActiveRecord 4.2.11 ruby 2.5.5 and 2.6.6

Please use branch [0.3.11-acdcorp-activerecord4.2.11](https://github.com/acdcorp/mini_record/tree/0.3.11-acdcorp-activerecord4.2.11)

## Development

Master is the development branch of this gem for acdcorp because we can't
change the official mini_record gem version unless we push our custom
development.

Current version support Rails 6.0.1

## Author

DAddYE, you can follow me on twitter [@daddye](http://twitter.com/daddye) or take a look at my site [daddye.it](http://www.daddye.it)
Expand Down
55 changes: 54 additions & 1 deletion lib/mini_record/auto_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ def self.included(base)
end

module ClassMethods

def init_table_definition(connection)
#connection.create_table(table_name) unless connection.table_exists?(table_name)

case ActiveRecord::ConnectionAdapters::TableDefinition.instance_method(:initialize).arity
when 1
# Rails 3.2 and earlier
ActiveRecord::ConnectionAdapters::TableDefinition.new(connection)
when 4
when 4, -5
# Rails 4
ActiveRecord::ConnectionAdapters::TableDefinition.new(connection.native_database_types, table_name, false, {})
else
raise ArgumentError,
"Unsupported number of args for ActiveRecord::ConnectionAdapters::TableDefinition.new()"
end

end

def schema_tables
Expand Down Expand Up @@ -72,14 +74,65 @@ def fields_in_db
end
end

def columns_hash
if mini_record_fake_columns
super.merge mini_record_fake_columns
else
super
end
end

def mini_record_columns
@@_mr_columns ||= {}
@@_mr_columns[table_name] ||= {}
end

def mini_record_fake_columns
@@_mr_fake_columns ||= {}
@@_mr_fake_columns[table_name] ||= {}
end

# Lookup for registered ActiveRecord Types
# This in important for rails 4 and 5 due to ActiveRecord converts
# columns into object with the column type. Types depends from Connection
# Adapter.
# activerecord/lib/active_record/type/
# active_record/connection_adapters
# initialize_type_map defined the available types depending of
# database adapter.
def lookup_cast_type(type)
connection.lookup_cast_type(type)
end

def field(*args)
return unless connection?

options = args.extract_options!
type = options.delete(:as) || options.delete(:type) || :string
index = options.delete(:index)
fake = options.delete(:fake) || false

args.each do |column_name|
# add it it the mini record columns for this table so we can access
# special fields like input_as, used by form builders
mini_record_columns[column_name] = options

if fake
# allow you to access the field on the instance object
attr_accessor column_name
# ActiveRecord 4.2.x maps columns into types.
# Create a column symbol as type produced
# undefined method `type_cast_from_database' for :[boolean|string]:Symbol
type = lookup_cast_type(type) if defined?(ActiveRecord::Type)
# create a column that column_hashes will understand (a fake row)
fake_column = ActiveRecord::ConnectionAdapters::Column.new(
column_name.to_s, nil, type, true
)
# add it to the list of fake columns for this table
mini_record_fake_columns[column_name.to_s] = fake_column
# skip everything else as it's a fake column and don't want it in the db
next
end

# Allow custom types like:
# t.column :type, "ENUM('EMPLOYEE','CLIENT','SUPERUSER','DEVELOPER')"
Expand Down
2 changes: 1 addition & 1 deletion lib/mini_record/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module MiniRecord
VERSION = "0.3.7"
VERSION = "0.3.10"
end
9 changes: 8 additions & 1 deletion mini_record.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,12 @@ Gem::Specification.new do |s|

# specify any dependencies here; for example:
# s.add_development_dependency "rspec"
s.add_dependency "activerecord", ">=3.2.0"
s.add_runtime_dependency "activerecord", '~> 6.1.0'

s.add_development_dependency 'rake'
s.add_development_dependency 'minitest'
s.add_development_dependency 'sqlite3'
s.add_development_dependency 'mysql2'
s.add_development_dependency 'pg'
s.add_development_dependency 'foreigner', '>= 1.4.2'
end