structify 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56ca4a2c78aa18b382aa54c4ba88ef246bd2014f895db59fb877ecfd5cb12edf
4
- data.tar.gz: 7cb8abbf4ebc23b68a7c19492d4a5fa648d89bfea4dd49a632418a3a962be1cc
3
+ metadata.gz: 1542f94c3a228a96c611d5d8c4a9a76ff97b6070321a0b88166d6182a0eec652
4
+ data.tar.gz: a10e778ed0ea8958b4d111f6b6d49dac5a534ebe05926656760115a60a685856
5
5
  SHA512:
6
- metadata.gz: 16e43c43971e51405759fd3cdf1cd12759ffef115313c144938d5dea704583e04fff57dfd388682127321b71c527131ed3d6edade964db6bb55e9b1c43900744
7
- data.tar.gz: 9de0c840ee85e0ac8722b518125461672006624d70d2d7317e5df9db4832a6bd454e030c2790fab8d6e408d4e694039c4a50f471bf4a45e3a523929d59c7473e
6
+ metadata.gz: 764c252133923dbd6c340087f58f902ae5753bf2c6d56c65244b81dbbce2fc63da22c0b5b5734049dcc908dbc3c846c8f7f85ee40ff5c8d43ba3f0484a3fe8ec
7
+ data.tar.gz: c2ba694a9c738fd3067f3cb7c6c4d69fe707664075dc65d1ff7c3ac1d9c29a4b4d166b95767edc6fab202219d042c50e9699d0d266f3489e84ea35efbe182fa7
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", "~> 7.1.0"
11
- gem "sqlite3", "~> 1.6.0" # For testing with ActiveRecord
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.1.0)
5
- activesupport (~> 7.1)
4
+ structify (0.3.0)
5
+ activesupport (~> 8)
6
6
  attr_json (~> 2.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actionpack (7.1.5.1)
12
- actionview (= 7.1.5.1)
13
- activesupport (= 7.1.5.1)
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
- actionview (7.1.5.1)
22
- activesupport (= 7.1.5.1)
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 (7.1.5.1)
28
- activesupport (= 7.1.5.1)
29
- activerecord (7.1.5.1)
30
- activemodel (= 7.1.5.1)
31
- activesupport (= 7.1.5.1)
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 (7.1.5.1)
33
+ activesupport (8.0.2)
34
34
  base64
35
35
  benchmark (>= 0.3)
36
36
  bigdecimal
37
- concurrent-ruby (~> 1.0, >= 1.0.2)
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
- addressable (2.8.7)
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 (7.1.5.1)
112
- actionpack (= 7.1.5.1)
113
- activesupport (= 7.1.5.1)
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 (1.6.9-x86_64-darwin)
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 (~> 7.1.0)
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 (~> 1.6.0)
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, :extracted_data, :jsonb # PostgreSQL
67
+ add_column :articles, :json_attributes, :jsonb # PostgreSQL (default column name)
68
68
  # or
69
- add_column :articles, :extracted_data, :json # MySQL
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.extracted_data # => The complete JSON
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
 
@@ -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
- # Store all extracted data in the extracted_data JSON column
34
- attr_json_config(default_container_attribute: :extracted_data)
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
- record_version = self.extracted_data && self.extracted_data["version"] ?
40
- self.extracted_data["version"] : 1
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 = self.extracted_data && self.extracted_data["version"] ?
291
- self.extracted_data["version"] : 1
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}
@@ -1,3 +1,3 @@
1
1
  module Structify
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
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
@@ -26,6 +26,6 @@ Gem::Specification.new do |spec|
26
26
  spec.require_paths = ["lib"]
27
27
 
28
28
  # Runtime dependencies
29
- spec.add_dependency "activesupport", "~> 7.1"
29
+ spec.add_dependency "activesupport", "~> 8"
30
30
  spec.add_dependency "attr_json", "~> 2.1"
31
31
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: structify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
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-13 00:00:00.000000000 Z
11
+ date: 2025-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '7.1'
19
+ version: '8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '7.1'
26
+ version: '8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: attr_json
29
29
  requirement: !ruby/object:Gem::Requirement