fixjour 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,7 +22,7 @@ module Fixjour
22
22
 
23
23
  # The list of classes that have builders defined.
24
24
  def builders
25
- @builders ||= Set.new
25
+ @builders ||= {}
26
26
  end
27
27
 
28
28
  # This method should always return a valid instance of
@@ -49,7 +49,8 @@ module Fixjour
49
49
  module_eval(&block)
50
50
  rescue NameError => e
51
51
  if e.name && evaluator.respond_to?(e.name)
52
- raise NonBlockBuilderReference.new("You must use a builder block in order to reference other Fixjour creation methods.")
52
+ raise NonBlockBuilderReference.new \
53
+ "You must use a builder block in order to reference other Fixjour creation methods."
53
54
  else
54
55
  raise e
55
56
  end
@@ -59,14 +60,14 @@ module Fixjour
59
60
  # Checks to see whether or not a builder is defined. Duh.
60
61
  def builder_defined?(builder)
61
62
  case builder
62
- when Class then builders.map(&:klass).include?(builders)
63
- when String then builders.map(&:name).include?(builder)
64
- when Symbol then builders.map(&:name).include?(builder.to_s)
63
+ when Class then builders.values.map(&:klass).include?(builders)
64
+ when String then builders.values.map(&:name).include?(builder)
65
+ when Symbol then builders.values.map(&:name).include?(builder.to_s)
65
66
  end
66
67
  end
67
68
 
68
- def remove(builder)
69
- builders.delete(Builder.new(builder))
69
+ def remove(klass)
70
+ builders.delete(Builder.new(klass).name)
70
71
  end
71
72
 
72
73
  private
@@ -75,8 +76,10 @@ module Fixjour
75
76
  # redundant builders aren't defined, which can lead to confusion
76
77
  # when trying to figure out where objects are being created.
77
78
  def add_builder(builder)
78
- unless builders.add?(builder) or Fixjour.allow_redundancy?
79
+ if builders.has_key?(builder.name) and not Fixjour.allow_redundancy?
79
80
  raise RedundantBuilder.new("You already defined a builder for #{builder.klass.inspect}")
81
+ else
82
+ builders[builder.name] = builder
80
83
  end
81
84
  end
82
85
 
@@ -6,7 +6,7 @@ module Fixjour
6
6
  # * The new_* methods return new records
7
7
  # * The creation methods return objects of the proper type
8
8
  def verify!
9
- builders.each do |builder|
9
+ builders.each do |name, builder|
10
10
  klass = builder.klass
11
11
  result = new_record(builder)
12
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixjour
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Nakajima