as_value 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43c9866bd21f9300afff131ffa77cd86a3eac904
4
+ data.tar.gz: 529233a4157fa4ca6fa41b068dc0b0ad037e7d74
5
+ SHA512:
6
+ metadata.gz: 252a1b6c4026fa83039077bd55c9a158fbc7dc62be1ab0619d7c04379fe23d8df6acaf011a18b1b2e12caae1e76533c0ec18eae5ba025be87a9b5c7b507f76d6
7
+ data.tar.gz: befd8b10eeaa22763b524a11775328e77b7d67bc2bd54df8788f8eb3e9d3e8114b610d2514aa4ffef0e5771bf94baac8775d3d5b3c81bb9e03bfa03caf83eb5a
data/MIT-LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Bradley Ankrom
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ module AsValue::ValueObject
2
+
3
+ module InstanceMethods
4
+
5
+ def initialize(params = {})
6
+ self.class.send(:attr_accessor, *instance_attributes)
7
+
8
+ params.each do |key, value|
9
+ send("#{key}=", value) if instance_attributes.include? key
10
+ end
11
+
12
+ freeze!
13
+ end
14
+
15
+ def instance_attributes
16
+ self.class.instance_variable_get(:@instance_attributes)
17
+ end
18
+
19
+ def to_h
20
+ Hash[instance_attributes.map { |attribute| [attribute, send(attribute)] }]
21
+ end
22
+
23
+ def hash
24
+ to_h.sort.hash
25
+ end
26
+
27
+ def ==(other)
28
+ hash == other.hash
29
+ end
30
+
31
+ alias_method :eql?, :==
32
+
33
+ def freeze!
34
+ instance_attributes.each do |attribute|
35
+ define_singleton_method("#{attribute}=") do |*|
36
+ fail AsValue::ImmutableObjectError,
37
+ "ValueObjects are immutable -- write methods are unavailable."
38
+ end
39
+ end
40
+ self.freeze
41
+ end
42
+ end
43
+
44
+ def instance_attributes(*attributes)
45
+ @instance_attributes = attributes
46
+ end
47
+
48
+ def self.extended(base); base.include(InstanceMethods); end
49
+ end
data/lib/as_value.rb ADDED
@@ -0,0 +1,12 @@
1
+ module AsValue
2
+
3
+ ImmutableObjectError = Class.new(StandardError)
4
+
5
+ VERSION = [0,0,1]
6
+
7
+ def self.version
8
+ VERSION.join('.')
9
+ end
10
+
11
+ require 'as_value/value_object'
12
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: as_value
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bradley Ankrom
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: |-
28
+ Extend AsValue to create Ruby value objects; based on the ValueObject described by Martin Fowler in his book,
29
+ 'Patterns of Enterprise Application Architecture'.
30
+ email:
31
+ - bradley@aller.io
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - MIT-LICENSE
37
+ - lib/as_value.rb
38
+ - lib/as_value/value_object.rb
39
+ homepage: http://github.com/bradleyankrom/as_value
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.2.2
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Easily create value objects.
63
+ test_files: []