clean-architecture 0.0.5 → 0.1.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
  SHA1:
3
- metadata.gz: 29d2b604ce2c99cc43eb8d12974961ea498fa45e
4
- data.tar.gz: f8a4be0c752f19d34d62ec1de688b53ad4640299
3
+ metadata.gz: 9c12933e54f79e602a9aa26cc2f959e1ce7decd0
4
+ data.tar.gz: bf30e8c044d46f04e02028b53375b492af95b033
5
5
  SHA512:
6
- metadata.gz: 64abafd4b1fe4c99bbbad2dec5de6ee925767d818a696bf29bc9712f30bb6b6c464f270fca95436d599a9bcdfe41aa38e15a330d5bfeba139335859fb6c59fad
7
- data.tar.gz: c7bafa6e2e76ac50422649687fd335c3544785daa7934828ec2a5a78de21cd2bf032cc23e347cdfe16252894bdf10f9b4725563e0d4651b6dd29daee869cb94c
6
+ metadata.gz: 638aeb1b5ab5435392e652472aec5ffc05d3055bc0a3d2862c2e222ffa676be53729fdd48c0589a7e3b376b6c4245f723f45e31519ac4cea2a17d47c96c2922d
7
+ data.tar.gz: b6c3a7b94a70c92b38833c2d5de6f11f728042382da0fcbc67ea7a53ace3c69a79611ba3a3c0879b0c404a56078203bbf3c2cfdbeb8d0f93c7501367af00f350
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ 0.1.0
2
+
3
+ * Add Adapters::AttributeHashBase
4
+
1
5
  0.0.3 - 0.0.5
2
6
 
3
7
  * Fix require files
data/Gemfile.lock CHANGED
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- clean-architecture (0.0.4)
5
- dry-matcher
6
- dry-monads
7
- duckface-interfaces
4
+ clean-architecture (0.1.0)
5
+ dry-matcher (~> 0.0)
6
+ dry-monads (~> 1.0)
7
+ duckface-interfaces (~> 0.0)
8
8
 
9
9
  GEM
10
10
  remote: https://rubygems.org/
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
19
19
  end
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'dry-matcher'
23
- spec.add_dependency 'dry-monads'
24
- spec.add_dependency 'duckface-interfaces'
22
+ spec.add_dependency 'dry-matcher', '~> 0.0'
23
+ spec.add_dependency 'dry-monads', '~> 1.0'
24
+ spec.add_dependency 'duckface-interfaces', '~> 0.0'
25
25
 
26
- spec.add_development_dependency 'bundler', '>= 1.13'
27
- spec.add_development_dependency 'rake', '>= 10.0'
28
- spec.add_development_dependency 'rspec', '>= 3.0'
26
+ spec.add_development_dependency 'bundler', '~> 1.13'
27
+ spec.add_development_dependency 'rake', '~> 12.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.0'
29
29
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ # THIS FILE IS AUTOGENERATED AND SHOULD NOT BE MANUALLY MODIFIED
4
+
5
+ require 'clean_architecture/adapters/attribute_hash_base'
@@ -0,0 +1,133 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ # frozen_string_literal: true
6
+
7
+ module CleanArchitecture
8
+ module Adapters
9
+ # Allows you to implement an interface around a hash with type safety
10
+ class AttributeHashBase
11
+ # Error raised if an expected value isn't present or isn't the type we expect
12
+ class EmptyOrIncorrectAttributeTypeError < StandardError; end
13
+
14
+ def initialize(attribute_hash)
15
+ @attribute_hash = attribute_hash
16
+ end
17
+
18
+ protected
19
+
20
+ attr_reader :attribute_hash
21
+
22
+ private
23
+
24
+ def ensured_value(default:)
25
+ yield
26
+ rescue EmptyOrIncorrectAttributeTypeError, TypeError, ArgumentError
27
+ default
28
+ end
29
+
30
+ def maybe_value
31
+ ensured_value(default: nil) { yield }
32
+ end
33
+
34
+ def boolean_value(key)
35
+ raw_value(key).to_s == 'true'
36
+ end
37
+
38
+ def complex_object_value(key, adapter_class)
39
+ adapter_class.new(raw_value(key))
40
+ end
41
+
42
+ def complex_object_list_value(key, adapter_class, additional_arguments = [])
43
+ array = maybe_raw_value(key) || []
44
+ unless array.is_a?(Array)
45
+ raise EmptyOrIncorrectAttributeTypeError, "value at key #{key} is not an array!"
46
+ end
47
+ array.map { |array_entry| adapter_class.new(array_entry, *additional_arguments) }
48
+ end
49
+
50
+ def currency_value(key)
51
+ float_value(key).round(2)
52
+ end
53
+
54
+ def date_value(key)
55
+ Date.parse(raw_value(key))
56
+ end
57
+
58
+ def time_value(key)
59
+ Time.parse(raw_value(key))
60
+ end
61
+
62
+ def date_time_value(key)
63
+ Time.strptime(raw_value(key), '%Y-%m-%dT%H:%M:%S.%L%z')
64
+ end
65
+
66
+ def float_value(key)
67
+ raw_value(key).to_f
68
+ end
69
+
70
+ def int_value(key)
71
+ raw_value(key).to_i
72
+ end
73
+
74
+ def regex_value(key)
75
+ raw_pattern = raw_value(key)
76
+ return raw_pattern if raw_pattern.is_a?(Regexp)
77
+ /#{raw_pattern}/
78
+ end
79
+
80
+ def maybe_complex_object_value(key, adapter_class)
81
+ maybe_value { complex_object_value(key, adapter_class) }
82
+ end
83
+
84
+ def maybe_date_value(key)
85
+ maybe_value { date_value(key) }
86
+ end
87
+
88
+ def maybe_time_value(key)
89
+ maybe_value { time_value(key) }
90
+ end
91
+
92
+ def maybe_date_time_value(key)
93
+ maybe_value { date_time_value(key) }
94
+ end
95
+
96
+ def maybe_int_value(key)
97
+ maybe_value { int_value(key) }
98
+ end
99
+
100
+ def maybe_float_value(key)
101
+ maybe_value { float_value(key) }
102
+ end
103
+
104
+ def maybe_string_value(key)
105
+ maybe_value { string_value(key) }
106
+ end
107
+
108
+ def string_value(key)
109
+ raw_value(key).to_s
110
+ end
111
+
112
+ def symbol_value(key)
113
+ string_value(key).to_sym
114
+ end
115
+
116
+ def maybe_raw_value(key)
117
+ maybe_value { raw_value(key) }
118
+ end
119
+
120
+ EMPTY_VALUES = [nil, ''].freeze
121
+
122
+ def raw_value(key)
123
+ value = @attribute_hash[key]
124
+ if EMPTY_VALUES.include?(value)
125
+ raise EmptyOrIncorrectAttributeTypeError, "value at key #{key} is empty!"
126
+ end
127
+ value
128
+ end
129
+
130
+ private_constant :EMPTY_VALUES
131
+ end
132
+ end
133
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  # THIS FILE IS AUTOGENERATED AND SHOULD NOT BE MANUALLY MODIFIED
4
4
 
5
+ require 'clean_architecture/adapters/all'
5
6
  require 'clean_architecture/entities/all'
6
7
  require 'clean_architecture/interfaces/all'
7
8
  require 'clean_architecture/queries/all'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CleanArchitecture
4
- VERSION = '0.0.5'
4
+ VERSION = '0.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clean-architecture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bellroy Tech Team
@@ -14,84 +14,84 @@ dependencies:
14
14
  name: dry-matcher
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.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: '0'
26
+ version: '0.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dry-monads
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: duckface-interfaces
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.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'
54
+ version: '0.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '1.13'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.13'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '10.0'
75
+ version: '12.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: '10.0'
82
+ version: '12.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '3.0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.0'
97
97
  description: An attempt at building a reusable Clean Architecture framework for Ruby
@@ -116,6 +116,8 @@ files:
116
116
  - clean-architecture.gemspec
117
117
  - generate_require_files.rb
118
118
  - lib/clean-architecture.rb
119
+ - lib/clean_architecture/adapters/all.rb
120
+ - lib/clean_architecture/adapters/attribute_hash_base.rb
119
121
  - lib/clean_architecture/all.rb
120
122
  - lib/clean_architecture/entities/all.rb
121
123
  - lib/clean_architecture/entities/targeted_parameters.rb