Skip to content
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: make test

- name: Run integration tests
if: github.event_name == 'push' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main')
if: github.event_name == 'push' || github.event_name == 'pull_request'
run: make test-integration

- name: Run code quality checks
Expand Down
10 changes: 9 additions & 1 deletion generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fi
if ! bundle --version &> /dev/null
then
echo "cannot find bundle in path, did you setup this repo correctly?";
exit 1;
# exit 1;
fi

set -ex
Expand All @@ -27,6 +27,14 @@ echo "Applying Ruby-specific fixes..."
# Ensure generated directory exists
mkdir -p lib/getstream_ruby/generated/models

# Delete APNS model: it contains hyphenated field names (content-available, mutable-content)
# which are invalid Ruby identifiers. The generated code has syntax errors that need manual fixing.
# TODO: Fix the code generator to handle hyphenated field names properly
if [ -f "lib/getstream_ruby/generated/models/apns.rb" ]; then
echo "Removing APNS model (contains invalid Ruby identifiers with hyphens)..."
rm "lib/getstream_ruby/generated/models/apns.rb"
fi

# Fix any potential issues in generated code
echo "Generated Ruby SDK for feeds in $DST_PATH"
echo ""
Expand Down
31 changes: 28 additions & 3 deletions lib/getstream_ruby/generated/base_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ def initialize(attributes = {})
end
end

# Convert to hash
# Class method to define which fields should be omitted when empty (like Go's omitempty)
# Override this in subclasses to specify fields that should be excluded from JSON serialization when empty
# @return [Array<Symbol>] Array of field names to omit when empty
def self.omit_empty_fields
[]
end

# Convert to hash (used for equality, inspect, etc.)
def to_h
instance_variables.each_with_object({}) do |var, hash|
key = var.to_s.delete('@').to_sym
Expand All @@ -22,9 +29,27 @@ def to_h
end
end

# Convert to JSON
# Convert to JSON with optional field filtering
# This is the Ruby-idiomatic way: filter only for JSON, keep to_h clean
# Automatically omits nil values (optional fields default to nil, like Go pointers)
def to_json(*args)
to_h.to_json(*args)
hash = to_h
omit_fields = self.class.omit_empty_fields

# Filter out nil values and empty fields for JSON serialization
hash = hash.reject do |key, value|
# Always omit nil values (optional fields default to nil)
next true if value.nil?

# For fields in omit_empty_fields, also omit empty strings/arrays/hashes
if omit_fields.include?(key)
value == "" || (value.respond_to?(:empty?) && value.empty?)
else
false
end
end

hash.to_json(*args)
end

# Equality comparison
Expand Down
Loading