massager 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/massager.rb +18 -0
- data/lib/massager/attributes/attribute_with_multiple_keys.rb +7 -1
- data/lib/massager/attributes/attribute_with_single_key.rb +7 -1
- data/lib/massager/errors/constraint_error.rb +4 -0
- data/lib/massager/hashify.rb +13 -0
- data/lib/massager/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bb5f8e586ab12d52bd6754f918c955a8bcfc7b35
|
4
|
+
data.tar.gz: de71786ff585c916936b4c6d6f3a9309ca054518
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca80f2aa124b47bd794ab56fd94aba597b1534349561e7588ad3cd1c88f191d1dd66ebba9d5c4334ce1fd1397b1eece186f45edc36d9c911faf4cfc11b2ef1d8
|
7
|
+
data.tar.gz: 5d16cc90a4e2301f5b297c27458958134624eceda586bcc420a58943bf11e71d28073cee298bc22df3c33c724e1534b32b4348f1022754a42da5a41af5c642b9
|
data/lib/massager.rb
CHANGED
@@ -4,10 +4,27 @@ require "dry-monads"
|
|
4
4
|
require "dry-container"
|
5
5
|
require "set"
|
6
6
|
|
7
|
+
require "massager/errors/constraint_error"
|
7
8
|
require "massager/attributes/attribute_with_single_key"
|
8
9
|
require "massager/attributes/attribute_with_multiple_keys"
|
10
|
+
require "massager/hashify"
|
9
11
|
|
10
12
|
module Massager
|
13
|
+
module InstanceMethods
|
14
|
+
def [](name)
|
15
|
+
public_send(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_hash
|
19
|
+
self.class._container.keys.select {|a| a.include?("attributes.")}.each_with_object({}) do |key, result|
|
20
|
+
attribute_name = key.gsub("attributes.", "").to_sym
|
21
|
+
result[attribute_name] = Hashify[self[attribute_name]]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
alias_method :to_h, :to_hash
|
26
|
+
end
|
27
|
+
|
11
28
|
module ClassMethods
|
12
29
|
def attribute(name, *target_keys, **opts, &block)
|
13
30
|
case
|
@@ -92,5 +109,6 @@ module Massager
|
|
92
109
|
|
93
110
|
def self.included(base)
|
94
111
|
base.extend(ClassMethods)
|
112
|
+
base.include(InstanceMethods)
|
95
113
|
end
|
96
114
|
end
|
@@ -8,7 +8,13 @@ module Massager
|
|
8
8
|
def call(values)
|
9
9
|
values = values.values_at(*keys)
|
10
10
|
values = block.call(*values)
|
11
|
-
Dry::Monads::Maybe(opts[:type]).fmap {|type|
|
11
|
+
Dry::Monads::Maybe(opts[:type]).fmap {|type|
|
12
|
+
begin
|
13
|
+
value = type.call(values)
|
14
|
+
rescue Dry::Types::ConstraintError
|
15
|
+
raise Massager::ConstraintError, "Attribute #{name} did not pass the constraint for value of #{values.inspect}"
|
16
|
+
end
|
17
|
+
}
|
12
18
|
values
|
13
19
|
end
|
14
20
|
|
@@ -7,7 +7,13 @@ module Massager
|
|
7
7
|
def call(values)
|
8
8
|
value = values.fetch(key)
|
9
9
|
Dry::Monads::Maybe(block).fmap {|block| value = block.call(value)}
|
10
|
-
Dry::Monads::Maybe(opts[:type]).fmap {|type|
|
10
|
+
Dry::Monads::Maybe(opts[:type]).fmap {|type|
|
11
|
+
begin
|
12
|
+
value = type.call(value)
|
13
|
+
rescue Dry::Types::ConstraintError
|
14
|
+
raise Massager::ConstraintError, "Attribute #{name} did not pass the constraint for value of #{value}"
|
15
|
+
end
|
16
|
+
}
|
11
17
|
value
|
12
18
|
end
|
13
19
|
|
data/lib/massager/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: massager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Janis Miezitis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-types
|
@@ -101,6 +101,8 @@ files:
|
|
101
101
|
- lib/massager.rb
|
102
102
|
- lib/massager/attributes/attribute_with_multiple_keys.rb
|
103
103
|
- lib/massager/attributes/attribute_with_single_key.rb
|
104
|
+
- lib/massager/errors/constraint_error.rb
|
105
|
+
- lib/massager/hashify.rb
|
104
106
|
- lib/massager/version.rb
|
105
107
|
- massager.gemspec
|
106
108
|
homepage: http://github.com/janjiss/massager
|