structify 0.2.0 → 0.3.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/CHANGELOG.md +8 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +26 -31
- data/README.md +31 -4
- data/lib/structify/model.rb +18 -6
- data/lib/structify/version.rb +1 -1
- data/lib/structify.rb +23 -0
- data/structify.gemspec +1 -1
- metadata +12 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fbeb1c01044934870011f48445f8e6f16eeaef8f05c8494f3b091fdd653cef5
|
4
|
+
data.tar.gz: c26b11296ffb7d3443fd987372b0190b56b1663e612853ee085da4a312d2caaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92e66ce5f01fc08608407df5042c50ea15aec7a8f150b58ad65bfc162a2af0dbc8341a964b51c0f6b2e188c9d9bfe3514e44f8d7930edcfd466ae66d16c2504c
|
7
|
+
data.tar.gz: e5df0c18b158393df16f61321bb6f56694e811591da44de748d0ff287a0007b61395678031e70d18f7d06fbed90b4c3e4eedd6eb4143cc9e37ecfe5e34266a6f
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,14 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
|
5
|
+
## [0.3.0] - 2025-03-17
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- Added configuration system with `Structify.configure` method
|
10
|
+
- Added ability to configure default container attribute through initializer
|
11
|
+
- Changed default container attribute from `:extracted_data` to `:json_attributes`
|
12
|
+
|
5
13
|
## [0.2.0] - 2025-03-12
|
6
14
|
|
7
15
|
### Added
|
data/Gemfile
CHANGED
@@ -7,8 +7,8 @@ group :development, :test do
|
|
7
7
|
gem "rake", "~> 13.0"
|
8
8
|
gem "rspec", "~> 3.12"
|
9
9
|
gem "rspec-rails", "~> 6.1"
|
10
|
-
gem "activerecord", "~>
|
11
|
-
gem
|
10
|
+
gem "activerecord", "~> 8"
|
11
|
+
gem 'sqlite3', '~> 2.0', '>= 2.0.2'
|
12
12
|
gem "rubocop", "~> 1.21"
|
13
13
|
gem "rubocop-rspec", "~> 2.25"
|
14
14
|
gem "yard", "~> 0.9"
|
data/Gemfile.lock
CHANGED
@@ -1,50 +1,48 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
structify (0.
|
5
|
-
activesupport (
|
4
|
+
structify (0.3.0)
|
5
|
+
activesupport (>= 7.0, < 9.0)
|
6
6
|
attr_json (~> 2.1)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actionpack (
|
12
|
-
actionview (=
|
13
|
-
activesupport (=
|
11
|
+
actionpack (8.0.2)
|
12
|
+
actionview (= 8.0.2)
|
13
|
+
activesupport (= 8.0.2)
|
14
14
|
nokogiri (>= 1.8.5)
|
15
|
-
racc
|
16
15
|
rack (>= 2.2.4)
|
17
16
|
rack-session (>= 1.0.1)
|
18
17
|
rack-test (>= 0.6.3)
|
19
18
|
rails-dom-testing (~> 2.2)
|
20
19
|
rails-html-sanitizer (~> 1.6)
|
21
|
-
|
22
|
-
|
20
|
+
useragent (~> 0.16)
|
21
|
+
actionview (8.0.2)
|
22
|
+
activesupport (= 8.0.2)
|
23
23
|
builder (~> 3.1)
|
24
24
|
erubi (~> 1.11)
|
25
25
|
rails-dom-testing (~> 2.2)
|
26
26
|
rails-html-sanitizer (~> 1.6)
|
27
|
-
activemodel (
|
28
|
-
activesupport (=
|
29
|
-
activerecord (
|
30
|
-
activemodel (=
|
31
|
-
activesupport (=
|
27
|
+
activemodel (8.0.2)
|
28
|
+
activesupport (= 8.0.2)
|
29
|
+
activerecord (8.0.2)
|
30
|
+
activemodel (= 8.0.2)
|
31
|
+
activesupport (= 8.0.2)
|
32
32
|
timeout (>= 0.4.0)
|
33
|
-
activesupport (
|
33
|
+
activesupport (8.0.2)
|
34
34
|
base64
|
35
35
|
benchmark (>= 0.3)
|
36
36
|
bigdecimal
|
37
|
-
concurrent-ruby (~> 1.0, >= 1.
|
37
|
+
concurrent-ruby (~> 1.0, >= 1.3.1)
|
38
38
|
connection_pool (>= 2.2.5)
|
39
39
|
drb
|
40
40
|
i18n (>= 1.6, < 2)
|
41
41
|
logger (>= 1.4.2)
|
42
42
|
minitest (>= 5.1)
|
43
|
-
mutex_m
|
44
43
|
securerandom (>= 0.3)
|
45
|
-
tzinfo (~> 2.0)
|
46
|
-
|
47
|
-
public_suffix (>= 2.0.2, < 7.0)
|
44
|
+
tzinfo (~> 2.0, >= 2.0.5)
|
45
|
+
uri (>= 0.13.1)
|
48
46
|
ast (2.4.2)
|
49
47
|
attr_json (2.5.0)
|
50
48
|
activerecord (>= 6.0.0, < 8.1)
|
@@ -70,15 +68,12 @@ GEM
|
|
70
68
|
rdoc (>= 4.0.0)
|
71
69
|
reline (>= 0.4.2)
|
72
70
|
json (2.9.1)
|
73
|
-
json-schema (4.3.1)
|
74
|
-
addressable (>= 2.8)
|
75
71
|
language_server-protocol (3.17.0.4)
|
76
72
|
logger (1.6.5)
|
77
73
|
loofah (2.24.0)
|
78
74
|
crass (~> 1.0.2)
|
79
75
|
nokogiri (>= 1.12.0)
|
80
76
|
minitest (5.25.4)
|
81
|
-
mutex_m (0.3.0)
|
82
77
|
nokogiri (1.18.2-x86_64-darwin)
|
83
78
|
racc (~> 1.4)
|
84
79
|
parallel (1.26.3)
|
@@ -91,7 +86,6 @@ GEM
|
|
91
86
|
psych (5.2.3)
|
92
87
|
date
|
93
88
|
stringio
|
94
|
-
public_suffix (6.0.1)
|
95
89
|
racc (1.8.1)
|
96
90
|
rack (3.1.9)
|
97
91
|
rack-session (2.1.0)
|
@@ -108,10 +102,10 @@ GEM
|
|
108
102
|
rails-html-sanitizer (1.6.2)
|
109
103
|
loofah (~> 2.21)
|
110
104
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
111
|
-
railties (
|
112
|
-
actionpack (=
|
113
|
-
activesupport (=
|
114
|
-
irb
|
105
|
+
railties (8.0.2)
|
106
|
+
actionpack (= 8.0.2)
|
107
|
+
activesupport (= 8.0.2)
|
108
|
+
irb (~> 1.13)
|
115
109
|
rackup (>= 1.0.0)
|
116
110
|
rake (>= 12.2)
|
117
111
|
thor (~> 1.0, >= 1.2.2)
|
@@ -169,7 +163,7 @@ GEM
|
|
169
163
|
rubocop (~> 1.61)
|
170
164
|
ruby-progressbar (1.13.0)
|
171
165
|
securerandom (0.4.1)
|
172
|
-
sqlite3 (
|
166
|
+
sqlite3 (2.2.0-x86_64-darwin)
|
173
167
|
stringio (3.1.2)
|
174
168
|
thor (1.3.2)
|
175
169
|
timeout (0.4.3)
|
@@ -178,6 +172,8 @@ GEM
|
|
178
172
|
unicode-display_width (3.1.4)
|
179
173
|
unicode-emoji (~> 4.0, >= 4.0.4)
|
180
174
|
unicode-emoji (4.0.4)
|
175
|
+
uri (1.0.3)
|
176
|
+
useragent (0.16.11)
|
181
177
|
yard (0.9.37)
|
182
178
|
zeitwerk (2.7.1)
|
183
179
|
|
@@ -185,15 +181,14 @@ PLATFORMS
|
|
185
181
|
x86_64-darwin-22
|
186
182
|
|
187
183
|
DEPENDENCIES
|
188
|
-
activerecord (~>
|
184
|
+
activerecord (~> 8)
|
189
185
|
debug (>= 1.0.0)
|
190
|
-
json-schema (~> 4.1)
|
191
186
|
rake (~> 13.0)
|
192
187
|
rspec (~> 3.12)
|
193
188
|
rspec-rails (~> 6.1)
|
194
189
|
rubocop (~> 1.21)
|
195
190
|
rubocop-rspec (~> 2.25)
|
196
|
-
sqlite3 (~>
|
191
|
+
sqlite3 (~> 2.0, >= 2.0.2)
|
197
192
|
structify!
|
198
193
|
yard (~> 0.9)
|
199
194
|
|
data/README.md
CHANGED
@@ -64,9 +64,24 @@ bundle install
|
|
64
64
|
Add a JSON column to store extracted data:
|
65
65
|
|
66
66
|
```ruby
|
67
|
-
add_column :articles, :
|
67
|
+
add_column :articles, :json_attributes, :jsonb # PostgreSQL (default column name)
|
68
68
|
# or
|
69
|
-
add_column :articles, :
|
69
|
+
add_column :articles, :json_attributes, :json # MySQL (default column name)
|
70
|
+
|
71
|
+
# Or if you configure a custom column name:
|
72
|
+
add_column :articles, :custom_json_column, :jsonb # PostgreSQL
|
73
|
+
```
|
74
|
+
|
75
|
+
## Configuration
|
76
|
+
|
77
|
+
Structify can be configured in an initializer:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# config/initializers/structify.rb
|
81
|
+
Structify.configure do |config|
|
82
|
+
# Configure the default JSON container attribute (default: :json_attributes)
|
83
|
+
config.default_container_attribute = :custom_json_column
|
84
|
+
end
|
70
85
|
```
|
71
86
|
|
72
87
|
## Usage
|
@@ -192,8 +207,8 @@ article.title # => "How AI is Changing Healthcare"
|
|
192
207
|
article.category # => "tech"
|
193
208
|
article.topics # => ["machine learning", "healthcare"]
|
194
209
|
|
195
|
-
# All data is in the JSON column
|
196
|
-
article.
|
210
|
+
# All data is in the JSON column (default column name: json_attributes)
|
211
|
+
article.json_attributes # => The complete JSON
|
197
212
|
```
|
198
213
|
|
199
214
|
## Field Types
|
@@ -324,6 +339,18 @@ article_v3.summary = "Added in v3"
|
|
324
339
|
article_v3.save! # Record version is automatically updated to 3
|
325
340
|
```
|
326
341
|
|
342
|
+
### Accessing the Container Attribute
|
343
|
+
|
344
|
+
The JSON container attribute can be accessed directly:
|
345
|
+
|
346
|
+
```ruby
|
347
|
+
# Using the default container attribute :json_attributes
|
348
|
+
article.json_attributes # => { "title" => "My Title", "version" => 1, ... }
|
349
|
+
|
350
|
+
# If you've configured a custom container attribute
|
351
|
+
article.custom_json_column # => { "title" => "My Title", "version" => 1, ... }
|
352
|
+
```
|
353
|
+
|
327
354
|
|
328
355
|
## Understanding Structify's Role
|
329
356
|
|
data/lib/structify/model.rb
CHANGED
@@ -30,17 +30,25 @@ module Structify
|
|
30
30
|
include AttrJson::Record
|
31
31
|
class_attribute :schema_builder, instance_writer: false, default: nil
|
32
32
|
|
33
|
-
#
|
34
|
-
attr_json_config(default_container_attribute:
|
33
|
+
# Use the configured default container attribute
|
34
|
+
attr_json_config(default_container_attribute: Structify.configuration.default_container_attribute)
|
35
35
|
end
|
36
36
|
|
37
37
|
# Instance methods
|
38
38
|
def version_compatible_with?(required_version)
|
39
|
-
|
40
|
-
|
39
|
+
container_attribute = self.class.attr_json_config.default_container_attribute
|
40
|
+
record_data = self.send(container_attribute) || {}
|
41
|
+
record_version = record_data["version"] || 1
|
41
42
|
record_version >= required_version
|
42
43
|
end
|
43
44
|
|
45
|
+
# Get the stored version of this record
|
46
|
+
def stored_version
|
47
|
+
container_attribute = self.class.attr_json_config.default_container_attribute
|
48
|
+
record_data = self.send(container_attribute) || {}
|
49
|
+
record_data["version"] || 1
|
50
|
+
end
|
51
|
+
|
44
52
|
# Check if a version is within a given range/array of versions
|
45
53
|
# This is used in field accessors to check version compatibility
|
46
54
|
#
|
@@ -286,9 +294,13 @@ module Structify
|
|
286
294
|
|
287
295
|
# Override reader to check version compatibility
|
288
296
|
def #{name}
|
297
|
+
# Get the container attribute and data
|
298
|
+
container_attribute = self.class.attr_json_config.default_container_attribute
|
299
|
+
record_data = self.send(container_attribute)
|
300
|
+
|
289
301
|
# Get the version from the record data
|
290
|
-
record_version =
|
291
|
-
|
302
|
+
record_version = record_data && record_data["version"] ?
|
303
|
+
record_data["version"] : 1
|
292
304
|
|
293
305
|
# Check if record version is compatible with field's version range
|
294
306
|
field_version_range = #{version_range.inspect}
|
data/lib/structify/version.rb
CHANGED
data/lib/structify.rb
CHANGED
@@ -23,6 +23,29 @@ require_relative "structify/model"
|
|
23
23
|
# end
|
24
24
|
# end
|
25
25
|
module Structify
|
26
|
+
# Configuration class for Structify
|
27
|
+
class Configuration
|
28
|
+
# @return [Symbol] The default container attribute for JSON fields
|
29
|
+
attr_accessor :default_container_attribute
|
30
|
+
|
31
|
+
def initialize
|
32
|
+
@default_container_attribute = :json_attributes
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Structify::Configuration] The current configuration
|
37
|
+
def self.configuration
|
38
|
+
@configuration ||= Configuration.new
|
39
|
+
end
|
40
|
+
|
41
|
+
# Configure Structify
|
42
|
+
# @yield [config] The configuration block
|
43
|
+
# @yieldparam config [Structify::Configuration] The configuration object
|
44
|
+
# @return [Structify::Configuration] The updated configuration
|
45
|
+
def self.configure
|
46
|
+
yield(configuration) if block_given?
|
47
|
+
configuration
|
48
|
+
end
|
26
49
|
# Base error class for Structify
|
27
50
|
class Error < StandardError; end
|
28
51
|
|
data/structify.gemspec
CHANGED
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: structify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kieran Klaassen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '7.0'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '9.0'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '7.0'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '9.0'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: attr_json
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|