fabrication 2.12.2 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 976a84a363881df56a3f0f18dca2e05ba63a66c2
4
- data.tar.gz: a8f5a55c6ef0eddf7824a0698c3737b64ec17fe3
3
+ metadata.gz: 63f6c7600246d2a616c443cfe4f1f40d97dfdfc7
4
+ data.tar.gz: df342015cfb8dd239fa9fbab926772d4ba06f023
5
5
  SHA512:
6
- metadata.gz: c904f38dda03158e9bf2b1d951eb00dc4166704ed7da9390509ff82158c15607ae4894b3fb20c7ca04783e7a36e5d37b992d8eaa7adf4a82c4df707a8017e46d
7
- data.tar.gz: a6b0447ef77a116fd159a09db9d9ced493866a63085b57003d1a28180997c41a3da75cb2c63f4ed5f1e8eeb807675a82a9fa49856e8f14b0f8bc07dd3961e0c6
6
+ metadata.gz: d1913a5783bbfc4989a912f3483612fa9dea69548c02a08bc365576395eec0ce64713f5104afea0cceeafa9fa1a1ca00f95676e35a85005da628943dbf8b9e9d
7
+ data.tar.gz: dfff237fd6789080b8713f12e2ace38d273cc7e3191e35b40b6b16995836fd9c2ae54e35bb1389cbc2b69ec62e38d8d5127e83a650f66cf145c4211e02ab6eac
@@ -36,7 +36,7 @@ module Fabrication
36
36
  end
37
37
 
38
38
  def klass
39
- Fabricate.schematic(@fabricator).klass
39
+ Fabricate.schematic(@fabricator).send(:klass)
40
40
  end
41
41
 
42
42
  private
@@ -8,10 +8,18 @@ class Fabrication::Schematic::Definition
8
8
  Fabrication::Generator::Base
9
9
  ]
10
10
 
11
- attr_accessor :klass
12
- def initialize(klass, &block)
13
- self.klass = klass
14
- process_block(&block)
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] = schematic_for(name, options, &block)
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
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '2.12.2'
2
+ VERSION = '2.13.0'
3
3
  end
@@ -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
- template 'fabricator.rb', File.join(options[:dir], "#{singular_table_name}_fabricator.#{options[:extension].to_s}")
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
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.12.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-01-16 00:00:00.000000000 Z
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.rb
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.5
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.