Class: Koi::ActiveRecordGenerator

Inherits:
ActiveRecord::Generators::ModelGenerator
  • Object
show all
Defined in:
lib/generators/koi/active_record/active_record_generator.rb

Instance Method Summary collapse

Instance Method Details

#admin_searchObject



9
10
11
# File 'lib/generators/koi/active_record/active_record_generator.rb', line 9

def admin_search
  "PgSearch::Model".safe_constantize ? pg_search : sql_search
end

#ordinal_scopeObject



13
14
15
16
17
18
19
20
21
# File 'lib/generators/koi/active_record/active_record_generator.rb', line 13

def ordinal_scope
  return unless attributes.any? { |attr| attr.name == "ordinal" }

  insert_into_file "app/models/#{file_path}.rb", before: /end\Z/ do
    <<~RUBY
      default_scope -> { order(ordinal: :asc) }
    RUBY
  end
end