attribeauty 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c705d3129b34e6dbc91c53163face634eafbc288a2b36b2768faf97a77a7f8a
4
- data.tar.gz: 1553078b6ae388c7d75c367e9f70b2e1153b59b4999ce7fbe7da7bf078d64725
3
+ metadata.gz: 0635b380b4cb80f46aa693faef308dd93acf646950c8a592efe9ee56f3f019d1
4
+ data.tar.gz: f47043d7784f3068f3f82575bc71a5cdf7006cc73e8a8b4f481381a55091cb84
5
5
  SHA512:
6
- metadata.gz: efb29ddb06c0c1391d661efcc43b4b1e122233a7c0a481f0fe5bb96a00fe190e0bd05e87640f8f16872ca32c9bd6aaf7120665a6f931b8d41d60109dc8ac49af
7
- data.tar.gz: 9c10fb519ec0eaaffd5a31d02c5aea808917fd2ce0b3421ba4e4edf1c4b8dba796ac2fddda907e62e79ba9edf8c8c2355dc37a564346b7377979994ef57ea603
6
+ metadata.gz: 90040026bba413f4390d1c8141140dc90d7547b47e1af3ec737d23a6ec79c7a9ca9677086318b4d44107acdaf39b8587711e41231074ad80854c619eb3a02883
7
+ data.tar.gz: 747703281202de16748413ecee1703ad15a6353a31caa289bf77b68e41d6ca820cf2d0bce5087af54ab7c39a237b398492701fa964a02af707dc00c4131fd487
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.3.1] - 2024-06-22
4
+
5
+ - added container to exclude the "head" param
6
+
3
7
  ## [0.3.0] - 2024-06-21
4
8
 
5
9
  - Experimental params coercion
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attribeauty (0.3.0)
4
+ attribeauty (0.3.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Attribeauty
2
2
 
3
3
  I just wanted a quick, simple way to initialize mutable objects. This is it.
4
- There are so many of these, but none were what I wanted.
4
+ There are so many of these (notably rails Attributes api), but none were what I wanted.
5
5
 
6
6
  ## Installation
7
7
 
@@ -13,7 +13,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
13
13
 
14
14
  $ gem install attribeauty
15
15
 
16
- ## Usage
16
+ ## Base
17
17
 
18
18
  Inherit from `Attribeauty::Base` and then add attribute with the type you want.
19
19
  Initialize with these and they will be cast to that attribute.
@@ -111,6 +111,44 @@ class MyController
111
111
  end
112
112
  ```
113
113
 
114
+ If you have a "head" param, like in rails, you can exclude it like this:
115
+
116
+ ```
117
+ class MyController
118
+ def update
119
+ MyRecord.update(update_params)
120
+
121
+ redirect_to index_path
122
+ end
123
+
124
+ private
125
+
126
+ # your params look like this:
127
+ # { user: { title: "woo", email: { address: "hmm@yep.com" } } }
128
+ #
129
+ def params_filter
130
+ Attribeauty::Params.with(request.params)
131
+ end
132
+
133
+ # using container will exclude the value and yield:
134
+ # { title: "woo", email: { address: "hmm@yep.com" } }
135
+ #
136
+ def update_params
137
+ params_filter.accept do
138
+ container :user do
139
+ attribute :title, :string, allow_nil: false, required: true
140
+ attribute :email do
141
+ attribute :address, :string, allow_empty: false
142
+ attribute :valid, :boolean, allow_nil: false
143
+ attribute :ip_address, :string, allow_blank: true
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
149
+
150
+ ```
151
+
114
152
  See `test/test_params.rb` for what is expected.
115
153
 
116
154
 
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "forwardable"
4
-
5
3
  module Attribeauty
6
4
  class Params
7
5
  extend Forwardable
@@ -32,6 +30,12 @@ module Attribeauty
32
30
  to_h[key]
33
31
  end
34
32
 
33
+ def container(name)
34
+ @request_params = request_params[name]
35
+
36
+ yield
37
+ end
38
+
35
39
  # rubocop:disable Naming::BlockForwarding
36
40
  def attribute(name, type = nil, **args, &block)
37
41
  value = request_params[name]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Attribeauty
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/attribeauty.rb CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "date"
4
4
  require "time"
5
+ require "forwardable"
5
6
 
6
7
  # Module
7
8
  module Attribeauty
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.3.0
4
+ version: 0.3.1
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-21 00:00:00.000000000 Z
11
+ date: 2024-06-22 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: