fabrication 2.12.2 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fabrication/cucumber/step_fabricator.rb +1 -1
- data/lib/fabrication/schematic/definition.rb +27 -4
- data/lib/fabrication/schematic/manager.rb +1 -21
- data/lib/fabrication/version.rb +1 -1
- data/lib/rails/generators/fabrication/model/model_generator.rb +15 -1
- data/lib/rails/generators/fabrication/model/templates/{fabricator.rb → fabricator.erb} +0 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63f6c7600246d2a616c443cfe4f1f40d97dfdfc7
|
4
|
+
data.tar.gz: df342015cfb8dd239fa9fbab926772d4ba06f023
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1913a5783bbfc4989a912f3483612fa9dea69548c02a08bc365576395eec0ce64713f5104afea0cceeafa9fa1a1ca00f95676e35a85005da628943dbf8b9e9d
|
7
|
+
data.tar.gz: dfff237fd6789080b8713f12e2ace38d273cc7e3191e35b40b6b16995836fd9c2ae54e35bb1389cbc2b69ec62e38d8d5127e83a650f66cf145c4211e02ab6eac
|
@@ -8,10 +8,18 @@ class Fabrication::Schematic::Definition
|
|
8
8
|
Fabrication::Generator::Base
|
9
9
|
]
|
10
10
|
|
11
|
-
attr_accessor :
|
12
|
-
def initialize(
|
13
|
-
self.
|
14
|
-
|
11
|
+
attr_accessor :name, :options
|
12
|
+
def initialize(name, options={}, &block)
|
13
|
+
self.name = name
|
14
|
+
self.options = options
|
15
|
+
|
16
|
+
if parent
|
17
|
+
merge_result = parent.merge(&block)
|
18
|
+
@attributes = merge_result.attributes
|
19
|
+
@callbacks = merge_result.callbacks
|
20
|
+
else
|
21
|
+
process_block(&block)
|
22
|
+
end
|
15
23
|
end
|
16
24
|
|
17
25
|
def process_block(&block)
|
@@ -118,4 +126,19 @@ class Fabrication::Schematic::Definition
|
|
118
126
|
proc { Fabricate(params[:fabricator] || name) }
|
119
127
|
end
|
120
128
|
end
|
129
|
+
|
130
|
+
protected
|
131
|
+
|
132
|
+
def parent
|
133
|
+
@parent ||= Fabrication.manager[options[:from].to_s] if options[:from]
|
134
|
+
end
|
135
|
+
|
136
|
+
def klass
|
137
|
+
@klass ||= Fabrication::Support.class_for(
|
138
|
+
options[:class_name] ||
|
139
|
+
(parent && parent.klass) ||
|
140
|
+
options[:from] ||
|
141
|
+
name
|
142
|
+
)
|
143
|
+
end
|
121
144
|
end
|
@@ -61,28 +61,8 @@ class Fabrication::Schematic::Manager
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def store(name, aliases, options, &block)
|
64
|
-
schematic = schematics[name] =
|
64
|
+
schematic = schematics[name] = Fabrication::Schematic::Definition.new(name, options, &block)
|
65
65
|
aliases.each { |as| schematics[as.to_sym] = schematic }
|
66
66
|
end
|
67
67
|
|
68
|
-
def resolve_class(name, parent, options)
|
69
|
-
Fabrication::Support.class_for(
|
70
|
-
options[:class_name] ||
|
71
|
-
(parent && parent.klass) ||
|
72
|
-
options[:from] ||
|
73
|
-
name
|
74
|
-
)
|
75
|
-
end
|
76
|
-
|
77
|
-
def schematic_for(name, options, &block)
|
78
|
-
parent = self[options[:from].to_s] if options[:from]
|
79
|
-
klass = resolve_class(name, parent, options)
|
80
|
-
|
81
|
-
if parent
|
82
|
-
parent.merge(&block).tap { |s| s.klass = klass }
|
83
|
-
else
|
84
|
-
Fabrication::Schematic::Definition.new(klass, &block)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
68
|
end
|
data/lib/fabrication/version.rb
CHANGED
@@ -8,12 +8,26 @@ module Fabrication
|
|
8
8
|
class_option :extension, :type => :string, :default => "rb", :desc => "file extension name"
|
9
9
|
|
10
10
|
def create_fabrication_file
|
11
|
-
|
11
|
+
copy_attributes_from_model if attributes.empty?
|
12
|
+
template 'fabricator.erb', File.join(options[:dir], "#{singular_table_name}_fabricator.#{options[:extension].to_s}")
|
12
13
|
end
|
13
14
|
|
14
15
|
def self.source_root
|
15
16
|
@_fabrication_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
16
17
|
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def copy_attributes_from_model
|
22
|
+
model = class_name.constantize
|
23
|
+
if defined?(ActiveRecord) && model < ActiveRecord::Base
|
24
|
+
self.attributes = model.columns_hash.map { |name, column|
|
25
|
+
Rails::Generators::GeneratedAttribute.new(name, column.type)
|
26
|
+
}
|
27
|
+
end
|
28
|
+
rescue NameError
|
29
|
+
end
|
30
|
+
|
17
31
|
end
|
18
32
|
end
|
19
33
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Elliott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Fabrication is an object generation framework for ActiveRecord, Mongoid,
|
14
14
|
DataMapper, Sequel, or any other Ruby object.
|
@@ -47,7 +47,7 @@ files:
|
|
47
47
|
- lib/rails/generators/fabrication/cucumber_steps/cucumber_steps_generator.rb
|
48
48
|
- lib/rails/generators/fabrication/cucumber_steps/templates/fabrication_steps.rb
|
49
49
|
- lib/rails/generators/fabrication/model/model_generator.rb
|
50
|
-
- lib/rails/generators/fabrication/model/templates/fabricator.
|
50
|
+
- lib/rails/generators/fabrication/model/templates/fabricator.erb
|
51
51
|
- lib/tasks/defined_fabricators.rake
|
52
52
|
homepage: http://fabricationgem.org
|
53
53
|
licenses:
|
@@ -69,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
69
|
version: '0'
|
70
70
|
requirements: []
|
71
71
|
rubyforge_project:
|
72
|
-
rubygems_version: 2.4.
|
72
|
+
rubygems_version: 2.4.6
|
73
73
|
signing_key:
|
74
74
|
specification_version: 4
|
75
75
|
summary: Implementing the factory pattern in Ruby so you don't have to.
|