class_kit 0.7.1 → 0.8.0

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: 5862b302a6e1c4dddaa15da72f07cc526de5ae2dd0c61c7aed4abec281656cc8
4
- data.tar.gz: 3fee66206edb8a6bdf64911420d00e5057f16e30206b032b2a674a585a9d7408
3
+ metadata.gz: 4f501847a8ffea1775ff197945234f28865db2ba0188b35d469b9e2968f00d2f
4
+ data.tar.gz: 37c4acff0fc0114dc9cc4e4fe9c2c41acc294fa4d54e3e53e99149ac0afb17ad
5
5
  SHA512:
6
- metadata.gz: e0aa0a7303439cf8c049dbaa4d0876cdcdfdec51d10adf68455ff9bebf951c0c73544eea8f56e7bdcb59835f04c78de6d975ceff6aad0e687abdb921139b857b
7
- data.tar.gz: 4d793c93ff3170a45aab2cce0a91ee6dbd4209bc3490af5be019e0601d9370f6cb7ca5d240209b9dc52252d8b865f80c8cc169a30c1dcc1274230314fb94c78f
6
+ metadata.gz: 77507663db94f9e8d8da1a77bde21ef2000f40124a3a776de446715a133b944aa132fe71cf68dd7197b1434a6a70b0817dfcb455b4a2808d57f3878ad4472d59
7
+ data.tar.gz: b2f047deffc4c43fb07b09b6ba8d9a7d9d732c1f0b5ed5192af614182e1bf6703fb72bcd3b0fb4a4dee010db515bc7f700f0b4c09cdf3b03b7cd43e297b000fe
@@ -0,0 +1,22 @@
1
+ module ClassKit
2
+ module CustomType
3
+ def self.included(base)
4
+ base.extend(CustomType)
5
+ end
6
+
7
+ # This method must return the parsed value when +from_hash+ is called
8
+ def self.parse_from_hash(_value)
9
+ raise NotImplementedError
10
+ end
11
+
12
+ # This method must return the parsed value when the class' attribute is assigned a value
13
+ def self.parse_assign(_value)
14
+ raise NotImplementedError
15
+ end
16
+
17
+ # This method must return the value that will be serialised for the attribute
18
+ def to_hash_value
19
+ raise NotImplementedError
20
+ end
21
+ end
22
+ end
@@ -11,6 +11,10 @@ module ClassKit
11
11
  klass.is_a?(ClassKit)
12
12
  end
13
13
 
14
+ def is_class_kit_custom_type?(klass)
15
+ !klass.nil? && klass != :bool && klass.include?(ClassKit::CustomType)
16
+ end
17
+
14
18
  def validate_class_kit(klass)
15
19
  is_class_kit?(klass) || raise(ClassKit::Exceptions::InvalidClassError,
16
20
  "Class: #{klass} does not implement ClassKit.")
@@ -32,10 +36,14 @@ module ClassKit
32
36
  if value != nil
33
37
  hash[key] = if is_class_kit?(type)
34
38
  to_hash(value, use_alias)
39
+ elsif is_class_kit_custom_type?(type)
40
+ value.to_hash_value
35
41
  elsif type == Array
36
42
  value.map do |i|
37
43
  if is_class_kit?(i.class)
38
44
  to_hash(i, use_alias)
45
+ elsif is_class_kit_custom_type?(i.class)
46
+ i.to_hash_value
39
47
  else
40
48
  i
41
49
  end
@@ -67,6 +75,8 @@ module ClassKit
67
75
 
68
76
  value = if is_class_kit?(type)
69
77
  from_hash(hash: hash[key], klass: type, use_alias: use_alias)
78
+ elsif is_class_kit_custom_type?(type)
79
+ type.parse_from_hash(hash[key])
70
80
  elsif type == Array
71
81
  hash[key].map do |array_element|
72
82
  if attribute[:collection_type].nil?
@@ -74,6 +84,8 @@ module ClassKit
74
84
  else
75
85
  if is_class_kit?(attribute[:collection_type])
76
86
  from_hash(hash: array_element, klass: attribute[:collection_type], use_alias: use_alias)
87
+ elsif is_class_kit_custom_type?(attribute[:collection_type])
88
+ attribute[:collection_type].parse_from_hash(array_element)
77
89
  else
78
90
  @value_helper.parse(type: attribute[:collection_type], value: array_element)
79
91
  end
@@ -17,16 +17,12 @@ module ClassKit
17
17
  elsif type == Date
18
18
  if value.is_a?(Date)
19
19
  value
20
- elsif value.is_a?(Integer)
21
- Date.at(value)
22
20
  else
23
21
  Date.parse(value)
24
22
  end
25
23
  elsif type == DateTime
26
24
  if value.is_a?(DateTime)
27
25
  value
28
- elsif value.is_a?(Integer)
29
- DateTime.at(value)
30
26
  else
31
27
  DateTime.parse(value)
32
28
  end
@@ -62,6 +58,8 @@ module ClassKit
62
58
  elsif type == Array
63
59
  raise 'Unable to parse Array' unless value.is_a?(Array)
64
60
  value
61
+ elsif type.include?(ClassKit::CustomType)
62
+ type.parse_assign(value)
65
63
  else
66
64
  raise 'Unable to parse'
67
65
  end
@@ -1,5 +1,5 @@
1
1
  # Namespace
2
2
  module ClassKit
3
3
  # :nodoc:
4
- VERSION = '0.7.1'
4
+ VERSION = '0.8.0'
5
5
  end
data/lib/class_kit.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require_relative 'class_kit/class_methods'
2
2
  require_relative 'class_kit/exceptions'
3
3
  require_relative 'class_kit/attribute_helper'
4
+ require_relative 'class_kit/custom_type'
4
5
  require_relative 'class_kit/value_helper'
5
6
  require_relative 'class_kit/helper'
6
7
  require_relative 'class_kit/version'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: class_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sage One
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-10-17 00:00:00.000000000 Z
11
+ date: 2021-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '2'
20
20
  type: :development
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: '1.11'
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: simplecov
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "<"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.18.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "<"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.18.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: hash_kit
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -118,6 +118,7 @@ files:
118
118
  - lib/class_kit.rb
119
119
  - lib/class_kit/attribute_helper.rb
120
120
  - lib/class_kit/class_methods.rb
121
+ - lib/class_kit/custom_type.rb
121
122
  - lib/class_kit/exceptions.rb
122
123
  - lib/class_kit/exceptions/attribute_not_found_error.rb
123
124
  - lib/class_kit/exceptions/invalid_attribute_value_error.rb
@@ -145,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
145
146
  - !ruby/object:Gem::Version
146
147
  version: '0'
147
148
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.7.7
149
+ rubygems_version: 3.1.2
150
150
  signing_key:
151
151
  specification_version: 4
152
152
  summary: Toolkit for working with classes