module Ros::Console::Methods

Public Class Methods

init() click to toggle source
# File lib/ros/core/console.rb, line 41
def init
  models.each do |model|
    name = File.basename(model).gsub('.rb', '')
    id = name[0]
    define_method("#{id}a") { name.classify.constantize.all }
    define_method("#{id}c") { fbc(name) }
    define_method("#{id}f") { Rails.configuration.x.memoized_shortcuts["#{id}f"] ||= name.classify.constantize.first }
    define_method("#{id}l") { Rails.configuration.x.memoized_shortcuts["#{id}l"] ||= name.classify.constantize.last }
    define_method("#{id}p") { |column| name.classify.constantize.pluck(column) }
  end
end
models() click to toggle source
# File lib/ros/core/console.rb, line 38
def models
  Dir[Pathname.new(Dir.pwd).join('app', 'models', '**', '*.rb')]
end

Public Instance Methods

ct() click to toggle source
# File lib/ros/core/console.rb, line 54
def ct; Rails.configuration.x.memoized_shortcuts[:ct] ||= Tenant.find_by(schema_name: Apartment::Tenant.current) end
fbc(type) click to toggle source
# File lib/ros/core/console.rb, line 29
def fbc(type)
  try_count ||= 0
  FactoryBot.create(type)
rescue KeyError
  try_count += 1
  Dir[Pathname.new(Dir.pwd).join('spec', 'factories', '**', '*.rb')].each { |f| require f }
  retry if try_count < 2
end