attribeauty 0.4.4 → 0.4.6

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: cea80fa1b1b1eedce5673a87e9a4a34e65e897d4f1f1756d044a8ee37c4d961e
4
- data.tar.gz: 798d5bab20443753941eebb76810a667700e09e70b9c82019e2a20ec2a64a2d5
3
+ metadata.gz: e043b4e5f8fcbdfd096c6cd5deabfca25667b5c0e3a2754b8106f250e12569cd
4
+ data.tar.gz: 450ccb28494f3b5dbde4d3f56113997bf5d3e85dfb6fee82a1f683ca85e7523e
5
5
  SHA512:
6
- metadata.gz: 232c14b463c2f6fcffc213079b0df03c61078f6b3f4c680784a4613c4025fb36249d87f17c5fc144749863cb0baa3af8ff1fa08d04d3ec399286f4c3c5e31175
7
- data.tar.gz: e2e7426248fdd68bc46c5efb5b3aea9d4841e6012c92ed105e1b1c7d7db7965025acf0622945dc109dc20f257564593663bb67588ade867274200c0bd09901ac
6
+ metadata.gz: a44271c47fdec0e64fcfa8bae79b426d88a67b3c5eae25201c7ce675f1b9188308dfb5c13df908c3701bef1f7350bf786becf0d395b6ff5ce918d2706f4a6bed
7
+ data.tar.gz: '048046380ad6ac7c65b7406beeb222ee553beea2bed15ea2b855dfdac4b19243537046caeb579d21eb3d536b3e758323f38e6cfb0cbec8d8fea90284331aca00'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.4.6] - 2024-06-28
4
+
5
+ - unofficial support for auto generating rails models params filtering
6
+ - no tests, and simply a script I'm using in an app to do the same
7
+
8
+ ## [0.4.5] - 2024-06-27
9
+
10
+ - using `root` instead of `container`, this is what serializers use
11
+
3
12
  ## [0.4.4] - 2024-06-26
4
13
 
5
14
  - get `default:` working. Not expecting to use them since db will handle that, but nice to have?
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attribeauty (0.4.4)
4
+ attribeauty (0.4.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -133,12 +133,12 @@ class MyController
133
133
  Attribeauty::Params.with(request.params)
134
134
  end
135
135
 
136
- # using container will exclude the value and yield:
136
+ # using root will exclude the value and yield:
137
137
  # { title: "woo", email: { address: "hmm@yep.com" } }
138
138
  #
139
139
  def update_params
140
140
  params_filter.accept do
141
- container :user do
141
+ root :user do
142
142
  attribute :title, :string, required: true
143
143
  attribute :email do
144
144
  attribute :address, :string, exclude_if: [:empty?, :nil?]
@@ -177,7 +177,7 @@ class MyController
177
177
  #
178
178
  def update_params
179
179
  params_filter.accept! do
180
- container :user do
180
+ root :user do
181
181
  attribute :title, :string, exclude_if: :nil?, required: true
182
182
  attribute :email do
183
183
  attribute :address, :string
@@ -215,7 +215,7 @@ class MyController
215
215
  #
216
216
  def update_params
217
217
  params_filter.accept exclude_if: :nil?, required: true do
218
- container :user do
218
+ root :user do
219
219
  attribute :title, :string,
220
220
  attribute :email do
221
221
  attribute :address, :string
@@ -43,7 +43,7 @@ module Attribeauty
43
43
  to_h[key] = value
44
44
  end
45
45
 
46
- def container(name)
46
+ def root(name)
47
47
  @request_params = request_params[name]
48
48
 
49
49
  yield
@@ -68,6 +68,20 @@ module Attribeauty
68
68
  strict
69
69
  end
70
70
 
71
+ def generate_for(model, *columns)
72
+ raise "Method requires Rails" unless defined?(Rails)
73
+
74
+ root_node = model.to_s.downcase.to_sym
75
+ cols = columns.map(&:to_s)
76
+ root root_node do
77
+ model.columns_hash.slice(*cols).each_value do |table|
78
+ attrs = table.name.to_sym, table.type
79
+ attrs << { exclude_if: :nil? } if table.null == false
80
+ attribute(*attrs)
81
+ end
82
+ end
83
+ end
84
+
71
85
  private
72
86
 
73
87
  def value_from_validator(name, value, type, **args)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Attribeauty
4
- VERSION = "0.4.4"
4
+ VERSION = "0.4.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attribeauty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toby
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-26 00:00:00.000000000 Z
11
+ date: 2024-06-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: There are so many of these, I just needed this one.
14
14
  email: