Skip to content

Commit

Permalink
Make GeneratedAttribute work without ActiveRecord
Browse files Browse the repository at this point in the history
If GeneratedAttribute is used in a project that doesn't require
ActiveRecord, it should still work.

Co-authored-by: Ryuta Kamizono <kamipo@gmail.com>
  • Loading branch information
p8 and kamipo committed Sep 15, 2023
1 parent ed9248d commit 5d31d33
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion railties/lib/rails/generators/generated_attribute.rb
Expand Up @@ -65,11 +65,13 @@ def parse(column_definition)
end

def dangerous_name?(name)
ActiveRecord::Base.dangerous_attribute_method?(name)
defined?(ActiveRecord::Base) &&
ActiveRecord::Base.dangerous_attribute_method?(name)
end

def valid_type?(type)
DEFAULT_TYPES.include?(type.to_s) ||
!defined?(ActiveRecord::Base) ||
ActiveRecord::Base.connection.valid_type?(type)
end

Expand Down

0 comments on commit 5d31d33

Please sign in to comment.