yuba 0.0.3 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 290adbd946ac8cad632dd7d5cb975a4d5c68d831e9cbbeb7e3f6e42b89fd1b26
4
- data.tar.gz: 583c456070ce6dd43c470de3db139a4e8fc2c5753dc9a7dcd74021b33b4383c4
3
+ metadata.gz: 5194de3e17a63c28eea57ebb3d33e4a8ae03fae8a4433bcaad3514110586de2b
4
+ data.tar.gz: a85114bd871291f3436afae4c878f07fcfbd7e713e26c42439a21c975278efda
5
5
  SHA512:
6
- metadata.gz: ba927cfa71760e4b4e59e2959678783eaea2c77b9cd9eb746cc78b091d85ad23300f99da6770c36cc6f4f3fe7c07cc5d7f118cbaee1bae3fbd863d3dbbda404c
7
- data.tar.gz: bf0e9248993e20e124a6de98eeb7b5bce9fa629ac16d7d32702b3f167cfcc5f042477ea2bf789c2a70ca9e43a51280c196bd1c56191e80379d33460f78462801
6
+ metadata.gz: b3e1cd7e45ac09787b546db39fea103c4d396a8d2ca33df494e6d475291e954a03ecbda027039292fdf4f41782238dc3d0fb3f329fc84f40a7c0810fc5831942
7
+ data.tar.gz: fbb40d7809090a4ed252d4c801939e354fb0b6b7051be9b7c9860aba81fac9bdcdcefcf7be5fd02ae4a97832a3dcb06c803d061e48498edb03cace5997812f97
data/README.md CHANGED
@@ -35,8 +35,8 @@ $ bundle install
35
35
 
36
36
  ## Support
37
37
 
38
- - Rails 4.2+
39
- - Ruby 2.2+
38
+ - Rails 5.2+
39
+ - Ruby 2.5+
40
40
 
41
41
  ## ViewModel
42
42
 
@@ -154,6 +154,18 @@ end
154
154
  - `.call` invokes `#call` after assigning arguments as properties.
155
155
  - `#success?` returns `true` if you don't invoke `#fail!`
156
156
 
157
+ You have inspection methods for properties.
158
+
159
+ ```ruby
160
+ service = CreatePostService.new(user: someuser)
161
+ service.has_property?(:user) #=> true
162
+ service.has_value?(:user) #=> true
163
+ service.has_public_property?(:user) #=> true
164
+ service.has_private_property?(:user) #=> false
165
+ service.has_required_property?(:user) #=> true
166
+ service.has_optional_property?(:user) #=> false
167
+ ```
168
+
157
169
  ## Form
158
170
 
159
171
  Form is just wrapper of [reform-rails](https://github.com/trailblazer/reform-rails) for now.
@@ -178,6 +190,7 @@ class ArtistsController < ApplicationController
178
190
  render :new
179
191
  end
180
192
  end
193
+ end
181
194
  ```
182
195
 
183
196
  ```ruby
data/lib/yuba/service.rb CHANGED
@@ -11,7 +11,7 @@ module Yuba
11
11
  end
12
12
 
13
13
  def property(name, options = {})
14
- _properties[name.to_sym] = options
14
+ self._properties = _properties.merge(name.to_sym => options)
15
15
  end
16
16
  end
17
17
 
@@ -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)
@@ -45,6 +71,12 @@ module Yuba
45
71
  raise ArgumentError, "missing 'property :#{key}' in #{self.class.name} class"
46
72
  end
47
73
  end
74
+
75
+ required_keys = _required_properties.keys
76
+ missing_keys = required_keys - args.keys
77
+ unless missing_keys.empty?
78
+ raise ArgumentError, "missing required arguments: #{missing_keys.join(',')}"
79
+ end
48
80
  end
49
81
 
50
82
  def define_accessors(args)
@@ -56,5 +88,9 @@ module Yuba
56
88
  self.singleton_class.class_eval { private key.to_sym } unless public_method
57
89
  end
58
90
  end
91
+
92
+ def _required_properties
93
+ _properties.reject { |_, value| value[:optional] }
94
+ end
59
95
  end
60
96
  end
data/lib/yuba/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yuba
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.8'
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.3
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - willnet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-30 00:00:00.000000000 Z
11
+ date: 2021-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.0
19
+ version: 5.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.0
26
+ version: 5.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: reform-rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -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: 0.12.2
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: 0.12.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: chromedriver-helper
126
+ name: webdrivers
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -179,8 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
- rubyforge_project:
183
- rubygems_version: 2.7.6
182
+ rubygems_version: 3.1.6
184
183
  signing_key:
185
184
  specification_version: 4
186
185
  summary: Add New Layers to Rails