choron_support 0.1.4 → 0.1.6

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: 5aec7e221e4fc870c2cd989203b23d977c361a55830d4f3ec54732254ef9d68c
4
- data.tar.gz: 7ce392003f8f967ac35019e436dd29230a36d1b2232c5676b98f86820535fcb9
3
+ metadata.gz: 40ef4a2eb00c8d0c4b5d5066eaa7e31cac622c334db5c5cb3d1e1148f911459a
4
+ data.tar.gz: 16cc0ae3bebfd84c59c719b979ef64ded66576345252a33370ddb44f24216504
5
5
  SHA512:
6
- metadata.gz: 3a1eb4b85d33c2e40060b1b4d9941f432a06ba034dc6f8dee696817969bb4da9b7456ceac7be5bce90ce090ffd02e995c593587f0894bfd0f7645017d777b496
7
- data.tar.gz: 7f88d5b647058c03b70f0e95fb02df0b757ea11c2c5c2493a9da4346c876d81713e4c3a7576514c03a9471f5e27f31e1a9eb56febe3aeb5353cefa5e44132148
6
+ metadata.gz: e513dd0ba14ca1df5a4a845885e5b5e0125f47ca568c338ae4f38c6b39ff1e55a21be17ff4cdf8d57994224827ff91d40db8de37ab39e8ab902343188229f65f
7
+ data.tar.gz: c3a527888d13b32efcff166c0af46352c3e57d604837ed86f2c09d5aa2db7482f45ade6004f923887181f31f12da9e3668ae8df648ad5117d7509fd8569c7f9d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- choron_support (0.1.4)
4
+ choron_support (0.1.6)
5
5
  activesupport
6
6
 
7
7
  GEM
@@ -3,13 +3,19 @@ require_relative "props/ext/relation"
3
3
  require_relative "props/ext/hash"
4
4
  module ChoronSupport
5
5
  module AsProps
6
+ class NameError < StandardError; end
7
+ # @param [Symbol, String, nil] type_symbol どのPropsクラスを利用してPropsを生成するかを指定するシンボル。nilのときはデフォルトのPropsクラスを利用する。
8
+ # @param [Hash] params その他のパラメータ。camel: false を指定すると自動でキャメライズしない。
9
+ # @return [Hash]
6
10
  def as_props(type_symbol = nil, **params)
7
11
  serializer = self.__get_props_class(type_symbol, **params)
8
12
 
13
+ skip_camel = (params[:camel] == false)
14
+ pass_params = params.except(:camel)
9
15
  if serializer.nil?
10
- self.as_json
16
+ skip_camel ? self.as_json : self.as_json.as_camel
11
17
  else
12
- serializer.as_props(**params)
18
+ skip_camel ? serializer.as_props(**pass_params) : serializer.as_props(**pass_params).as_camel
13
19
  end
14
20
  end
15
21
 
@@ -39,15 +45,19 @@ module ChoronSupport
39
45
 
40
46
  props_class.new(self)
41
47
  rescue *rescue_errors
42
- return nil
48
+ if type_symbol.blank?
49
+ return nil
50
+ else
51
+ raise ChoronSupport::AsProps::NameError, "Props class not found: #{props_class_name}. Got type symbol: #{type_symbol}."
52
+ end
43
53
  end
44
54
  end
45
55
 
46
56
  def rescue_errors
47
57
  if defined?(Zeitwerk)
48
- [NameError, Zeitwerk::NameError]
58
+ [::NameError, Zeitwerk::NameError]
49
59
  else
50
- [NameError]
60
+ [::NameError]
51
61
  end
52
62
  end
53
63
  end
@@ -2,11 +2,22 @@ require_relative "domains/base"
2
2
 
3
3
  module ChoronSupport
4
4
  module DomainDelegate
5
+ class DelegationError < NoMethodError; end
5
6
  extend ActiveSupport::Concern
6
7
 
7
8
  included do
8
9
  extend Forwardable
9
10
 
11
+ # Forwardable が ActiveSupport#delegate を上書きしてしまうため、間違って使ったときのためエラーをraiseするようにしています
12
+ def self.delegate(*params, **keyparams)
13
+ # delegate :hoge, to: :fuga という形で呼び出された場合は、エラーをraiseする
14
+ if keyparams[:to].present?
15
+ raise DelegationError, "ActiveSupport#delegate is not usable. Please use Forwardable#delegate.\n@example\n delegate size: :array"
16
+ else
17
+ super
18
+ end
19
+ end
20
+
10
21
  # QueryオブジェクトパターンをEasyに使うためのクラスメソッドです
11
22
  # @param [Symbol] method_name Modelに定義されるメソッド名
12
23
  # @param [Choron::Domains::Base] option domain Domainクラスを文字列で直接指定することができます。シンボルを渡すとクラス化を自動で行います。デフォルトはnilです。
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ChoronSupport
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: choron_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - mksava
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-22 00:00:00.000000000 Z
11
+ date: 2023-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport