bukowskis_value_object 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +35 -0
- data/lib/bukowskis_value_object.rb +1 -0
- data/lib/value_object.rb +30 -0
- data/lib/value_object/permissive.rb +19 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/value_object_spec.rb +31 -0
- metadata +134 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0d4314221600322c7396758b1d83348c25b3b531
|
4
|
+
data.tar.gz: 7c11ece39409faa83a47f6a6a6d8780ac3521653
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1fd08e3251d407b5e846f8a09ddb3aa92861bb11f72f375463d0feb1c875b8663141bae4ea369894ced4718f3ae21f6a7f7a0038d4038fd6b53b449d864de665
|
7
|
+
data.tar.gz: 8c478c7e3f7dc6507afbe633d500bd88917c4dc66d2a9bed3c95bae4a0ea5ab52f33632cf1f7d1d9087167a0c68cd5027a94b9751d1270fe419951a9bc99d493
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# BukowskisValueObject
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bukowskis_value_object`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'bukowskis_value_object'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install bukowskis_value_object
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jens/bukowskis_value_object.
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'value_object'
|
data/lib/value_object.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'dry-initializer'
|
2
|
+
require 'value_object/permissive'
|
3
|
+
|
4
|
+
module ValueObject
|
5
|
+
def self.included(base)
|
6
|
+
base.extend Dry::Initializer
|
7
|
+
base.extend ClassMethods
|
8
|
+
base.prepend Initializer
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def attribute(*args)
|
13
|
+
option(*args)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module Initializer
|
18
|
+
def initialize(**data)
|
19
|
+
source_keys = self.class.dry_initializer.options.map(&:source)
|
20
|
+
unknown_keys = data.keys - source_keys
|
21
|
+
|
22
|
+
raise KeyError, "Key(s) #{unknown_keys} not found in #{source_keys}" if unknown_keys.any?
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def attributes
|
28
|
+
self.class.dry_initializer.public_attributes(self)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ValueObject
|
2
|
+
module Permissive
|
3
|
+
def self.included(base)
|
4
|
+
base.extend Dry::Initializer
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.prepend Initializer
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def attribute(*args)
|
11
|
+
option(*args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def attributes
|
16
|
+
self.class.dry_initializer.public_attributes(self)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
require "bukowskis_value_object"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
# Enable flags like --only-failures and --next-failure
|
6
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
7
|
+
|
8
|
+
# Disable RSpec exposing methods globally on `Module` and `main`
|
9
|
+
config.disable_monkey_patching!
|
10
|
+
|
11
|
+
config.expect_with :rspec do |c|
|
12
|
+
c.syntax = :expect
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class MyValue
|
2
|
+
include ValueObject
|
3
|
+
attribute :foo
|
4
|
+
end
|
5
|
+
|
6
|
+
RSpec.describe ValueObject do
|
7
|
+
describe ".new" do
|
8
|
+
it "raises if you give it an unknown attribute" do
|
9
|
+
expect do
|
10
|
+
MyValue.new(foo: 'hello', unexpected_value: 'surprise')
|
11
|
+
end.to raise_error(KeyError)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".attribute" do
|
16
|
+
it "defines a reader" do
|
17
|
+
expect(MyValue.new(foo: 'hello').foo).to eq('hello')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "does not define a writer" do
|
21
|
+
expect(MyValue.new(foo: 'hello')).not_to respond_to(:foo=)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#attributes" do
|
26
|
+
it "is a hash of the attributes" do
|
27
|
+
value = MyValue.new(foo: 'hello')
|
28
|
+
expect(value.attributes).to eq(foo: 'hello')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bukowskis_value_object
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bukowskis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-06-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-initializer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
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'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec_junit_formatter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Module for creating value objects
|
98
|
+
email:
|
99
|
+
executables: []
|
100
|
+
extensions: []
|
101
|
+
extra_rdoc_files: []
|
102
|
+
files:
|
103
|
+
- README.md
|
104
|
+
- lib/bukowskis_value_object.rb
|
105
|
+
- lib/value_object.rb
|
106
|
+
- lib/value_object/permissive.rb
|
107
|
+
- spec/spec_helper.rb
|
108
|
+
- spec/value_object_spec.rb
|
109
|
+
homepage:
|
110
|
+
licenses: []
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: '0'
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 2.5.1
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: Module for creating value objects
|
132
|
+
test_files:
|
133
|
+
- spec/spec_helper.rb
|
134
|
+
- spec/value_object_spec.rb
|