value_object-ruby 1.1.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/value_object.rb +5 -4
- data/lib/value_object/attribute.rb +5 -5
- data/lib/value_object/base.rb +6 -20
- data/lib/value_object/dsl.rb +31 -0
- data/lib/value_object/errors.rb +1 -1
- data/lib/value_object/i18n.rb +1 -1
- data/lib/value_object/version.rb +1 -1
- data/value_object.gemspec +1 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3c57b81e95b17456845c98c47e46139419b2e7f
|
4
|
+
data.tar.gz: 36668d890f197b9d17d32258126ec8ed1d00e04b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7296c54efeb28c7edf1438916f41103ae786860ef07856783decec84b0e15b3e77807c1d1b466ae270760828aff88cbc9b262c8a4223c03f558538bfa45d1925
|
7
|
+
data.tar.gz: 3d236b5aa11ced5065e42578f68949a97f1a46a34aba8e8dedcf64bda0ce0f2a3e16525801b58bfedac108da18bf91a82f2e2403ea6cb6c539aacb2622fdda8c
|
data/README.md
CHANGED
@@ -32,7 +32,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
32
32
|
|
33
33
|
## Contributing
|
34
34
|
|
35
|
-
1. Fork it ( https://github.com/
|
35
|
+
1. Fork it ( https://github.com/xjunior/value_object/fork )
|
36
36
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
37
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
38
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/value_object.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require 'value_object/version'
|
2
|
+
require 'value_object/dsl'
|
3
|
+
require 'value_object/base'
|
4
|
+
require 'value_object/attribute'
|
5
|
+
require 'value_object/errors'
|
@@ -5,15 +5,15 @@ module ValueObject
|
|
5
5
|
end
|
6
6
|
|
7
7
|
module ClassMethods
|
8
|
-
def value_attribute(
|
9
|
-
id_attr = "#{
|
8
|
+
def value_attribute(attr_name, klass)
|
9
|
+
id_attr = "#{attr_name}_id"
|
10
10
|
|
11
|
-
define_method
|
11
|
+
define_method attr_name do
|
12
12
|
klass.find self.public_send(id_attr)
|
13
13
|
end
|
14
14
|
|
15
|
-
define_method "#{
|
16
|
-
self.public_send("#{id_attr}=", obj.
|
15
|
+
define_method "#{attr_name}=" do |obj|
|
16
|
+
self.public_send("#{id_attr}=", obj.key)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/value_object/base.rb
CHANGED
@@ -1,26 +1,12 @@
|
|
1
1
|
module ValueObject
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
return unless id
|
6
|
-
all.find {|v| v.id.to_s.eql?(id.to_s)} || raise(ValueObject::InvalidValue, "#{self.name} with id #{id} not found")
|
7
|
-
end
|
2
|
+
# Rubocop wants me to document you
|
3
|
+
class Base
|
4
|
+
extend ::ValueObject::DSL
|
8
5
|
|
9
|
-
|
6
|
+
attr_reader :key
|
10
7
|
|
11
|
-
|
12
|
-
|
13
|
-
def value(name, id, *args)
|
14
|
-
object = new(name, id, *args)
|
15
|
-
define_value_getter object
|
16
|
-
|
17
|
-
@all ||= []
|
18
|
-
@all << object
|
19
|
-
end
|
20
|
-
|
21
|
-
def define_value_getter(object)
|
22
|
-
define_singleton_method(object.name) { object }
|
23
|
-
end
|
8
|
+
def initialize(key)
|
9
|
+
@key = key
|
24
10
|
end
|
25
11
|
end
|
26
12
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module ValueObject
|
2
|
+
module DSL
|
3
|
+
def find(key)
|
4
|
+
return unless key
|
5
|
+
object = all.find { |v| v.key.to_s.eql?(key.to_s) }
|
6
|
+
object || raise_invalid_value(key)
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_accessor :all
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def value(*args)
|
14
|
+
object = new(*args)
|
15
|
+
define_value_getter object
|
16
|
+
|
17
|
+
@all ||= []
|
18
|
+
@all << object
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def define_value_getter(object)
|
24
|
+
define_singleton_method(object.key) { object }
|
25
|
+
end
|
26
|
+
|
27
|
+
def raise_invalid_value(key)
|
28
|
+
raise(ValueObject::InvalidValue, "#{self} #{key} not found")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/value_object/errors.rb
CHANGED
data/lib/value_object/i18n.rb
CHANGED
data/lib/value_object/version.rb
CHANGED
data/value_object.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: value_object-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carlos Palhares
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.10'
|
41
55
|
description: ValueObjects compliant with most ruby ORM, allowing a class to have a
|
42
56
|
relation with a value object in similarly to any other relation
|
43
57
|
email:
|
@@ -59,6 +73,7 @@ files:
|
|
59
73
|
- lib/value_object.rb
|
60
74
|
- lib/value_object/attribute.rb
|
61
75
|
- lib/value_object/base.rb
|
76
|
+
- lib/value_object/dsl.rb
|
62
77
|
- lib/value_object/errors.rb
|
63
78
|
- lib/value_object/i18n.rb
|
64
79
|
- lib/value_object/version.rb
|
@@ -83,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
98
|
version: '0'
|
84
99
|
requirements: []
|
85
100
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.4.
|
101
|
+
rubygems_version: 2.4.5
|
87
102
|
signing_key:
|
88
103
|
specification_version: 4
|
89
104
|
summary: ValueObjects compliant with most ruby ORM
|