module ConsoleUtils
Rails Console Utils¶ ↑
Collection of utilities to use in Rails Console.
Modules¶ ↑
ActiveRecordUtils
-
useful console methods for
ActiveRecord::Base
models BenchUtils
-
benchmark shorthands
RequestUtils
-
tools to make local and remote JSON API requests with json response body formatting and automatic auth (currently supports only token auth).
OtherUtils
-
uncategorized collection of methods
Configuration¶ ↑
Parameters are changable by the config.console_utils
key inside the app's configuration block. It is also available as ConsoleUtils.configure(&block)
in the custom initializer.
Constants
- JSON_FORMATTERS
- MODULES
Class Methods
↑ topConstants
- VERSION
Public Class Methods
auto_token_for(id)
click to toggle source
# File lib/console_utils.rb, line 196 def auto_token_for(id) user = find_user(id, scope: user_model.select([:id, user_token_column])) user.public_send(user_token_column) end
configure() { || ... }
click to toggle source
:method: self.configure
# File lib/console_utils.rb, line 156 def configure # :yields: yield(config) end
enabled_modules() { || ... }
click to toggle source
# File lib/console_utils.rb, line 160 def enabled_modules # :yields: unless block_given? return to_enum(__method__) { ConsoleUtils::MODULES.size - disabled_modules.size } end (ConsoleUtils::MODULES - disabled_modules).each do |mod| yield(const_get(mod)) end end
find_user(id, scope: nil)
click to toggle source
Finds user_model
by user_primary_key
. If the first argument is :any
, gets a random user.
# File lib/console_utils.rb, line 186 def find_user(id, scope: nil) if id == :any user_scope(scope).anyone.tap do |u| puts "random user #{user_primary_key}: #{u.public_send(user_primary_key)}" end else user_scope(scope).where(user_primary_key => id).first! end end
pastel()
click to toggle source
# File lib/console_utils.rb, line 211 def pastel @pastel ||= Pastel.new end
pry!()
click to toggle source
Setup enabled modules for Pry context
# File lib/console_utils.rb, line 202 def pry! setup_modules_to(TOPLEVEL_BINDING.eval('self')) end
setup_modules_to(context = nil)
click to toggle source
Setup enabled modules by extending given context
# File lib/console_utils.rb, line 207 def setup_modules_to(context = nil) ReplState.setup(context) end
user_model()
click to toggle source
Returns User's class set in the :user_class_name
# File lib/console_utils.rb, line 171 def user_model Object.const_get(user_model_name) end
Also aliased as: user_class
user_scope(scope = nil)
click to toggle source
# File lib/console_utils.rb, line 176 def user_scope(scope = nil) case scope when nil then user_model when Symbol then user_model.public_send(scope) else user_model.all.merge(scope) end end