attribeauty 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +40 -2
- data/lib/attribeauty/params.rb +6 -2
- data/lib/attribeauty/version.rb +1 -1
- data/lib/attribeauty.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0635b380b4cb80f46aa693faef308dd93acf646950c8a592efe9ee56f3f019d1
|
4
|
+
data.tar.gz: f47043d7784f3068f3f82575bc71a5cdf7006cc73e8a8b4f481381a55091cb84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90040026bba413f4390d1c8141140dc90d7547b47e1af3ec737d23a6ec79c7a9ca9677086318b4d44107acdaf39b8587711e41231074ad80854c619eb3a02883
|
7
|
+
data.tar.gz: 747703281202de16748413ecee1703ad15a6353a31caa289bf77b68e41d6ca820cf2d0bce5087af54ab7c39a237b398492701fa964a02af707dc00c4131fd487
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
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
|
-
##
|
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
|
|
data/lib/attribeauty/params.rb
CHANGED
@@ -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]
|
data/lib/attribeauty/version.rb
CHANGED
data/lib/attribeauty.rb
CHANGED
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.
|
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-
|
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:
|