...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...

...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...

makandra dev

Timecop is a great gem to set the current time in tests. However, it is easy to introduce flakyness to...

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...

makandra dev

...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...

...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...

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...

...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...

...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...

...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 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...

...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...

...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...

stackoverflow.com

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...

...in replacement for trigger() (requires Unpoly): jQuery.fn.triggerNative = function(...args) { this.each(function() { up.emit(this, ...args) }) return this } With this you can replace a call like $element.trigger('change') with $element.triggerNative('change'). You...

if (!$event.originalEvent) { let eventProps = up.util.only($event, ...convertedPropNames) up.emit($event.target, eventName, eventProps) up.event.halt($event) } }) return this } Here is an example usage: $element.select2().enableNativeEvent('change') Make sure this function is applied...

...that dynamically composes person.firstName and person.lastName: var person = { firstName: 'Guybrush', lastName: 'Threepwood', get fullName() { return this.firstName + " " + this.lastName; }, set fullName(name) { var parts = name.split(" "); this.firstName = parts[0]; this.lastName = parts[1]; } };

...use Object.defineProperty() instead: var person = { firstName: 'Guybrush', lastName: 'Threepwood' }; Object.defineProperty(person, "fullName", { get: function() { return this.firstName + " " + this.lastName; }, set: function(name) { var parts = name.split(" "); this.firstName = parts[0]; this.lastName = parts[1]; } });

...HTTPS forwarding header, Rails recognizes that a request originally was on HTTPS and will return the correct protocol. Caveats: You need to harden your server setup to forbid the routing...

...If you want to check your setting, do the following. By default, it will return matching (see above). $ git config --global push.default matching So to change that to push only...

...PATH=$(find-up .nvmrc | tr -d '[:space:]') if [[ $NVM_PATH == $NVM_PATH_WAS ]]; then return fi NVM_PATH_WAS=$NVM_PATH if [[ -f "$NVM_PATH/.nvmrc" ]]; then nvm use $(<"$NVM_PATH/.nvmrc...

relishapp.com

...error, it will fail with a not-so-helpful error message: expected present? to return true, got false (Spec::Expectations::ExpectationNotMetError) Solution That can be fixed easily. RSpec expectations allow...

...an element is present, without errors raised, you can use #has_css?. It will return a Boolean – but will wait as well. If the element does not exist, it will...

...take the configured Capybara.default_wait_time for this check to return false, which is usually several seconds. The solution is to disable the waiting for just that check:

When your JavaScript bundle is so massive that you cannot load it all up front, I would recommend to load...

...function. Where promiseState() becomes useful is when writing unit tests for a function that returns a promise. Let's say we write a promise-based variant of setTimeout(): function setTimer...

return new Promise(resolve, reject) { setTimeout(resolve, delay) } } We would use it like this: setTimer(300).then(function() {...

Here is a test for setTimer() that uses promiseState(): describe('setTimer...