fabrication 2.11.0 → 2.11.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96031c7fe931f6f70a4e0e8b0a51c999151e0865
4
- data.tar.gz: 1714692bcc5f754e34855020a647750322a24fbe
3
+ metadata.gz: 51cda89ea052783eaff7e7f54a15c20384806c6f
4
+ data.tar.gz: 5fc0e39c30dbcc8d3c87156aefcf40f8b2f37906
5
5
  SHA512:
6
- metadata.gz: db66d3fe1d78fcdae6fe36fa3c4ddbd0b32c31364f1540ddfc99ed654bcaff0c73e09cb33e8033ec2b580d55da206165ef3970d399c25ef0ca24737634931efa
7
- data.tar.gz: 5b786db9b68d5c6db2b1d23016f9143dba83b6e465aca3cebe9a7b1464ebf3932ed712049f374979281daccefeb1eb3e6be91deb3318f1952c7453fc0ad8a30c
6
+ metadata.gz: b9bee0dd2589ae8ca4909052f2f3b72fc9832baf3c2baf15af93c6faa9ac1e86c020a21d5447231c6827dde2446e39bbee815a337ad00abf53138ee34903699a
7
+ data.tar.gz: 7ff5b3cf881b233b1ebe2c1f851d1e4b00657cdf4f94e9e2188e7159e0af1d11dfea5be9cebba8f263ebaf48f2f34d667f00cb07e6e67060db0c30e9f8bad53c
@@ -34,7 +34,7 @@ class Fabricate
34
34
  end
35
35
 
36
36
  def self.schematic(name)
37
- Fabrication::Support.find_definitions if Fabrication.manager.empty?
37
+ Fabrication.manager.load_definitions if Fabrication.manager.empty?
38
38
  Fabrication.manager[name] || raise(Fabrication::UnknownFabricatorError.new(name))
39
39
  end
40
40
 
@@ -39,6 +39,19 @@ class Fabrication::Schematic::Manager
39
39
  @to_params_stack ||= []
40
40
  end
41
41
 
42
+ def load_definitions
43
+ preinitialize
44
+ Fabrication::Config.fabricator_path.each do |folder|
45
+ Dir.glob(File.join(Fabrication::Config.path_prefix, folder, '**', '*.rb')).sort.each do |file|
46
+ load file
47
+ end
48
+ end
49
+ rescue Exception => e
50
+ raise e
51
+ ensure
52
+ freeze
53
+ end
54
+
42
55
  protected
43
56
 
44
57
  def raise_if_registered(name)
@@ -69,4 +82,5 @@ class Fabrication::Schematic::Manager
69
82
  Fabrication::Schematic::Definition.new(klass, &block)
70
83
  end
71
84
  end
85
+
72
86
  end
@@ -8,13 +8,32 @@ class Fabrication::Support
8
8
 
9
9
  def class_for(class_or_to_s)
10
10
  class_name = variable_name_to_class_name(class_or_to_s)
11
- klass = class_name.split('::').inject(Object) do |object, string|
12
- object.const_get(string)
13
- end
11
+ klass = constantize(class_name)
14
12
  rescue NameError => original_error
15
13
  raise Fabrication::UnfabricatableError.new(class_or_to_s, original_error)
16
14
  end
17
15
 
16
+ def constantize(camel_cased_word)
17
+ names = camel_cased_word.split('::')
18
+ Object.const_get(camel_cased_word) if names.empty?
19
+ names.shift if names.size > 1 && names.first.empty?
20
+ names.inject(Object) do |constant, name|
21
+ if constant == Object
22
+ constant.const_get(name)
23
+ else
24
+ candidate = constant.const_get(name)
25
+ next candidate if constant.const_defined?(name, false)
26
+ next candidate unless Object.const_defined?(name)
27
+ constant = constant.ancestors.inject do |const, ancestor|
28
+ break const if ancestor == Object
29
+ break ancestor if ancestor.const_defined?(name, false)
30
+ const
31
+ end
32
+ constant.const_get(name, false)
33
+ end
34
+ end
35
+ end
36
+
18
37
  def extract_options!(args)
19
38
  args.last.is_a?(::Hash) ? args.pop : {}
20
39
  end
@@ -24,18 +43,8 @@ class Fabrication::Support
24
43
  end
25
44
 
26
45
  def find_definitions
27
- Fabrication.manager.preinitialize
28
- Fabrication::Config.path_prefix.each do |prefix|
29
- Fabrication::Config.fabricator_path.each do |folder|
30
- Dir.glob(File.join(prefix, folder, '**', '*.rb')).sort.each do |file|
31
- load file
32
- end
33
- end
34
- end
35
- rescue Exception => e
36
- raise e
37
- ensure
38
- Fabrication.manager.freeze
46
+ puts "DEPRECATION WARNING: Fabrication::Support.find_definitions has been replaced by Fabrication.manager.load_definitions and will be removed in 3.0.0."
47
+ Fabrication.manager.load_definitions
39
48
  end
40
49
 
41
50
  def hash_class
@@ -3,7 +3,7 @@ class Fabrication::Transform
3
3
  class << self
4
4
 
5
5
  def apply_to(schematic, attributes_hash)
6
- Fabrication::Support.find_definitions if Fabrication.manager.empty?
6
+ Fabrication.manager.load_definitions if Fabrication.manager.empty?
7
7
  attributes_hash.inject({}) {|h,(k,v)| h.update(k => apply_transform(schematic, k, v)) }
8
8
  end
9
9
 
@@ -1,3 +1,3 @@
1
1
  module Fabrication
2
- VERSION = '2.11.0'
2
+ VERSION = '2.11.1'
3
3
  end
@@ -1,7 +1,7 @@
1
1
  namespace :fabrication do
2
2
  desc "Display all registered fabricators by class"
3
3
  task :list => :environment do
4
- Fabrication::Support.find_definitions if Fabrication.manager.empty?
4
+ Fabrication.manager.laod_definitions if Fabrication.manager.empty?
5
5
 
6
6
  if Fabrication.manager.schematics.none?
7
7
  puts "No fabricators found"
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.11.0
4
+ version: 2.11.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Elliott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-27 00:00:00.000000000 Z
11
+ date: 2014-04-14 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.