ph_model 1.0.2 → 1.1.2

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
- SHA1:
3
- metadata.gz: 18eb5a8b10e9378536d448b174f91f656023547c
4
- data.tar.gz: 98833d553696e61f645270860eab78de9e46a9a8
2
+ SHA256:
3
+ metadata.gz: 22c9a24cf0e12f417a5dfa23f3fb967828e9772533bfde21e1ea8ff4547d8bfe
4
+ data.tar.gz: b5ea967101912061b338ed8d80e9bdd06f79848cd3996e7fa51234bd77bec316
5
5
  SHA512:
6
- metadata.gz: 4def997bc8690a1a6273a3fe9006013996980c098bad2a4031fdfc2b3ebeab40eb1ba4a904ef4280afaa177671050bf4d414fc4025ae412b267d48372f1ea440
7
- data.tar.gz: 8b99a104a0715cccba40ad6b1f837d828c72dba5b40e87dbc1f71d3cfb4a0f3a191b83caa8af2a2ac3c0fbdf2ea05e445002f82f07fc546ea3c69c4839487171
6
+ metadata.gz: b33ddd683bbee7054fa38ba0ee5ca8841276d75a3cba2cc3c5915297a9a4a4bcecd9a826339ab23048c8d42a54b26977bc5b6e93765ced081b753b99367c157d
7
+ data.tar.gz: e6b149296201228a3d72a4dd6edad1480a4a97b904e3fa35a1782be1d36e1a4ab8f192395fc15794642c21f8aff62912bec6dee7cf9d909271fad5012ec692bd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Change Log
2
2
 
3
+ ## [v1.1.0](https://github.com/payrollhero/ph_model/tree/v1.1.0) (2017-05-23)
4
+ [Full Changelog](https://github.com/payrollhero/ph_model/compare/v1.0.2...v1.1.0)
5
+
6
+ ## [v1.0.2](https://github.com/payrollhero/ph_model/tree/v1.0.2) (2017-04-06)
7
+ [Full Changelog](https://github.com/payrollhero/ph_model/compare/v1.0.1...v1.0.2)
8
+
9
+ ## [v1.0.1](https://github.com/payrollhero/ph_model/tree/v1.0.1) (2017-04-04)
10
+ [Full Changelog](https://github.com/payrollhero/ph_model/compare/v1.0.0...v1.0.1)
11
+
3
12
  ## [v1.0.0](https://github.com/payrollhero/ph_model/tree/v1.0.0) (2017-04-04)
4
13
  [Full Changelog](https://github.com/payrollhero/ph_model/compare/v0.0.1...v1.0.0)
5
14
 
data/README.md CHANGED
@@ -11,6 +11,7 @@
11
11
  [![Code Climate](https://codeclimate.com/github/payrollhero/ph_model/badges/gpa.svg)](https://codeclimate.com/github/payrollhero/ph_model)
12
12
  [![Issue Count](https://codeclimate.com/github/payrollhero/ph_model/badges/issue_count.svg)](https://codeclimate.com/github/payrollhero/ph_model)
13
13
  [![Dependency Status](https://gemnasium.com/payrollhero/ph_model.svg)](https://gemnasium.com/payrollhero/ph_model)
14
+ [![Gem Version](https://badge.fury.io/rb/ph_model.svg)](https://badge.fury.io/rb/ph_model)
14
15
 
15
16
  This Gem basically marries ActiveModel and ActiveAttr is a nice package.
16
17
 
@@ -18,7 +18,7 @@ module ActiveModel
18
18
  allowed_classes = classes.to_sentence two_words_connector: " or ",
19
19
  last_word_connector: ", or "
20
20
 
21
- record.errors[attribute] << (options[:message] || "must be a #{allowed_classes}")
21
+ record.errors.add(attribute, (options[:message] || "must be a #{allowed_classes}"))
22
22
  end
23
23
  end
24
24
  end
@@ -13,7 +13,7 @@ module PhModel
13
13
  if info[:type].is_a? Array
14
14
  if value.respond_to? :each_with_index
15
15
  value.each_with_index do |item_value, index|
16
- check_one(item_value, "#{attribute_name}[#{index}]")
16
+ check_one(item_value, format_nested_attribute_name(attribute_name, index, item_value))
17
17
  end
18
18
  end
19
19
  else
@@ -22,6 +22,10 @@ module PhModel
22
22
  end
23
23
  end
24
24
 
25
+ def format_nested_attribute_name(attribute_name, index, item_value)
26
+ "#{attribute_name}[#{index}]"
27
+ end
28
+
25
29
  def check_one(value, attribute_name)
26
30
  return if !value.respond_to?(:valid?) || !value.respond_to?(:errors) || value.errors.nil? || value.valid?
27
31
  value.errors.full_messages.each do |message|
@@ -1,5 +1,11 @@
1
1
  module PhModel
2
2
  module Concerns
3
+
4
+ # This will validate any attribute defined with `type: `
5
+ # the type value should be a class, or the special notation `[SomeClass]` which is meant to designate that this is
6
+ # a collection of those classes
7
+ #
8
+ # `no_type_check: true` can be optionally passed to disable this check (other features might use the `type` column)
3
9
  module AttributeTypeValidation
4
10
  extend ActiveSupport::Concern
5
11
 
@@ -9,7 +15,7 @@ module PhModel
9
15
 
10
16
  def ensure_typed_attributes_class
11
17
  self.class.attributes.each do |attribute_name, info|
12
- if info[:type] && !type_match?(attribute_name)
18
+ if info[:type] && !info[:no_type_check] && !type_match?(attribute_name)
13
19
  errors.add(attribute_name, "must be #{info[:type].inspect}, was #{type_summary(attribute_name)}")
14
20
  end
15
21
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module PhModel
3
- VERSION = '1.0.2'.freeze
3
+ VERSION = '1.1.2'.freeze
4
4
  end
data/lib/ph_model.rb CHANGED
@@ -31,7 +31,7 @@ module PhModel
31
31
  include Concerns::AttributeNestedValidation
32
32
  include Concerns::AttributeOfArrayTypeInitialization
33
33
 
34
- def as_json
34
+ def as_json(*)
35
35
  {}.tap do |hash|
36
36
  self.class.attributes.each do |attribute_name, _info|
37
37
  hash[attribute_name] = send(attribute_name).as_json
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ph_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Banasik
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-06 00:00:00.000000000 Z
11
+ date: 2022-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -231,8 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  - !ruby/object:Gem::Version
232
232
  version: '0'
233
233
  requirements: []
234
- rubyforge_project:
235
- rubygems_version: 2.5.2
234
+ rubygems_version: 3.2.32
236
235
  signing_key:
237
236
  specification_version: 4
238
237
  summary: ph-model -- active_model, active_attr brought together at last