valued 0.3.0 → 0.4.0
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/valued.rb +3 -19
- data/lib/valued/mutable.rb +3 -23
- data/lib/valued/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c09b1d932113939667c5e36981e3256b25483679ebc222131d377985152a70a9
|
4
|
+
data.tar.gz: 823e69bdf5587363b1cae66ce2bd68ed8f38aedcdca3bddac5e59b953c27414f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c050eb350406595297da5f44fddd9f8b87e7675ad72596eaf89b8de9075e4da48f873da3750d01f7bd47f986c56efe5dd295900a17f94c1d81aee22459d482f
|
7
|
+
data.tar.gz: bd235452be8f966895982d83b31650bd468af5922e27d97680f04f95e8557cfd87f5c82ca982dc36880b0f2b2b767d9c56fb573ec6e42ed6396c16f433e183e1
|
data/Gemfile.lock
CHANGED
data/lib/valued.rb
CHANGED
@@ -3,29 +3,13 @@ require 'valued/version'
|
|
3
3
|
|
4
4
|
module Valued
|
5
5
|
module ClassMethods
|
6
|
-
def self.normalized_attributes(attributes)
|
7
|
-
attributes.each_with_object(attributes) do |attr, result|
|
8
|
-
result << attr.to_s.chomp('?').to_sym if attr.to_s.end_with?('?')
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
6
|
def self.define_method(attr, klass)
|
13
|
-
klass.class_eval
|
14
|
-
if attr.to_s.end_with?('?')
|
15
|
-
define_method(attr) do
|
16
|
-
instance_variable_get("@#{attr.to_s.chomp('?')}")
|
17
|
-
end
|
18
|
-
else
|
19
|
-
attr_reader attr
|
20
|
-
end
|
21
|
-
end
|
7
|
+
klass.class_eval { attr_reader attr }
|
22
8
|
end
|
23
9
|
|
24
10
|
def attributes(*attributes)
|
25
11
|
attributes.each { |attr| Valued::ClassMethods.define_method(attr, self) }
|
26
|
-
define_method('_attributes')
|
27
|
-
Valued::ClassMethods.normalized_attributes(attributes)
|
28
|
-
end
|
12
|
+
define_method('_attributes') { attributes }
|
29
13
|
private :_attributes
|
30
14
|
end
|
31
15
|
end
|
@@ -49,7 +33,7 @@ module Valued
|
|
49
33
|
_attributes.each do |attribute|
|
50
34
|
if attributes.key?(attribute)
|
51
35
|
instance_variable_set(
|
52
|
-
"@#{attribute
|
36
|
+
"@#{attribute}",
|
53
37
|
attributes.fetch(attribute).freeze
|
54
38
|
)
|
55
39
|
end
|
data/lib/valued/mutable.rb
CHANGED
@@ -1,32 +1,15 @@
|
|
1
1
|
module Valued
|
2
2
|
module Mutable
|
3
3
|
module ClassMethods
|
4
|
-
def self.normalized_attributes(attributes)
|
5
|
-
attributes.each_with_object(attributes) do |attr, result|
|
6
|
-
result << attr.to_s.chomp('?').to_sym if attr.to_s.end_with?('?')
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
4
|
def self.define_method(attr, klass)
|
11
|
-
klass.class_eval
|
12
|
-
if attr.to_s.end_with?('?')
|
13
|
-
define_method(attr) do
|
14
|
-
instance_variable_get("@#{attr.to_s.chomp('?')}")
|
15
|
-
end
|
16
|
-
attr_writer "#{attr.to_s.chomp('?')}".to_sym
|
17
|
-
else
|
18
|
-
attr_accessor attr
|
19
|
-
end
|
20
|
-
end
|
5
|
+
klass.class_eval { attr_accessor attr }
|
21
6
|
end
|
22
7
|
|
23
8
|
def attributes(*attributes)
|
24
9
|
attributes.each do |attr|
|
25
10
|
Valued::Mutable::ClassMethods.define_method(attr, self)
|
26
11
|
end
|
27
|
-
define_method('_attributes')
|
28
|
-
Valued::Mutable::ClassMethods.normalized_attributes(attributes)
|
29
|
-
end
|
12
|
+
define_method('_attributes') { attributes }
|
30
13
|
private :_attributes
|
31
14
|
end
|
32
15
|
end
|
@@ -49,10 +32,7 @@ module Valued
|
|
49
32
|
def initialize(attributes = {})
|
50
33
|
_attributes.each do |attribute|
|
51
34
|
if attributes.key?(attribute)
|
52
|
-
instance_variable_set(
|
53
|
-
"@#{attribute.to_s.chomp('?')}",
|
54
|
-
attributes.fetch(attribute)
|
55
|
-
)
|
35
|
+
instance_variable_set("@#{attribute}", attributes.fetch(attribute))
|
56
36
|
end
|
57
37
|
end
|
58
38
|
end
|
data/lib/valued/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: valued
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mario Mainz
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '1.38'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- mainz.mario@googlemail.com
|
86
86
|
executables: []
|
@@ -107,7 +107,7 @@ licenses:
|
|
107
107
|
metadata:
|
108
108
|
homepage_uri: https://github.com/mmainz/valued
|
109
109
|
source_code_uri: https://github.com/mmainz/valued
|
110
|
-
post_install_message:
|
110
|
+
post_install_message:
|
111
111
|
rdoc_options: []
|
112
112
|
require_paths:
|
113
113
|
- lib
|
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
123
|
version: '0'
|
124
124
|
requirements: []
|
125
125
|
rubygems_version: 3.1.2
|
126
|
-
signing_key:
|
126
|
+
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: A Ruby gem that makes it easy to create value objects.
|
129
129
|
test_files: []
|