profile
viewpoint
Kevin Choubacha kbacha TaskRabbit Morro Bay, CA

kbacha/git-release-name 29

Generate a release names based on a git sha

kbacha/grusp 3

An ack clone written in rust

kbacha/csv-writing-rs 1

Testing the functionality of writing csvs

kbacha/cxn_pool_test 1

Connection Pool Test

kbacha/file-finder 1

Finds files... kinda like github

issue openedsorbet/sorbet

Ability to cast a value at runtime but not statically

Problem

We'd like to provide an API for a user of our gem to declare a type as part of a structure or api. Such as declaring the return value of some arbitrary execution.

This type would be returned as a value and then used to assert that the return value of one of it's abstract methods is valid. Currently, this fails because using T.case(value, return_type) errors if the return_type is not a type literal (such as Class or T::Boolean). This is a static error as the code it self properly asserts the runtime values. The below example is contrived to demonstrate the use-case.

class Step < T::Struct
  prop :result, T.untyped
  prop :action, Action
end

class Action
  extend T::Helpers
  extend T::Sig

  abstract!

  sig { abstract.returns(T.untyped) }
  def perform; end
 
  sig { abstract.returns(T.any(Class, T::Type::Base)) }
  def return_type; end
end

class MyBooleanAction < Action
  def perform
    true
  end

  def return_type
    T::Boolean
  end
end

class MyStringAction < Action
  def perform
    "string"
  end

  def return_type
    String
  end
end

def MyBrokenAction < Action
  def perform
    123
  end

  def return_type
    String
  end
end

class Executor
  extend T::Sig
  sig { params(steps: T::Array[Step]).void }
  def execute(action)
    steps.each do |step|
      step.result = T.cast(action.perform, action.result_type)
  end
end

# This should raise a type error on the last action.
Executor.new.execute([MyBooleanAction.new, MyStringAction.new, MyBrokenAction.new])

It does pass the type checker

Workaround solution

To use cast without needing the static type checker, we have created a file:

# typed: ignore
module Utils::Unsafe
  def self.cast(value, type)
    T.cast(value, type)
  end
end

We load this module in a "clever" way:

# typed: true
module Utils
  module Unsafe
  end

  def self.unsafe
    T.unsafe(Unsafe)
  end
end

This returns a type erased module that can then have cast called on it without issue.

Proposed solution

Provide either a new runtime-only type assertion method. Here are some ways it could work:

A new function

value = T.assert(value, type)

A "check" function that returns boolean

T.is_a?(value, type)
T.is_type?(value, type)

A kwarg for cast similar to checked

value = T.cast(value, type, static: false)

created time in 17 days

CommitCommentEvent
CommitCommentEvent

issue commentflyerhzm/bullet

Does Bullet work with Rails Engine?

A lot of our services are wrapped in engines as well. We have bullet set to raise on n+1's but nothing has been raised and no logs written. Something about this cannot be correct because our codebase is actually full of them.

If it's related to your issue then it does seem to be a problem.

edisonywh

comment created time in 2 months

Pull request review commenttaskrabbit/activerecord-mysql-structure

Adds option to sort schema migration versions

 def sort_indices(lines)        sorted_lines     end++    def sort_versions(lines)+      versions = []+      sorted_lines = []+      in_versions = false+      lines.each do |line|+        if in_versions+          if MIGRATION_VERSION_VALUE_REGEX.match(line)+            # Collect the version values until we run out (generally due to the newlines at the end)+            versions << line+          else+            # Once we have stopped finding version values, sort them and add them all in order,+            # correcting the separator punctuation+            versions.sort.each_with_index do |version, idx|+              if (versions.size - 1) == idx+                sorted_lines << version.gsub(MIGRATION_VERSION_SEPARATOR_REGEX, ';')+              else+                sorted_lines << version.gsub(MIGRATION_VERSION_SEPARATOR_REGEX, ',')+              end+            end+            sorted_lines << line+            in_versions = false+          end+        else+          # Most of the file until the "insert into schema_migrations" line is unchanged+          sorted_lines << line+          in_versions = !!SCHEMA_INSERT_REGEX.match(line)

I believe using the .match? method may be slightly faster and it returns a boolean.

aalong-tr

comment created time in 3 months

Pull request review commenttaskrabbit/activerecord-mysql-structure

Adds option to sort schema migration versions

 def sort_indices(lines)        sorted_lines     end++    def sort_versions(lines)+      versions = []+      sorted_lines = []+      in_versions = false+      lines.each do |line|+        if in_versions+          if MIGRATION_VERSION_VALUE_REGEX.match(line)+            # Collect the version values until we run out (generally due to the newlines at the end)

Will this fail if an extra new line is missing?

aalong-tr

comment created time in 3 months

Pull request review commenttaskrabbit/activerecord-mysql-structure

Adds option to sort schema migration versions

           ActiveRecordMySqlStructure::StructureSqlSanitizer.new(             filename,             sorted_columns: false,-            sorted_indices: true+            sorted_indices: true,+          sorted_schema_versions: false,

indentation

aalong-tr

comment created time in 3 months

Pull request review commenttaskrabbit/activerecord-mysql-structure

Adds option to sort schema migration versions

 def sort_indices(lines)        sorted_lines     end++    def sort_versions(lines)+      versions = []+      sorted_lines = []+      in_versions = false+      lines.each do |line|+        if in_versions+          if MIGRATION_VERSION_VALUE_REGEX.match(line)+            # Collect the version values until we run out (generally due to the newlines at the end)+            versions << line+          else+            # Once we have stopped finding version values, sort them and add them all in order,+            # correcting the separator punctuation+            versions.sort.each_with_index do |version, idx|+              if (versions.size - 1) == idx+                sorted_lines << version.gsub(MIGRATION_VERSION_SEPARATOR_REGEX, ';')+              else+                sorted_lines << version.gsub(MIGRATION_VERSION_SEPARATOR_REGEX, ',')+              end+            end+            sorted_lines << line+            in_versions = false+          end+        else+          # Most of the file until the "insert into schema_migrations" line is unchanged+          sorted_lines << line+          in_versions = !!SCHEMA_INSERT_REGEX.match(line)+        end+      end+      sorted_lines

We should have a base case here where if we're still in_versions = true that we sort through and add the versions.

aalong-tr

comment created time in 3 months

PR opened queue-bus/datadog-queue-bus

Reviewers
Bumps rake version

There's a security vulnerability in lower versions of rake, this bumps to avoid it.

+1 -1

0 comment

1 changed file

pr created time in 3 months

create barnchqueue-bus/datadog-queue-bus

branch : choubacha/bump-rake-version

created branch time in 3 months

more