diff --git a/lib/active_graph.rb b/lib/active_graph.rb index 878e133cc..3a508f188 100644 --- a/lib/active_graph.rb +++ b/lib/active_graph.rb @@ -29,13 +29,12 @@ require 'rails/generators/active_model' require 'rails/generators/named_base' require 'rails/railtie' + require File.expand_path('rails/generators/migration_helper.rb', __dir__) end loader = Zeitwerk::Loader.for_gem -unless defined?(Rails) - loader.ignore(File.expand_path('active_graph/generators', __dir__)) - loader.ignore(File.expand_path('active_graph/railtie.rb', __dir__)) -end +loader.ignore(File.expand_path('rails', __dir__)) +loader.ignore(File.expand_path('active_graph/railtie.rb', __dir__)) loader.inflector.inflect("ansi" => "ANSI") loader.setup # loader.eager_load diff --git a/lib/active_graph/generators/active_model.rb b/lib/active_graph/generators/active_model.rb deleted file mode 100644 index 7c4150107..000000000 --- a/lib/active_graph/generators/active_model.rb +++ /dev/null @@ -1,33 +0,0 @@ -class ActiveGraph::Generators::ActiveModel < Rails::Generators::ActiveModel #:nodoc: - def self.all(klass) - "#{klass}.all" - end - - def self.find(klass, params = nil) - "#{klass}.find(#{params})" - end - - def self.build(klass, params = nil) - if params - "#{klass}.new(#{params})" - else - "#{klass}.new" - end - end - - def save - "#{name}.save" - end - - def update_attributes(params = nil) - "#{name}.update_attributes(#{params})" - end - - def errors - "#{name}.errors" - end - - def destroy - "#{name}.destroy" - end -end diff --git a/lib/active_graph/generators/generated_attribute.rb b/lib/active_graph/generators/generated_attribute.rb deleted file mode 100644 index ba92177c6..000000000 --- a/lib/active_graph/generators/generated_attribute.rb +++ /dev/null @@ -1,17 +0,0 @@ -module ActiveGraph - module Generators - module GeneratedAttribute #:nodoc: - def type_class - case type.to_s.downcase - when 'any' then 'any' - when 'datetime' then 'DateTime' - when 'date' then 'Date' - when 'integer', 'number', 'fixnum' then 'Integer' - when 'float' then 'Float' - else - 'String' - end - end - end - end -end diff --git a/lib/rails/generators/migration_helper.rb b/lib/rails/generators/migration_helper.rb index da7c980a2..5a2df2875 100644 --- a/lib/rails/generators/migration_helper.rb +++ b/lib/rails/generators/migration_helper.rb @@ -1,3 +1,8 @@ +module ActiveGraph + module Generators #:nodoc: + end +end + module ActiveGraph::Generators::MigrationHelper extend ActiveSupport::Concern @@ -44,3 +49,55 @@ def migration_template(template_name, prefix = '') FileUtils.rm(real_file_name) if @behavior == :revoke end end + +class ActiveGraph::Generators::ActiveModel < Rails::Generators::ActiveModel #:nodoc: + def self.all(klass) + "#{klass}.all" + end + + def self.find(klass, params = nil) + "#{klass}.find(#{params})" + end + + def self.build(klass, params = nil) + if params + "#{klass}.new(#{params})" + else + "#{klass}.new" + end + end + + def save + "#{name}.save" + end + + def update_attributes(params = nil) + "#{name}.update_attributes(#{params})" + end + + def errors + "#{name}.errors" + end + + def destroy + "#{name}.destroy" + end +end + +module ActiveGraph + module Generators + module GeneratedAttribute #:nodoc: + def type_class + case type.to_s.downcase + when 'any' then 'any' + when 'datetime' then 'DateTime' + when 'date' then 'Date' + when 'integer', 'number', 'fixnum' then 'Integer' + when 'float' then 'Float' + else + 'String' + end + end + end + end +end