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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9fc7f483875f6696ab2d7c7b3ce6e9d56d5128c
4
- data.tar.gz: 95da1a8a7ea68c15737b1fb35abbd9e63cc5a185
3
+ metadata.gz: c3c57b81e95b17456845c98c47e46139419b2e7f
4
+ data.tar.gz: 36668d890f197b9d17d32258126ec8ed1d00e04b
5
5
  SHA512:
6
- metadata.gz: 02568a1247cd0da8c2814c61c295ac4079803a38f4eab52075adc2101826fb809dc82b54720798ca67903ea009602e6c7c0988b5995fce158968fd02252080b1
7
- data.tar.gz: 0c2f4a9973d8a95a99e0cd571a08cacd6c6a60cbb6e4e45fad5f2591236c44730c09585143331161d581208d1a23440fec9245be4da23911d7eba013b48c5526
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/[my-github-username]/value_object/fork )
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 "value_object/version"
2
- require "value_object/base"
3
- require "value_object/attribute"
4
- require "value_object/errors"
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(name, klass)
9
- id_attr = "#{name}_id"
8
+ def value_attribute(attr_name, klass)
9
+ id_attr = "#{attr_name}_id"
10
10
 
11
- define_method name do
11
+ define_method attr_name do
12
12
  klass.find self.public_send(id_attr)
13
13
  end
14
14
 
15
- define_method "#{name}=" do |obj|
16
- self.public_send("#{id_attr}=", obj.id)
15
+ define_method "#{attr_name}=" do |obj|
16
+ self.public_send("#{id_attr}=", obj.key)
17
17
  end
18
18
  end
19
19
  end
@@ -1,26 +1,12 @@
1
1
  module ValueObject
2
- class Base < Struct.new(:name, :id)
3
- class << self
4
- def find(id)
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
- attr_accessor :all
6
+ attr_reader :key
10
7
 
11
- protected
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
@@ -1,4 +1,4 @@
1
1
  module ValueObject
2
- class InvalidValue < defined?(ActiveRecord::RecordNotFound) ? ActiveRecord::RecordNotFound : StandardError
2
+ class InvalidValue < StandardError
3
3
  end
4
4
  end
@@ -3,7 +3,7 @@ require 'i18n'
3
3
  module ValueObject
4
4
  module I18n
5
5
  def name_s
6
- ::I18n.t(self.name, scope: [:value_objects, self.class.name.to_sym], default: self.name)
6
+ ::I18n.t(self.key, scope: [:value_objects, self.class.name.to_sym], default: self.key)
7
7
  end
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module ValueObject
2
- VERSION = "1.1.0"
2
+ VERSION = "2.0.1"
3
3
  end
data/value_object.gemspec CHANGED
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.9"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "pry", "~> 0.10"
28
29
  end
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: 1.1.0
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: 2015-06-24 00:00:00.000000000 Z
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.8
101
+ rubygems_version: 2.4.5
87
102
  signing_key:
88
103
  specification_version: 4
89
104
  summary: ValueObjects compliant with most ruby ORM