Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,31 @@ jobs:
working-directory: tests/nim
run: python3 testnim.py

build-ruby:
name: Build Ruby
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: ruby/setup-ruby@v1
with:
ruby-version: ruby
- name: flatc
run: |
cmake \
-S . \
-B build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DFLATBUFFERS_BUILD_FLATHASH=OFF \
-DFLATBUFFERS_BUILD_FLATLIB=OFF \
-DFLATBUFFERS_BUILD_TESTS=OFF \
-DFLATBUFFERS_INSTALL=OFF \
-DFLATBUFFERS_STRICT_MODE=ON
ninja -C build
- name: test
run: |
BUILD_DIR=build tests/RubyTest.rb

bazel:
name: Bazel
runs-on: ubuntu-24.04
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ set(FlatBuffers_Compiler_SRCS
src/bfbs_gen.h
src/bfbs_gen_lua.h
src/bfbs_gen_nim.h
src/bfbs_gen_ruby.h
src/bfbs_namer.h
include/codegen/idl_namer.h
include/codegen/namer.h
Expand All @@ -195,6 +196,7 @@ set(FlatBuffers_Compiler_SRCS
src/annotated_binary_text_gen.cpp
src/bfbs_gen_lua.cpp
src/bfbs_gen_nim.cpp
src/bfbs_gen_ruby.cpp
src/code_generators.cpp
grpc/src/compiler/schema_interface.h
grpc/src/compiler/cpp_generator.h
Expand Down
1 change: 1 addition & 0 deletions include/flatbuffers/idl.h
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ struct IDLOptions {
kNim = 1 << 17,
kProto = 1 << 18,
kKotlinKmp = 1 << 19,
kRuby = 1 << 20,
kMAX
};

Expand Down
20 changes: 20 additions & 0 deletions ruby/flatbuffers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2025 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative "flatbuffers/enum"
require_relative "flatbuffers/flags"
require_relative "flatbuffers/struct"
require_relative "flatbuffers/table"
require_relative "flatbuffers/union"
require_relative "flatbuffers/version"
49 changes: 49 additions & 0 deletions ruby/flatbuffers/enum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2025 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module FlatBuffers
class Enum
class << self
def try_convert(value)
case value
when Symbol, String
@name_to_enum[value.to_s]
when Integer
@value_to_enum[value]
when self
value
else
nil
end
end

def register(name, value)
object = new(name, value)
(@name_to_enum ||= {})[name] = object
(@value_to_enum ||= {})[value] = object
object
end
end

attr_reader :name
attr_reader :value
def initialize(name, value)
@name = name
@value = value
end

alias_method :to_i, :value
alias_method :to_int, :value
end
end
69 changes: 69 additions & 0 deletions ruby/flatbuffers/flags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Copyright 2025 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module FlatBuffers
class Flags
class << self
def try_convert(value)
case value
when Array
value.inject(new) do |previous, v|
flag = try_convert(v)
return nil if flag.nil?
previous | flag
end
when Symbol, String
try_convert(@name_to_value[value.to_s])
when Integer
new(value)
when self
value
else
nil
end
end

def register(name, value)
(@name_to_value ||= {})[name] = value
new(value)
end

def names
@name_to_value.keys
end

def resolve_names(value)
@name_to_value.select do |name, v|
not (value & v).zero?
end
end
end

attr_reader :value
def initialize(value=0)
@value = value
end

def names
@names ||= self.class.resolve_names(@value)
end

alias_method :to_i, :value
alias_method :to_int, :value

def |(other)
self.class.new(@value | Integer(other))
end
end
end
41 changes: 41 additions & 0 deletions ruby/flatbuffers/inspectable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2025 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module FlatBuffers
module Inspectable
def inspect
inspected = +"<#{self.class}:"
public_methods(false).each do |name|
next unless method(name).arity.zero?
inspected << " #{name}=#{__send__(name).inspect}"
end
inspected << ">"
inspected
end

def pretty_print(q)
q.object_group(self) do
targets = public_methods(false).select do |name|
method(name).arity.zero?
end
q.seplist(targets, lambda {q.text(",")}) do |name|
q.breakable
q.text(name.to_s)
q.text("=")
q.pp(__send__(name))
end
end
end
end
end
26 changes: 26 additions & 0 deletions ruby/flatbuffers/struct.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2025 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative "inspectable"
require_relative "view"

module FlatBuffers
class Struct
include Inspectable

def initialize(view)
@view = view
end
end
end
34 changes: 34 additions & 0 deletions ruby/flatbuffers/table.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2025 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require_relative "inspectable"
require_relative "view"

module FlatBuffers
class Table
include Inspectable

def initialize(input)
if input.is_a?(View)
@view = input
else
if input.is_a?(String)
input = IO::Buffer.for(input)
end
offset = input.get_value(:u32, 0)
@view = View.new(input, offset, have_vtable: true)
end
end
end
end
62 changes: 62 additions & 0 deletions ruby/flatbuffers/union.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2025 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module FlatBuffers
class Union
class << self
def try_convert(value)
case value
when Symbol, String
@name_to_union[value.to_s]
when Integer
@value_to_union[value]
when self
value
else
nil
end
end

def register(name, value, table_class_name, require_path)
object = new(name, value, table_class_name, require_path)
(@name_to_union ||= {})[name] = object
(@value_to_union ||= {})[value] = object
object
end
end

attr_reader :name
attr_reader :value
def initialize(name, value, table_class_name, require_path)
@name = name
@value = value
@table_class_name = table_class_name
@require_path = require_path
end

def table_class
@table_class ||= resolve_table_class
end

private def resolve_table_class
return nil if @table_class_name.nil?

require_table_class
Object.const_get(@table_class_name)
end

alias_method :to_i, :value
alias_method :to_int, :value
end
end
17 changes: 17 additions & 0 deletions ruby/flatbuffers/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2025 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module FlatBuffers
VERSION = "25.9.23"
end
Loading