This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Super.RepoTest do | |
use Super.DataCase, async: true | |
require Logger | |
@skipped_schemas [UserService.User] | |
defp tenant_schemas do | |
{:ok, mods} = :application.get_key(:super, :modules) | |
Enum.map(mods, fn mod -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clean the database | |
DROP TABLE IF EXISTS _orders CASCADE; | |
DROP TABLE IF EXISTS _users CASCADE; | |
DROP TABLE IF EXISTS orders CASCADE; | |
DROP TABLE IF EXISTS users CASCADE; | |
# Build the database (for hard deletion) | |
CREATE TABLE users ( | |
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY, | |
name text NOT NULL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$x = 0; | |
$x = $x + 1; | |
$x = $x + 2; | |
$x = $x + 3; | |
print($x); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
code = "<?php \n" | |
code += " $x = 0; \n" | |
(1..3).each do |n| | |
code += " $x = $x + #{n}; \n" | |
end | |
code += " print($x); \n?>" | |
File.open("dummy.php", 'w') { |file| file.write(code) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MethodCatcher | |
def method_missing(name, *args, &block) | |
puts "El nombre del método no encontrado es #{name}" | |
puts "los argumentos del método son #{args}" | |
puts "El cuerpo del método es #{block.inspect}" | |
end | |
end | |
catch = MethodCatcher.new | |
catch.some_method(1, 2) { puts "something" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Student | |
def method_missing(name) | |
puts "No fue encontrado el método #{name}" | |
end | |
end | |
student = Student.new | |
student.reflection | |
# No fue encontrado el método reflection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance_variable_set(name, value) # Nos permite definir y asignar un valor a una nueva variable de instancia | |
define_method(name, &block) # Nos permite definir dentro de la clase un método de manera dinámica y en tiempo de ejecución | |
method_missing(name, *args, &block) # Nos permite capturar y manejar la excepción que se dispara cuando llamamos un método no definido dentro de una clase. | |
... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clase base con la definición de nuestra macro a nivel de clase: | |
class AttrCustom | |
def self.attr_custom(name) | |
define_method("#{name}=") do |value| | |
puts "Asignando #{value.inspect} a #{name}" | |
instance_variable_set("@#{name}", value) | |
end | |
define_method("#{name}") do | |
puts "Leyendo #{name}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class.methods.select { |m| m =~ /attr/ } # [:attr, :attr_reader, :attr_writer, :attr_accessor] |
NewerOlder