yuba 0.0.5 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -16
- data/lib/yuba/form/coercion.rb +2 -2
- data/lib/yuba/form/multi_parameter_attributes.rb +1 -1
- data/lib/yuba/service.rb +26 -0
- data/lib/yuba/version.rb +1 -1
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 972ae9498c1bcea0f825f330d594b94ec00d487f8369faeab51ccf72cd95ecf9
|
4
|
+
data.tar.gz: 907c054c3471e936f6c4665971dc6e555b93ea83586c606ab0b971ade8842ffd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4944859716ce1cd8b5771cacfb1d718b019bf69cdaf54ffa81c52c4a70a86fc69ed648da1b8fc252ce176d1a9ec6e87eb7aeada7f37a86f85c8f86e86aa2f49f
|
7
|
+
data.tar.gz: 3d94063165609298b2dda4e15dfd5e96505b38f5fde9008da3443a437ae69a6437a0ad7d3b9633ea80e9c48e7c89e8179c73e389d947983cae543456292c9776
|
data/README.md
CHANGED
@@ -5,19 +5,18 @@
|
|
5
5
|
|
6
6
|
## warning
|
7
7
|
|
8
|
-
|
8
|
+
The version of this gem is now 0.0.x. It works, but there must be occasional breaking changes to the API.
|
9
9
|
|
10
10
|
## Summary
|
11
11
|
|
12
|
-
Yuba
|
12
|
+
Yuba adds new layers to rails.
|
13
13
|
|
14
14
|
- Service
|
15
15
|
- Form
|
16
16
|
- ViewModel
|
17
17
|
|
18
|
-
It is convenient to use them in combination, but you can use them even
|
19
|
-
|
20
|
-
If you have difficulties with large rails application, Yuba help you.
|
18
|
+
It is convenient to use them in combination, but you can use them even individually.
|
19
|
+
If you have difficulties with a large rails application, Yuba helps you.
|
21
20
|
|
22
21
|
## Installation
|
23
22
|
|
@@ -35,12 +34,12 @@ $ bundle install
|
|
35
34
|
|
36
35
|
## Support
|
37
36
|
|
38
|
-
- Rails
|
39
|
-
- Ruby 2.
|
37
|
+
- Rails 5.2+
|
38
|
+
- Ruby 2.5+
|
40
39
|
|
41
40
|
## ViewModel
|
42
41
|
|
43
|
-
ViewModel is useful when there are many instance variables in
|
42
|
+
ViewModel is useful when there are many instance variables in controllers.
|
44
43
|
|
45
44
|
```ruby
|
46
45
|
class PostViewModel < Yuba::ViewModel
|
@@ -69,15 +68,15 @@ view.post #=> NoMethodError
|
|
69
68
|
|
70
69
|
### property
|
71
70
|
|
72
|
-
`.property` method
|
71
|
+
`.property` method registers property to the class.
|
73
72
|
|
74
|
-
|
73
|
+
We need to pass those properties as arguments to the `initialize` except when `optional: true` is attached. You get ArgumentError if you don't pass `property` to `initialize`.
|
75
74
|
|
76
|
-
Property is default to private.
|
75
|
+
Property is default to private. It means you can use it in the internal instance. If you want to use it as public, use `public: true` option.
|
77
76
|
|
78
77
|
### Auto Assign
|
79
78
|
|
80
|
-
You can use ViewModel in a controller like following
|
79
|
+
You can use ViewModel in a controller like the following.
|
81
80
|
|
82
81
|
```ruby
|
83
82
|
class PostsController < ApplicationController
|
@@ -98,11 +97,11 @@ class PostsController < ApplicationController
|
|
98
97
|
end
|
99
98
|
```
|
100
99
|
|
101
|
-
view_model option of render takes ViewModel, which
|
100
|
+
view_model option of render takes ViewModel, which gets its public methods (include public property) and assigns them to instance variables in the view template. So you can write `<%= @post.title %>` instead of `<%= @view_model.post.title %>`
|
102
101
|
|
103
102
|
## Service
|
104
103
|
|
105
|
-
Service is
|
104
|
+
Service is valuable when a controller has many application logic.
|
106
105
|
|
107
106
|
```ruby
|
108
107
|
class PostController < ApplicationController
|
@@ -150,10 +149,22 @@ class CreatePostService < Yuba::Service
|
|
150
149
|
end
|
151
150
|
```
|
152
151
|
|
153
|
-
- `.property` method
|
152
|
+
- `.property` method registers property to the class like ViewModel.
|
154
153
|
- `.call` invokes `#call` after assigning arguments as properties.
|
155
154
|
- `#success?` returns `true` if you don't invoke `#fail!`
|
156
155
|
|
156
|
+
You have inspection methods for properties.
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
service = CreatePostService.new(user: someuser)
|
160
|
+
service.has_property?(:user) #=> true
|
161
|
+
service.has_value?(:user) #=> true
|
162
|
+
service.has_public_property?(:user) #=> true
|
163
|
+
service.has_private_property?(:user) #=> false
|
164
|
+
service.has_required_property?(:user) #=> true
|
165
|
+
service.has_optional_property?(:user) #=> false
|
166
|
+
```
|
167
|
+
|
157
168
|
## Form
|
158
169
|
|
159
170
|
Form is just wrapper of [reform-rails](https://github.com/trailblazer/reform-rails) for now.
|
@@ -231,7 +242,7 @@ rails generate yuba:view_model artist_index
|
|
231
242
|
|
232
243
|
## Contributing
|
233
244
|
|
234
|
-
You can try to test by doing as following
|
245
|
+
You can try to test by doing as following.
|
235
246
|
|
236
247
|
```
|
237
248
|
git clone https://github.com/willnet/yuba.git
|
data/lib/yuba/form/coercion.rb
CHANGED
@@ -4,7 +4,7 @@ module Yuba
|
|
4
4
|
class Form < ::Reform::Form
|
5
5
|
module Coercion
|
6
6
|
module Types
|
7
|
-
include Dry
|
7
|
+
include Dry.Types
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
@@ -17,7 +17,7 @@ module Yuba
|
|
17
17
|
|
18
18
|
def coercing_setter!(name, type)
|
19
19
|
class_name = type.to_s.classify
|
20
|
-
type_class = "Yuba::Form::Coercion::Types::
|
20
|
+
type_class = "Yuba::Form::Coercion::Types::Params::#{class_name}".constantize
|
21
21
|
|
22
22
|
mod = Module.new do
|
23
23
|
define_method("#{name}=") do |value|
|
data/lib/yuba/service.rb
CHANGED
@@ -37,6 +37,32 @@ module Yuba
|
|
37
37
|
!@_success
|
38
38
|
end
|
39
39
|
|
40
|
+
def has_property?(property)
|
41
|
+
_properties.has_key?(property.to_sym)
|
42
|
+
end
|
43
|
+
|
44
|
+
def has_required_property?(property)
|
45
|
+
has_property?(property) && !_properties.dig(property.to_sym, :optional)
|
46
|
+
end
|
47
|
+
|
48
|
+
def has_optional_property?(property)
|
49
|
+
has_property?(property) && !has_required_property?(property)
|
50
|
+
end
|
51
|
+
|
52
|
+
def has_public_property?(property)
|
53
|
+
has_property?(property) && !has_private_property?(property)
|
54
|
+
end
|
55
|
+
|
56
|
+
def has_private_property?(property)
|
57
|
+
has_property?(property) && !_properties.dig(property.to_sym, :public)
|
58
|
+
end
|
59
|
+
|
60
|
+
def has_value?(property)
|
61
|
+
has_property?(property) && respond_to?(property, true) && !send(property).nil?
|
62
|
+
end
|
63
|
+
|
64
|
+
alias_method :value?, :has_value?
|
65
|
+
|
40
66
|
private
|
41
67
|
|
42
68
|
def validate_arguments(args)
|
data/lib/yuba/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yuba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- willnet
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: dry-types
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0
|
47
|
+
version: '1.0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0
|
54
|
+
version: '1.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -164,7 +164,7 @@ homepage: https://github.com/willnet/yuba
|
|
164
164
|
licenses:
|
165
165
|
- MIT
|
166
166
|
metadata: {}
|
167
|
-
post_install_message:
|
167
|
+
post_install_message:
|
168
168
|
rdoc_options: []
|
169
169
|
require_paths:
|
170
170
|
- lib
|
@@ -179,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
179
179
|
- !ruby/object:Gem::Version
|
180
180
|
version: '0'
|
181
181
|
requirements: []
|
182
|
-
rubygems_version: 3.
|
183
|
-
signing_key:
|
182
|
+
rubygems_version: 3.2.33
|
183
|
+
signing_key:
|
184
184
|
specification_version: 4
|
185
185
|
summary: Add New Layers to Rails
|
186
186
|
test_files: []
|