schema-model 0.6.11 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +93 -0
- data/.github/workflows/release.yml +93 -0
- data/.release-please-manifest.json +3 -0
- data/.rubocop.yml +70 -8
- data/.ruby-version +1 -1
- data/ARCHITECTURE.md +135 -0
- data/CHANGELOG.md +9 -0
- data/CLAUDE.md +83 -0
- data/Gemfile +1 -2
- data/Gemfile.lock +79 -47
- data/README.md +361 -85
- data/lib/schema/active_model_validations.rb +14 -14
- data/lib/schema/array_headers.rb +6 -4
- data/lib/schema/arrays.rb +11 -13
- data/lib/schema/associations/dynamic_types.rb +3 -5
- data/lib/schema/associations/has_many.rb +2 -4
- data/lib/schema/associations/has_one.rb +3 -5
- data/lib/schema/associations/schema_creator.rb +2 -2
- data/lib/schema/csv_parser.rb +1 -1
- data/lib/schema/model.rb +26 -21
- data/lib/schema/parsers/array.rb +2 -2
- data/lib/schema/parsers/common.rb +6 -8
- data/lib/schema/parsers/hash.rb +1 -1
- data/lib/schema/parsers/json.rb +1 -1
- data/lib/schema/parsing_errors.rb +1 -1
- data/lib/schema/utils.rb +5 -5
- data/lib/schema/version.rb +6 -0
- data/lib/schema-model.rb +1 -0
- data/release-please-config.json +12 -0
- data/schema-model.gemspec +8 -4
- data/script/coverage_badge.rb +49 -0
- metadata +17 -12
- data/.cursor-rules +0 -39
- data/.travis.yml +0 -14
- data/Rakefile +0 -11
- data/docs/ARCHITECTURE.md +0 -171
- data/script/bundle_install_all_versions +0 -8
- data/script/rspec_all_versions +0 -5
data/Rakefile
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'rubygems'
|
|
4
|
-
require 'bundler/setup'
|
|
5
|
-
require 'rake'
|
|
6
|
-
require 'rspec/core/rake_task'
|
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |t|
|
|
8
|
-
t.pattern = Dir.glob('spec/**/*_spec.rb')
|
|
9
|
-
t.rspec_opts = '--format documentation'
|
|
10
|
-
end
|
|
11
|
-
task default: :spec
|
data/docs/ARCHITECTURE.md
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
# Schema Architecture Documentation
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
Schema is a Ruby gem that provides a robust framework for data transformation, validation, and type safety. It follows a modular architecture that allows for flexible and extensible data modeling.
|
|
6
|
-
|
|
7
|
-
## Core Components
|
|
8
|
-
|
|
9
|
-
### 1. Model System (`lib/schema/model.rb`)
|
|
10
|
-
|
|
11
|
-
The foundation of the Schema system, providing:
|
|
12
|
-
- Attribute definition and management
|
|
13
|
-
- Type system integration
|
|
14
|
-
- Data parsing and validation
|
|
15
|
-
- Association handling
|
|
16
|
-
|
|
17
|
-
Key features:
|
|
18
|
-
- Dynamic attribute registration
|
|
19
|
-
- Type coercion and validation
|
|
20
|
-
- Nested model support
|
|
21
|
-
- Error collection and reporting
|
|
22
|
-
|
|
23
|
-
### 2. Association System (`lib/schema/associations/`)
|
|
24
|
-
|
|
25
|
-
Handles relationships between models:
|
|
26
|
-
- `has_one`: Single nested model
|
|
27
|
-
- `has_many`: Multiple nested models
|
|
28
|
-
- Dynamic associations based on type fields
|
|
29
|
-
- Hash-based associations
|
|
30
|
-
|
|
31
|
-
### 3. Parser System (`lib/schema/parsers/`)
|
|
32
|
-
|
|
33
|
-
Responsible for data type conversion and validation:
|
|
34
|
-
- Built-in parsers for common types (string, integer, float, etc.)
|
|
35
|
-
- Custom parser support
|
|
36
|
-
- Array parsing with separators
|
|
37
|
-
- CSV data parsing
|
|
38
|
-
|
|
39
|
-
### 4. Validation System (`lib/schema/active_model_validations.rb`)
|
|
40
|
-
|
|
41
|
-
Integrates with ActiveModel validations to provide:
|
|
42
|
-
- Attribute presence validation
|
|
43
|
-
- Format validation
|
|
44
|
-
- Custom validation rules
|
|
45
|
-
- Nested model validation
|
|
46
|
-
|
|
47
|
-
### 5. Error Handling (`lib/schema/errors.rb`, `lib/schema/parsing_errors.rb`)
|
|
48
|
-
|
|
49
|
-
Comprehensive error management:
|
|
50
|
-
- Parsing errors
|
|
51
|
-
- Validation errors
|
|
52
|
-
- Nested model errors
|
|
53
|
-
- Error message formatting
|
|
54
|
-
|
|
55
|
-
## Data Flow
|
|
56
|
-
|
|
57
|
-
1. **Initialization**
|
|
58
|
-
- Schema class definition
|
|
59
|
-
- Attribute registration
|
|
60
|
-
- Association setup
|
|
61
|
-
- Validation rules configuration
|
|
62
|
-
|
|
63
|
-
2. **Data Processing**
|
|
64
|
-
- Input data parsing
|
|
65
|
-
- Type coercion
|
|
66
|
-
- Association resolution
|
|
67
|
-
- Validation execution
|
|
68
|
-
|
|
69
|
-
3. **Error Collection**
|
|
70
|
-
- Parsing error collection
|
|
71
|
-
- Validation error aggregation
|
|
72
|
-
- Nested model error propagation
|
|
73
|
-
|
|
74
|
-
## Extension Points
|
|
75
|
-
|
|
76
|
-
### Custom Parsers
|
|
77
|
-
|
|
78
|
-
```ruby
|
|
79
|
-
module Schema::Parsers
|
|
80
|
-
class CustomParser
|
|
81
|
-
def self.parse(field_name, errors, value)
|
|
82
|
-
# Custom parsing logic
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
### Custom Validators
|
|
89
|
-
|
|
90
|
-
```ruby
|
|
91
|
-
class CustomValidator < ActiveModel::Validator
|
|
92
|
-
def validate(record)
|
|
93
|
-
# Custom validation logic
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
### Custom Associations
|
|
99
|
-
|
|
100
|
-
```ruby
|
|
101
|
-
module Schema::Associations
|
|
102
|
-
class CustomAssociation < Base
|
|
103
|
-
def initialize(name, options = {}, &block)
|
|
104
|
-
# Custom association logic
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
## Performance Considerations
|
|
111
|
-
|
|
112
|
-
1. **Attribute Access**
|
|
113
|
-
- Dynamic method generation for attribute accessors
|
|
114
|
-
- Caching of parsed values
|
|
115
|
-
- Lazy loading of associations
|
|
116
|
-
|
|
117
|
-
2. **Validation**
|
|
118
|
-
- Early termination on first error
|
|
119
|
-
- Parallel validation of independent attributes
|
|
120
|
-
- Caching of validation results
|
|
121
|
-
|
|
122
|
-
3. **Memory Management**
|
|
123
|
-
- Efficient error object creation
|
|
124
|
-
- Minimal object allocation during parsing
|
|
125
|
-
- Garbage collection optimization
|
|
126
|
-
|
|
127
|
-
## Security Considerations
|
|
128
|
-
|
|
129
|
-
1. **Data Validation**
|
|
130
|
-
- Strict type checking
|
|
131
|
-
- Input sanitization
|
|
132
|
-
- Size limits on collections
|
|
133
|
-
|
|
134
|
-
2. **Error Handling**
|
|
135
|
-
- Safe error message generation
|
|
136
|
-
- No sensitive data exposure
|
|
137
|
-
- Controlled error propagation
|
|
138
|
-
|
|
139
|
-
## Testing Strategy
|
|
140
|
-
|
|
141
|
-
1. **Unit Tests**
|
|
142
|
-
- Individual component testing
|
|
143
|
-
- Mock dependencies
|
|
144
|
-
- Edge case coverage
|
|
145
|
-
|
|
146
|
-
2. **Integration Tests**
|
|
147
|
-
- Component interaction testing
|
|
148
|
-
- Real-world usage scenarios
|
|
149
|
-
- Performance benchmarks
|
|
150
|
-
|
|
151
|
-
3. **Regression Tests**
|
|
152
|
-
- Backward compatibility
|
|
153
|
-
- Bug fixes verification
|
|
154
|
-
- Performance regression detection
|
|
155
|
-
|
|
156
|
-
## Future Considerations
|
|
157
|
-
|
|
158
|
-
1. **Planned Features**
|
|
159
|
-
- JSON Schema integration
|
|
160
|
-
- GraphQL type generation
|
|
161
|
-
- Async validation support
|
|
162
|
-
|
|
163
|
-
2. **Performance Improvements**
|
|
164
|
-
- Parallel processing
|
|
165
|
-
- Memory optimization
|
|
166
|
-
- Caching strategies
|
|
167
|
-
|
|
168
|
-
3. **API Evolution**
|
|
169
|
-
- Backward compatibility
|
|
170
|
-
- Deprecation strategy
|
|
171
|
-
- Version management
|