Skip to content

Commit

Permalink
Merge pull request #87 from factorialco/add_library_on_create_query_f…
Browse files Browse the repository at this point in the history
…rom_json

Add library as argument on Query creation from_json
  • Loading branch information
txus authored Aug 22, 2023
2 parents 8a4679c + d9a46b2 commit fce6a94
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ AllCops:
DisplayCopNames: true
DisplayStyleGuide: true
NewCops: enable
TargetRubyVersion: 2.6
TargetRubyVersion: 3.0
Exclude:
- "tmp/**/*"
- "vendor/**/*"
Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.4
3.0.6
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ruby:2.7
FROM ruby:3.0.6

WORKDIR /usr/src/app

Expand Down
138 changes: 72 additions & 66 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
fql (0.2.11)
fql (0.2.12)
activerecord (~> 6.0)
i18n (~> 1.8)
sorbet-rails (~> 0.7.3)
Expand All @@ -12,31 +12,32 @@ PATH
GEM
remote: https://rubygems.org/
specs:
activemodel (6.1.7)
activesupport (= 6.1.7)
activerecord (6.1.7)
activemodel (= 6.1.7)
activesupport (= 6.1.7)
activesupport (6.1.7)
activemodel (6.1.7.4)
activesupport (= 6.1.7.4)
activerecord (6.1.7.4)
activemodel (= 6.1.7.4)
activesupport (= 6.1.7.4)
activesupport (6.1.7.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
ast (2.4.2)
backport (1.2.0)
benchmark (0.2.0)
benchmark (0.2.1)
byebug (11.1.3)
coderay (1.1.3)
commander (4.6.0)
highline (~> 2.0.0)
concurrent-ruby (1.1.10)
concurrent-ruby (1.2.2)
diff-lcs (1.5.0)
docile (1.4.0)
e2mmap (0.1.0)
erubi (1.12.0)
ffi (1.15.5)
fivemat (1.3.7)
formatador (0.3.0)
formatador (1.1.0)
guard (2.18.0)
formatador (>= 0.2.4)
listen (>= 2.7, < 4.0)
Expand All @@ -52,54 +53,55 @@ GEM
guard-compat (~> 1.1)
rspec (>= 2.99.0, < 4.0)
highline (2.0.3)
i18n (1.12.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
kramdown (2.3.1)
jaro_winkler (1.5.6)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
listen (3.7.1)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
lumberjack (1.2.8)
lumberjack (1.2.9)
method_source (1.0.0)
mini_portile2 (2.7.1)
minitest (5.16.3)
minitest (5.19.0)
nenv (0.3.0)
nokogiri (1.13.1)
mini_portile2 (~> 2.7.0)
netrc (0.11.0)
nokogiri (1.15.4-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.21.0)
parlour (8.0.0)
parallel (1.23.0)
parlour (8.1.0)
commander (~> 4.5)
parser
rainbow (~> 3.0)
sorbet-runtime (>= 0.5)
parser (3.1.2.1)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
polyfill (1.9.0)
pry (0.14.1)
prettier_print (1.2.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
racc (1.6.0)
racc (1.7.1)
rainbow (3.1.1)
rake (13.0.6)
rb-fsevent (0.11.0)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbi (0.0.16)
rbi (0.0.17)
ast
parser (>= 2.6.4.0)
parser (>= 3.0.0)
sorbet-runtime (>= 0.5.9204)
unparser
regexp_parser (2.2.0)
unparser (>= 0.5.6)
regexp_parser (2.8.1)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.5)
rexml (3.2.6)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
Expand All @@ -112,7 +114,7 @@ GEM
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
rspec_junit_formatter (0.5.1)
rspec_junit_formatter (0.6.0)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (1.24.1)
parallel (~> 1.10)
Expand All @@ -123,8 +125,8 @@ GEM
rubocop-ast (>= 1.15.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.15.1)
parser (>= 3.0.1.1)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-packaging (0.5.1)
rubocop (>= 0.89, < 2.0)
rubocop-performance (1.13.1)
Expand All @@ -134,20 +136,20 @@ GEM
rubocop (~> 1.0)
rubocop-rspec (2.7.0)
rubocop (~> 1.19)
rubocop-sorbet (0.6.5)
rubocop-sorbet (0.7.3)
rubocop (>= 0.90.0)
ruby-progressbar (1.11.0)
ruby-progressbar (1.13.0)
safe_type (1.1.1)
shellany (0.0.1)
simplecov (0.21.2)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
simplecov-buildkite (0.2.0)
simplecov (~> 0.16)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
solargraph (0.44.2)
simplecov_json_formatter (0.1.4)
solargraph (0.48.0)
backport (~> 1.2)
benchmark
bundler (>= 1.17.2)
Expand All @@ -162,8 +164,8 @@ GEM
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
sorbet (0.5.9531)
sorbet-static (= 0.5.9531)
sorbet (0.5.10981)
sorbet-static (= 0.5.10981)
sorbet-coerce (0.7.0)
polyfill (~> 1.8)
safe_type (~> 1.1, >= 1.1.1)
Expand All @@ -174,42 +176,46 @@ GEM
parser (>= 2.7)
sorbet-coerce (>= 0.2.6)
sorbet-runtime (>= 0.5.9892)
sorbet-runtime (0.5.10481)
sorbet-static (0.5.9531-universal-darwin-14)
sorbet-runtime (0.5.10981)
sorbet-static (0.5.10981-x86_64-linux)
sorbet-static-and-runtime (0.5.10981)
sorbet (= 0.5.10981)
sorbet-runtime (= 0.5.10981)
sorbet-struct-comparable (1.3.0)
sorbet-runtime (>= 0.5)
spoom (1.1.12)
sorbet (>= 0.5.9204)
sorbet-runtime (>= 0.5.9204)
spoom (1.2.3)
erubi (>= 1.10.0)
sorbet-static-and-runtime (>= 0.5.10187)
syntax_tree (>= 6.1.1)
thor (>= 0.19.2)
sqlite3 (1.4.2)
tapioca (0.7.3)
bundler (>= 1.17.3)
pry (>= 0.12.2)
rbi (~> 0.0.0, >= 0.0.14)
sorbet-runtime (>= 0.5.9204)
sorbet-static (>= 0.5.9204)
spoom (~> 1.1.0, >= 1.1.11)
sqlite3 (1.6.3-x86_64-linux)
syntax_tree (6.1.1)
prettier_print (>= 1.2.0)
tapioca (0.11.8)
bundler (>= 2.2.25)
netrc (>= 0.11.0)
parallel (>= 1.21.0)
rbi (~> 0.0.0, >= 0.0.16)
sorbet-static-and-runtime (>= 0.5.10187)
spoom (~> 1.2.0, >= 1.2.0)
thor (>= 1.2.0)
yard-sorbet
thor (1.2.1)
tilt (2.0.10)
tzinfo (2.0.5)
thor (1.2.2)
tilt (2.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
unparser (0.6.5)
unicode-display_width (2.4.2)
unparser (0.6.8)
diff-lcs (~> 1.3)
parser (>= 3.1.0)
webrick (1.7.0)
yard (0.9.27)
webrick (~> 1.7.0)
yard-sorbet (0.7.0)
parser (>= 3.2.0)
yard (0.9.34)
yard-sorbet (0.8.1)
sorbet-runtime (>= 0.5)
yard (>= 0.9)
zeitwerk (2.6.6)
zeitwerk (2.6.11)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
byebug
Expand All @@ -233,4 +239,4 @@ DEPENDENCIES
tapioca

BUNDLED WITH
2.1.4
2.4.18
2 changes: 1 addition & 1 deletion fql.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
spec.summary = "Factorial Query Language"
spec.homepage = "https://github.com/factorialco/fql"
spec.license = "MIT"
spec.required_ruby_version = ">= 2.6.0"
spec.required_ruby_version = ">= 3.0.6"

spec.metadata = {
"bug_tracker_uri" => "https://github.com/factorialco/fql/issues",
Expand Down
4 changes: 2 additions & 2 deletions lib/fql/backend/arel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def compile_expression(expr)
nil
when Integer, String, Date
expr
when Array
when Array
expr.map { |e| compile_expression(e) }
when Query::DSL::And
T.cast(compile_expression(expr.lhs), A::Node).and(T.cast(compile_expression(expr.rhs), A::Node))
Expand All @@ -65,7 +65,7 @@ def compile_expression(expr)
if rhs.is_a?(Array)
T.cast(compile_expression(expr.lhs), Attribute).in(rhs)
else
T.cast(compile_expression(expr.lhs), Attribute).eq(rhs)
T.cast(compile_expression(expr.lhs), Attribute).eq(rhs)
end
when Query::DSL::Gt
T.cast(compile_expression(expr.lhs), Attribute).gt(compile_expression(expr.rhs))
Expand Down
2 changes: 1 addition & 1 deletion lib/fql/backend/ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def self.compile_expression(expr, lib)
"(#{lhs} #{operator} #{rhs})"
when Query::DSL::Eq
rhs = compile_expression(expr.rhs, lib)
if rhs.start_with?('[')
if rhs.start_with?("[")
"(#{rhs}.include?(#{compile_expression(expr.lhs, lib)}))"
else
"(#{compile_expression(expr.lhs, lib)} == #{rhs})"
Expand Down
6 changes: 3 additions & 3 deletions lib/fql/query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def initialize(expr, library: Library.empty)
@library = library
end

sig { params(input: T::Hash[T.any(String, Symbol), T.untyped]).returns(Outcome[T.attached_class]) }
def self.from_json(input)
sig { params(input: T::Hash[T.any(String, Symbol), T.untyped], library: Library).returns(Outcome[T.attached_class]) }
def self.from_json(input, library: Library.empty)
Serde::JSON.new.deserialize(input).map do |parsed|
new(parsed)
new(parsed, library: library)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fql/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: false
module FQL
VERSION = "0.2.11".freeze
VERSION = "0.2.12".freeze
end
8 changes: 4 additions & 4 deletions rbi/fql.rbi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# typed: strong
module FQL
VERSION = "0.2.6".freeze
VERSION = "0.2.12".freeze

class Library
extend T::Sig
Expand Down Expand Up @@ -95,7 +95,7 @@ module FQL
def serialize_expression(expr); end

sig { params(expr: T.any(T::Hash[Symbol, T.untyped], T::Boolean, Integer, String,
Date, NilClass)).returns(Outcome[T.any(Query::DSL::Expr, NilClass)]) }
Date, NilClass, T::Array[T.untyped])).returns(Outcome[T.any(Query::DSL::Expr, NilClass)]) }
def parse_expression(expr); end
end
end
Expand Down Expand Up @@ -222,8 +222,8 @@ module FQL
sig { params(expr: DSL::Root, library: Library).void }
def initialize(expr, library: Library.empty); end

sig { params(input: T::Hash[T.any(String, Symbol), T.untyped]).returns(Outcome[T.attached_class]) }
def self.from_json(input); end
sig { params(input: T::Hash[T.any(String, Symbol), T.untyped], library: Library).returns(Outcome[T.attached_class]) }
def self.from_json(input, library: Library.empty); end

sig { returns(Backend::Ruby::CompiledFunction) }
def to_ruby; end
Expand Down
2 changes: 1 addition & 1 deletion spec/fql/backend/arel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
end

it "can call a simple function with array" do
expect(F.eq(F.call(:country), F.call(:echo, ["fr", "EN"]))).to compile_to('SELECT DISTINCT "users".* FROM "users" LEFT OUTER JOIN addresses "address" ON "users"."id" = "address"."tenant_id" WHERE "address"."country" IN (\'fr\', \'EN\')')
expect(F.eq(F.call(:country), F.call(:echo, %w[fr EN]))).to compile_to('SELECT DISTINCT "users".* FROM "users" LEFT OUTER JOIN addresses "address" ON "users"."id" = "address"."tenant_id" WHERE "address"."country" IN (\'fr\', \'EN\')')
end

it "can call a parameterized function from the library" do
Expand Down
2 changes: 1 addition & 1 deletion spec/fql/backend/ruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
expect(F.eq(true, nil)).to compile_to("(true == nil)")
end

it "accepts nil on the right hand side" do
it "accepts an array on the right hand side" do
expect(F.eq(true, [1, 2])).to compile_to("([1, 2].include?(true))")
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/fql/serde/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

matcher :roundtrip do
match do |expression|
serialized = subject.serialize(F.with_meta({foo: :bar}, expression))
serialized = subject.serialize(F.with_meta({ foo: :bar }, expression))
subject.serialize(
subject.deserialize(
serialized
Expand Down
Loading

0 comments on commit fce6a94

Please sign in to comment.