yuba 0.0.5 → 0.0.9

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: 7d13a7bddc245ba124ce105b6827afb261d6268a417809a6bc7ec04e70cff0b9
4
- data.tar.gz: c4769bdc11c239e2c99d848ab99f9b13309c5f6c4064b53b52b4087c025eeaa8
3
+ metadata.gz: 972ae9498c1bcea0f825f330d594b94ec00d487f8369faeab51ccf72cd95ecf9
4
+ data.tar.gz: 907c054c3471e936f6c4665971dc6e555b93ea83586c606ab0b971ade8842ffd
5
5
  SHA512:
6
- metadata.gz: 8337d0d4addebc3bd44412fd23d4433ebb6f17d53db5e63dcfe666b4dda6351de39450f9d48ef7fc225d62871b52d90082cefac7e6b705b38b185c1c2e9c7733
7
- data.tar.gz: 77447d91b1a2d68dd7cbf44055188d5e2bb6ac45b3b8e17af5101b0ce04952f7c4accb25f394eca3e8ba4a5b51690faba9978c45619a42603a265a19acd3c040
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
- Version of this gem is now 0.0.x. It works but there must be occasional breaking changes to the API.
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 add new layers to rails.
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 by themselves.
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 4.2+
39
- - Ruby 2.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 controller.
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 register property to the class.
71
+ `.property` method registers property to the class.
73
72
 
74
- Those registered by property need to be passed as arguments to the `initialize` except when `optional: true` is attached. You get ArgumentError if you don't pass `property` to `initialize`.
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. This means you can use it in internal the instance. If you want to use it as public, use `public: true` option.
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 get it's public methods (include public property) and assign them to instance variables in view template. So you can write `<%= @post.title %>` instead of `<%= @view_model.post.title %>`
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 useful when controller has many application logic.
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 register property to the class like ViewModel.
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
@@ -4,7 +4,7 @@ module Yuba
4
4
  class Form < ::Reform::Form
5
5
  module Coercion
6
6
  module Types
7
- include Dry::Types.module
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::Form::#{class_name}".constantize
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|
@@ -16,7 +16,7 @@ module Yuba::Form::MultiParameterAttributes
16
16
  params.delete("#{date_attribute}(3i)"),
17
17
  params.delete("#{date_attribute}(4i)"),
18
18
  params.delete("#{date_attribute}(5i)")
19
- )
19
+ ).to_s
20
20
  end
21
21
  end
22
22
 
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
@@ -1,3 +1,3 @@
1
1
  module Yuba
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.9'
3
3
  end
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.5
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: 2021-01-29 00:00:00.000000000 Z
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.12.2
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.12.2
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.1.2
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: []