A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.
posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord| # frozen_string_literal: true | |
| require "yaml" | |
| namespace :dev do | |
| desc "Create locale files to models" | |
| task create_locale_files: :environment do | |
| models_folder = Rails.root.join("app","models") | |
| original_new_locales_folder = Rails.root.join("config", "locales") |
| # frozen_string_literal: true | |
| module ArelNodesTrgm | |
| class Arel::Nodes::Trgm < Arel::Nodes::InfixOperation | |
| def initialize(left, right) | |
| super(:"%", left, right) | |
| end | |
| end | |
| class Arel::Visitors::PostgreSQL < Arel::Visitors::ToSql |
| { | |
| "Print asterisk line": { | |
| "prefix": "line", | |
| "body": [ | |
| "p '*' * 100" | |
| ], | |
| "description": "Print a asterisk line" | |
| }, | |
| "Print and inspect a element": { |
| Rich Hickey | |
| https://confreaks.tv/videos/railsconf2012-keynote-simplicity-matters | |
| https://confreaks.tv/videos/jaxconf2012-keynote-the-value-of-values | |
| Dave Thomas | |
| https://confreaks.tv/videos/elixirconf2014-opening-keynote-think-different | |
| https://confreaks.tv/videos/lonestarruby2013-elixir-power-of-erlang-joy-of-ruby | |
| Robert Martin | |
| https://confreaks.tv/videos/rubymidwest2011-keynote-architecture-the-lost-years |
| # In most cases, a single Rails app will be attached to a single repo | |
| # As of Rails 5.1, initializing a new project will also automatically initialize Git | |
| # This is perfect in most circumstances, but at App Academy, students have homework and | |
| # project repos that contain multiple rails apps inside them | |
| # To account for this without pushing the submodules, students need to remove the .git | |
| # directory before adding and commiting the new project, but most do not, resulting in |
| module Arel::Predications | |
| def has_key(right) | |
| Arel::Nodes::HasKey.new(self, quoted_node(right)) | |
| end | |
| end | |
| class Arel::Nodes::HasKey < Arel::Nodes::Binary | |
| def operator; :"?" end | |
| end |
| module Arel::Predications | |
| def any(right) | |
| Arel::Nodes::Any.new(self, quoted_node(right)) | |
| end | |
| end | |
| class Arel::Nodes::Any < Arel::Nodes::Binary | |
| def operator | |
| :'ANY' | |
| end |
| /[^\/?]+(?=\?|$)/ |