...it now looks like this: class BaseUploader module DoesStrictTypeValidations as_trait do def revalidate(*) return unless file check_content_type_allowlist!(file) # This was check_content_type_whitelist! before
...versions have not been initialized by store!, their file methods will at this point return nil. You most likely want to remove these stale files as soon as a new...
...the end goal is clearly described and sufficient context is provided. Example Create notification.resolver.ts: Return the state$ property from the notification service: Use an async resolver; Update overview.component.ts: Replace injected...
...same applies for providing expected types, for example of a function signature or the return value. Information-Dense Keywords Actions: create, update, delete, edit, mirror, move, replace, refactor, add, ...
...n] -- Steps into blocks or methods n times. If you accidentally stepped, you can return with finish 1. next [n] -- Runs n lines of code within the same frame
...find out the numbers finish [n] -- Runs the program until the n-th frame returns up -- Moves to a higher frame in the stack trace down -- Moves to a lower...
...metadata enabled (default since Rails 6). On mismatching purpose, #decrypt_and_verify will simply return nil. def decrypt_session_cookie(cookie_string) return if cookie_string.blank? cipher = ActiveSupport::MessageEncryptor.default_cipher
...between the two methods is that unresolvable constants raise an error with constantize, but return nil with safe_constantize. If you validate the input string against an allowlist, an error...
...not correspond to a valid constant or if the constant is not accessible, it returns nil: "String".safe_constantize # => String "NonExistentClass".safe_constantize # => nil "Module::ExistingClass".safe_constantize # => Module::ExistingClass...
Unit test with error describe UsersHelper do describe '#user_display_name' do it 'returns the first and last name of a user' do user = FactoryBot.create(:user) allow(helper).to...
...receive(:current_user).and_return(user) expect(helper.user_display_name).to eq('Jim Knopf') end end end Error: does not implement: current_user Solutions RSpec >= 3.6 Unit test fixed with...
...to run code when an element is removed from the DOM. When your compiler returns a function, it is called when the element is detached from the DOM: compiler('textarea.wysiwyg...
let editor = new SuperEditor(select) return () => editor.shutdown...
const controller = new CustomDirectUploadController(input, input.files[0]) controller.start(storedInput) } const hasFile = function() { return (storedInput?.value !== undefined && storedInput?.value !== '') || input.value !== '' } const updateClearButton = function() { clearButton.classList.toggle('visually-hidden', !hasFile()) // Make sure...
...app/models/test.rb +++ app/models/test.rb @@ -19,6 +19,10 @@ module RoutingFilter path = Rails.root / 'app' + if true + + end + return path (1/1) Discard this hunk from worktree [y,n,q,a,d,e,?]? ?
...may also provide a block that inspects an error object. To ignore the error, return a truthy value: BrowserConsole.ignore do |error| error.message.size < 100 end Default ignore rules By default BrowserConsole...
...Relation#traverse_association(*names) Edge Rider gives your relations a method #traverse_association which returns a new relation by "pivoting" around a named association. You can traverse multiple associations in...
...users WHERE sites.user_id = sites.id AND users.name = 'Bruce' It now uses these IDs to return a new relation that has no joins and a single condition on the id column...
...pool has a "reaper thread" that periodically looks for connections from inactive threads and returns them to the pool. By default the reaper runs once every 60 seconds. You can...
Will the pool ever close an unused connection? A released connection will be returned to the pool, but not disconnect from the database server. The connection will remain connected...
...created_at: 2.days.ago..), including orphan checks via where.missing(...). Important The inverted scope will not return rows where role is NULL, since in NOT NULL equals NULL in SQL. If this...
...the database adapter gives you methods like select_rows or select_all. These methods return query results as simple arrays, hashes, strings, numbers, etc.: select_all('SELECT * FROM articles') # => [ { 'name...
...an uncommon way to retrieve a file using selenium where JavaScript is used to return a binary data array to Ruby code. The following code example retrieves a PDF but...
...array of 8-bit unsigned integers # => [37, 208, 212, ...] const unsingedInt8Array = new Uint8Array(arrayBuffer) return unsingedInt8Array JS # convert the array we got from JS into a binary string which we...
...receive a locale parameter from a matching URL segment. Before Rails 7.1, this method returned all associated routes (as enumerable) and the using methods iterated over them. As the using...
...methods like serve do not actually need all routes, but may return early, a change has been introduced to add lazy behavior by adding an iterator block and yielding. This...
...named groups in Regex Exercises Find words Write a method second_words(string) that returns the second word of every sentence in the given string. Tip You can generate paragraphs...
...accessor sit on the same line. The superclass may be optional. ClassScanner#superclass should return nil in that case. Info In practice we would never parse Ruby code like this...
...nameCache: TERSER_NAME_CACHE, // preserve renames across files } function terserPlugin(terserOptions = DEFAULT_TERSER_OPTIONS) { return { name: 'terserPlugin', setup(build) { build.onLoad({ filter: /\.js$/ }, async (args) => { const text = await fs.promises.readFile(args.path, "utf8...
...let { code, map } = await terser.minify(text, terserOptions) return { contents: code, loader: 'js', } }) } } } Use the plugin in your build() or context() options: esbuild.build({ entrypoints: [...], minify: true, // prevent esbuild from pretty-printing...
Retrieve child nodes contents() (which behaves like children() except that it returns all types of child nodes) Filter manually using either plain Javascript or jQuery's filter...
Example Let's write a function that takes a jQuery element and returns an array of all child nodes that are text nodes: function selectTextNodes($container) { return $container.contents().filter...
...The execution times in the examples are very high, usually a Bitmap Index Scan returns within a few milliseconds. The approach above assumes you have a search_text field, where...
...const taskName = options.taskName || `observed changes in ${formOrField}` const delay = options.delay || formOrField.getAttribute('up-delay') || up.form.config.observeDelay return up.on(formOrField, 'input change', () => { window.CapybaraLockstep.startWork(taskName) setTimeout(() => window.CapybaraLockstep.stopWork(taskName), delay) }) } } if (window.CapybaraLockstep) { // lock capybara for...
...all changes to fields with callbacks up.compiler('[up-observe]', (formOrField) => { return lockCapybaraForObservedChanges(formOrField, { taskName: `[up-observe]: ${formOrField}` }) }); up.compiler('[up-autosubmit]', (formOrField) => { return lockCapybaraForObservedChanges(formOrField, { taskName: `[up-autosubmit]: ${formOrField}` }) }); up.compiler('[up...
The Edge Rider gem gives your relations a method #traverse_association which returns a new relation by "pivoting" around a named association. Say we have a Post model and each...
...traversal is achieved internally by collecting all foreign keys in the current relation and return a new relation with an IN(...) query (which is very efficient even for many thousand...
When you use method_missing to have an object return something on a method call, always make sure you also redefine respond_to_missing?. If you don't do it...
...is not defined within the receiver. When it has not been defined properly, its return value is a false negative! Thus, you need to patch respond_to_missing? as well...
...with 100 comments and 10 attachments. The OUTER JOINs will cause the query to return 1000 database rows, the full cross product of the blog post × all its comments × all...