Skip to content

Commit e456e7b

Browse files
committed
Enhance readme
1 parent 305343b commit e456e7b

File tree

1 file changed

+104
-14
lines changed

1 file changed

+104
-14
lines changed

lib/membrane/README.md

Lines changed: 104 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Inlined Membrane Library
1+
# Membrane (Internalized Copy)
22

3-
This directory contains the Membrane validation library inlined from the archived CloudFoundry project:
3+
This directory contains an internalized and maintained fork of the archived
4+
cloudfoundry Membrane validation project:
45
https://github.com/cloudfoundry/membrane
56

67
**License:** Apache License 2.0
@@ -32,7 +33,7 @@ This code is inlined into Cloud Controller NG because:
3233
All modifications are documented here for license compliance and auditability.
3334
The upstream repository was archived in 2022 with the last commit from 2014.
3435
Since this is an inlined copy (not a vendored dependency), CCNG maintains
35-
and modernizes the code for Ruby 3.3+ compatibility and removes unused features.
36+
and modernizes the code for Ruby 3.3+ compatibility and removes unused features. This is now a CCNG-maintained fork of Membrane.
3637

3738
### 1. New Files Created
3839

@@ -152,9 +153,93 @@ Applied to all 15 Ruby files to bring 2014 code to 2025 standards.
152153
# Modified for RuboCop compliance and Ruby 3.3 modernization
153154
```
154155

155-
### 5. Minor Code Improvements
156+
### 5. Removed Unused Upstream Feature: strict_checking
156157

157-
#### 5.1 Attribute Reader Consolidation
158+
**Deliberate Design Decision:** This feature was removed because CCNG never uses it.
159+
160+
#### 5.1 What Was Removed
161+
- **Files:** `schemas/record.rb` (multiple locations)
162+
- **Removed components:**
163+
- `strict_checking:` parameter from `initialize` method signature
164+
- `@strict_checking` instance variable
165+
- `validate_extra_keys` private method
166+
- Conditional logic checking extra keys in validation
167+
168+
#### 5.2 Original Upstream Behavior
169+
- **Default (`strict_checking: false`):** Ignores extra keys not in schema (lenient)
170+
- **Opt-in (`strict_checking: true`):** Raises error on extra keys not in schema (strict)
171+
172+
#### 5.3 CCNG Usage Analysis
173+
- Searched entire CCNG codebase: **Zero usages** of `strict_checking` parameter
174+
- Single production usage: `lib/vcap/config.rb` only passes 2 arguments (uses default)
175+
- CCNG always relied on default behavior (ignore extra keys)
176+
177+
#### 5.4 New Behavior
178+
- **Always ignores extra keys** (same as upstream default)
179+
- **No behavioral change for CCNG** - preserves exact behavior CCNG has always used
180+
- **API breaking change vs upstream** - third parameter no longer exists
181+
182+
#### 5.5 Rationale
183+
- Simplifies codebase by removing unused code paths
184+
- Makes behavior explicit rather than having unused configuration
185+
- Aligns with CCNG-maintained fork philosophy (tailor to actual needs)
186+
- Since upstream is archived, no risk of divergence issues
187+
188+
#### 5.6 Code Changes
189+
```ruby
190+
# Before:
191+
def initialize(schemas, optional_keys=[], strict_checking: false)
192+
@optional_keys = Set.new(optional_keys)
193+
@schemas = schemas
194+
@strict_checking = strict_checking
195+
end
196+
197+
class KeyValidator
198+
def initialize(optional_keys, schemas, strict_checking, object)
199+
@strict_checking = strict_checking
200+
# ...
201+
end
202+
203+
def validate
204+
# ... validation logic
205+
key_errors.merge!(validate_extra_keys(@object.keys - schema_keys)) if @strict_checking
206+
# ...
207+
end
208+
209+
def validate_extra_keys(extra_keys)
210+
extra_key_errors = {}
211+
extra_keys.each { |k| extra_key_errors[k] = 'was not specified in the schema' }
212+
extra_key_errors
213+
end
214+
end
215+
216+
# After:
217+
def initialize(schemas, optional_keys=[])
218+
@optional_keys = Set.new(optional_keys)
219+
@schemas = schemas
220+
end
221+
222+
class KeyValidator
223+
def initialize(optional_keys, schemas, object)
224+
# No @strict_checking
225+
end
226+
227+
def validate
228+
# ... validation logic (no extra key checking)
229+
end
230+
231+
# validate_extra_keys method removed entirely
232+
end
233+
```
234+
235+
#### 5.7 Test Changes
236+
- Removed test: "raises an error if there are extra keys that are not matched in the schema"
237+
- Removed test: "doesnt raise an error" (in "when not strict checking" context)
238+
- Added test: "ignores extra keys that are not in the schema" (verifies default behavior)
239+
240+
### 6. Minor Code Improvements
241+
242+
#### 6.1 Attribute Reader Consolidation
158243
- **Files:** `schemas/dictionary.rb`, `schemas/record.rb`
159244
- **Change:**
160245
```ruby
@@ -166,12 +251,12 @@ Applied to all 15 Ruby files to bring 2014 code to 2025 standards.
166251
attr_reader :key_schema, :value_schema
167252
```
168253

169-
#### 5.2 Unused Parameter Annotation
254+
#### 6.2 Unused Parameter Annotation
170255
- **Files:** `schemas/any.rb`
171256
- **Change:** `def validate(object)``def validate(_object)`
172257
- **Reason:** RuboCop compliance, documents intentionally unused parameter
173258

174-
#### 5.3 Removed Redundant Require Statements
259+
#### 6.3 Removed Redundant Require Statements
175260
- **Files:** `schemas/record.rb` (1 occurrence)
176261
- **Change:** Removed `require "set"`
177262
- **Reason:** Set is already loaded by ActiveSupport in CCNG's environment
@@ -206,7 +291,7 @@ Applied to all 15 Ruby files to bring 2014 code to 2025 standards.
206291
end
207292
```
208293

209-
#### 5.5 Ruby 3.3 Set API Compatibility
294+
#### 6.4 Ruby 3.3 Set API Compatibility
210295
- **Files:** `schemas/record.rb` (1 occurrence, line 50)
211296
- **Change:** `@optional_keys.exclude?(k)``!@optional_keys.member?(k)`
212297
- **Reason:** `Set#exclude?` was removed in Ruby 3.3
@@ -223,7 +308,7 @@ Applied to all 15 Ruby files to bring 2014 code to 2025 standards.
223308
key_errors[k] = 'Missing key'
224309
```
225310

226-
### 6. Files NOT Modified
311+
### 7. Files NOT Modified
227312

228313
These files were copied verbatim with ONLY the `frozen_string_literal: true` magic comment added:
229314

@@ -236,21 +321,26 @@ These files were copied verbatim with ONLY the `frozen_string_literal: true` mag
236321

237322
| Category | Files Changed | Lines Changed | Breaking? |
238323
|----------|---------------|---------------|-----------|
239-
| New shim file created | 1 | +8 | No |
324+
| New shim file created | 1 | +8 | No* |
240325
| frozen_string_literal added | 15 | +30 | No |
241326
| Modernized raise statements | 10 | ~18 | No |
242327
| Removed .freeze on literals | 1 | ~1 | No |
328+
| Removed unused strict_checking | 1 | ~15 | Yes** |
243329
| Ruby 3.3 Set API fix | 1 | ~1 | No |
244330
| RuboCop compliance | 1 | ~10 | No |
245331
| Code style improvements | 8 | ~20 | No |
246-
| **Total** | **15 files** | **~88 lines** | **No** |
332+
| **Total** | **15 files** | **~103 lines** | **See notes** |
333+
334+
\* No breaking changes for CCNG's usage
335+
\** Breaks upstream API compatibility but feature was unused by CCNG
247336

248337
## Functional Impact
249338

250-
**Zero breaking changes**
251-
**100% API compatible with upstream**
339+
**Zero breaking changes for CCNG's usage patterns**
252340
**All existing CCNG code continues to work without modification**
253-
**All Membrane tests pass**
341+
**All actively-used Membrane functionality preserved**
342+
⚠️ **Removed unused `strict_checking` parameter (not used by CCNG)**
343+
**Ruby 3.3+ compatibility achieved**
254344
**Performance improved (frozen strings, modern Ruby)**
255345

256346
## Testing

0 commit comments

Comments
 (0)