makery 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/lib/makery.rb +73 -0
- data/lib/makery/version.rb +3 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dbec1096203da447140c61c0c112860554dd0a4c146d33b9ea8a1dc2323a0d06
|
4
|
+
data.tar.gz: a95ecc95f869c91f92e725321a8fed5a97f41def7933db7d6fba9ef856703715
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: aab7a6fa4b33b25b0bf13e80aeb7fe5112a1a9f4044160208d3bc8292aacd639c726491bd0bf620ccf88ea49ba82c91bb43d45cd1bca552fe7d3e9b684beb50d
|
7
|
+
data.tar.gz: 53c17accf9ac98e4768d1b50fa983a484f8603169962c6f85fae363e7f3cb3b4274d812c804aa8b0f7d8faf7476af694c2b28adaea21acfe34f4faaa0e42e9ee
|
data/lib/makery.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require "makery/version"
|
2
|
+
|
3
|
+
# do factory stuff
|
4
|
+
module Makery
|
5
|
+
def self.[](klass)
|
6
|
+
makers[klass]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.makers
|
10
|
+
@makers ||= new_makers
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.new_makers
|
14
|
+
Hash.new { |h, k| h[k] = Factory.new(k) }
|
15
|
+
end
|
16
|
+
|
17
|
+
# makes stuff
|
18
|
+
Factory = Struct.new(:klass) do
|
19
|
+
attr_accessor :count, :traits_repository
|
20
|
+
def initialize(*args)
|
21
|
+
self.count = 1
|
22
|
+
self.traits_repository = {}
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def call(*traits, **override)
|
27
|
+
attrs = base.merge(**trait_attrs(traits), **override)
|
28
|
+
Builder.call(attrs, klass, :new, count)
|
29
|
+
ensure
|
30
|
+
self.count = count + 1
|
31
|
+
end
|
32
|
+
|
33
|
+
def base(**attrs)
|
34
|
+
@base ||= attrs
|
35
|
+
end
|
36
|
+
|
37
|
+
def instantiation_method(method = :new)
|
38
|
+
@instantiation_method = method
|
39
|
+
end
|
40
|
+
|
41
|
+
def trait_attrs(traits)
|
42
|
+
traits.map { |t| traits_repository[t] }.reduce({}, &:merge)
|
43
|
+
end
|
44
|
+
|
45
|
+
def trait(name, **attrs)
|
46
|
+
traits_repository[name] = attrs
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# makes stuff
|
51
|
+
Builder = Struct.new(:attrs, :klass, :instantiation_method, :id) do
|
52
|
+
attr_reader :obj
|
53
|
+
def self.call(*args)
|
54
|
+
new(*args).call
|
55
|
+
end
|
56
|
+
|
57
|
+
def call
|
58
|
+
@obj = klass.send(instantiation_method)
|
59
|
+
transform
|
60
|
+
@obj
|
61
|
+
end
|
62
|
+
|
63
|
+
def transform
|
64
|
+
attrs.each { |k, v| attrs[k] = (v.respond_to?(:call) ? v.call(self) : v) }
|
65
|
+
attrs.each { |k, v| @obj.send("#{k}=", v) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def [](attr)
|
69
|
+
a = attrs[attr]
|
70
|
+
a.respond_to?(:call) ? a.call(self) : a
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: makery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kelly Wolf Stannard
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-10 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: '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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry-byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: A minimalist factory gem
|
112
|
+
email:
|
113
|
+
- kwstannard@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- lib/makery.rb
|
119
|
+
- lib/makery/version.rb
|
120
|
+
homepage: https://github.com/kwstannard/makery
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata:
|
124
|
+
allowed_push_host: https://rubygems.org
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.7.3
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: A minimalist factory gem
|
145
|
+
test_files: []
|