vandelay 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +4 -0
- data/LICENSE +8 -0
- data/README.md +54 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/vandelay.rb +6 -0
- data/lib/vandelay/buildable.rb +68 -0
- data/lib/vandelay/version.rb +3 -0
- data/vandelay.gemspec +25 -0
- metadata +121 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d405003045d590b35b10831cbdcd80a2c80ff1cc
|
4
|
+
data.tar.gz: 75ef271c99e4cee9df35a41b3c33499e05f8532f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 90adbf845228d066261d560ed82694e5b56001de50c9c01025dcf4661dda6fe7a9c9ce0ae7725370087fc04df13bdb38e1952c27bede127357360af837e1edb8
|
7
|
+
data.tar.gz: b3c6442fb3ad028c836a679af8ce21d13ebf81600a1535c71f6216221e16f80637e06fc31f638538ed04c50fa4395c287ae36a3e007b4f1e2568acbdf599427d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
vandelay
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.4
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
Copyright (c) 2016 Dean Rex Silfen
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
5
|
+
|
6
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
7
|
+
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Vandelay
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/djds23/Vandelay.svg?branch=master)](https://travis-ci.org/djds23/Vandelay)
|
4
|
+
|
5
|
+
This is one implementation of the [Builder Pattern](https://en.wikipedia.org/wiki/Builder_pattern) in the Ruby programming language. This is primarily used for composing objects to transport a set of data to a receiver with a specific payload. The advantage of using a builder over a plain Hash is using explicit methods to set required fields, and getting a common way to present your data to the receiver. By default, `.build` will transform your data into a hash, but you can override this method to create your preferred format.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'vandelay'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install vandelay
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'vandelay'
|
27
|
+
|
28
|
+
class ToDoBuilder
|
29
|
+
include Vandelay::Buildable
|
30
|
+
|
31
|
+
composed_of :text,
|
32
|
+
:title,
|
33
|
+
:completed_at
|
34
|
+
|
35
|
+
composed_of :created_at, default: Time.now.iso8601
|
36
|
+
end
|
37
|
+
|
38
|
+
new_todo = ToDoBuilder.new
|
39
|
+
|
40
|
+
new_todo.set_title('Write a ruby package')
|
41
|
+
new_todo.set_text('Ruby is fun to write, so why not write a gem?')
|
42
|
+
new_todo.set_completed_at(Time.now.iso8601)
|
43
|
+
```
|
44
|
+
|
45
|
+
## Development
|
46
|
+
|
47
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
48
|
+
|
49
|
+
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).
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/djds23/vandelay.
|
54
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vandelay"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/lib/vandelay.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
module Vandelay
|
2
|
+
module Buildable
|
3
|
+
def self.included(base)
|
4
|
+
|
5
|
+
# Set default values on the base class so buildables
|
6
|
+
# do not over write each other's defaults.
|
7
|
+
base.send :class_variable_set, :@@_internal_hash, {}
|
8
|
+
base.define_singleton_method(:__set_default) do |attribute, default|
|
9
|
+
self.send(:class_variable_get, :@@_internal_hash)[attribute] = default
|
10
|
+
end
|
11
|
+
|
12
|
+
base.send :include, InstanceMethods
|
13
|
+
base.extend ClassMethods
|
14
|
+
end
|
15
|
+
|
16
|
+
module InstanceMethods
|
17
|
+
|
18
|
+
# Returns a hash of all the attributes & their set values.
|
19
|
+
# Best to practice would be to override this for your required formats.
|
20
|
+
#
|
21
|
+
# def build
|
22
|
+
# base = super
|
23
|
+
#
|
24
|
+
# {
|
25
|
+
# extra_fields: 'my_values',
|
26
|
+
# buildable: base
|
27
|
+
# }
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# @return [Hash] filled with attributes and set values
|
31
|
+
def build
|
32
|
+
attribute_hash
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def attribute_hash
|
37
|
+
@@_internal_hash ||= {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def update_attribute_hash(attribute, value)
|
41
|
+
attribute_hash[attribute] = value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module ClassMethods
|
46
|
+
|
47
|
+
# @param [Array] attributes fields that ought to be set on the builder
|
48
|
+
# @option [Object] default
|
49
|
+
def composed_of(*attributes, default: nil)
|
50
|
+
attributes.each do |attribute|
|
51
|
+
compose_setter(attribute, default)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
def compose_setter(attribute, default)
|
57
|
+
__set_default(attribute, default)
|
58
|
+
define_method("set_#{attribute}") do |value|
|
59
|
+
instance_variable_set("@#{attribute}", value)
|
60
|
+
update_attribute_hash(attribute, value)
|
61
|
+
|
62
|
+
self
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/vandelay.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vandelay/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vandelay"
|
8
|
+
spec.version = Vandelay::VERSION
|
9
|
+
spec.authors = ["Dean Silfen"]
|
10
|
+
spec.email = ["dean.silfen@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{An implmentation of the builder pattern for lightweight transport objects}
|
13
|
+
spec.description = %q{This is one implementation of the [Builder Pattern](https://en.wikipedia.org/wiki/Builder_pattern) in the Ruby programming language. This is primarily used for composing objects to transport a set of data to a receiver with a specific payload. The advantage of using a builder over a plain Hash is using explicit methods to set required fields, and getting a common way to present your data to the receiver. By default, `.build` will transform your data into a hash, but you can override this method to create your preferred format.}
|
14
|
+
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
15
|
+
spec.required_ruby_version = '>= 2.1.0'
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.1.0"
|
24
|
+
spec.add_development_dependency "yard", "~> 0.8.7.6"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,121 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vandelay
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dean Silfen
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.8.7.6
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.8.7.6
|
69
|
+
description: This is one implementation of the [Builder Pattern](https://en.wikipedia.org/wiki/Builder_pattern)
|
70
|
+
in the Ruby programming language. This is primarily used for composing objects to
|
71
|
+
transport a set of data to a receiver with a specific payload. The advantage of
|
72
|
+
using a builder over a plain Hash is using explicit methods to set required fields,
|
73
|
+
and getting a common way to present your data to the receiver. By default, `.build`
|
74
|
+
will transform your data into a hash, but you can override this method to create
|
75
|
+
your preferred format.
|
76
|
+
email:
|
77
|
+
- dean.silfen@gmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".rspec"
|
84
|
+
- ".ruby-gemset"
|
85
|
+
- ".ruby-version"
|
86
|
+
- ".travis.yml"
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/console
|
92
|
+
- bin/setup
|
93
|
+
- lib/vandelay.rb
|
94
|
+
- lib/vandelay/buildable.rb
|
95
|
+
- lib/vandelay/version.rb
|
96
|
+
- vandelay.gemspec
|
97
|
+
homepage:
|
98
|
+
licenses: []
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.1.0
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.8
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: An implmentation of the builder pattern for lightweight transport objects
|
120
|
+
test_files: []
|
121
|
+
has_rdoc:
|