fixjour 0.1.0 → 0.1.2
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.
- data/lib/fixjour/definitions.rb +4 -8
- data/lib/fixjour/deprecation.rb +24 -0
- data/lib/fixjour/errors.rb +7 -0
- data/lib/fixjour/generator.rb +1 -1
- data/lib/fixjour/merging_proxy.rb +1 -0
- data/lib/fixjour.rb +1 -0
- metadata +2 -1
data/lib/fixjour/definitions.rb
CHANGED
|
@@ -3,7 +3,7 @@ module Fixjour
|
|
|
3
3
|
# Defines the new_* method
|
|
4
4
|
def define_new(klass, &block)
|
|
5
5
|
define_method("new_#{name_for(klass)}") do |*args|
|
|
6
|
-
Generator.new(klass, block).call(self, args.extract_options!)
|
|
6
|
+
Generator.new(klass, block).call(self, args.extract_options!.symbolize_keys!)
|
|
7
7
|
end
|
|
8
8
|
end
|
|
9
9
|
|
|
@@ -19,14 +19,10 @@ module Fixjour
|
|
|
19
19
|
# Defines the valid_*_attributes method
|
|
20
20
|
def define_valid_attributes(name)
|
|
21
21
|
define_method("valid_#{name}_attributes") do |*args|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
valid_attributes.delete_if { |key, value| value.nil? }
|
|
25
|
-
instance_variable_set("@__valid_#{name}_attrs", valid_attributes)
|
|
26
|
-
end
|
|
27
|
-
|
|
22
|
+
valid_attributes = send("new_#{name}").attributes
|
|
23
|
+
valid_attributes.delete_if { |key, value| value.nil? }
|
|
28
24
|
overrides = args.extract_options!
|
|
29
|
-
attrs =
|
|
25
|
+
attrs = valid_attributes.merge(overrides)
|
|
30
26
|
attrs.stringify_keys!
|
|
31
27
|
attrs.make_indifferent!
|
|
32
28
|
attrs
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Fixjour
|
|
2
|
+
module Deprecation
|
|
3
|
+
module MergingProxy
|
|
4
|
+
def process(*args)
|
|
5
|
+
raise DeprecatedMergeAttempt.new(<<-END
|
|
6
|
+
You are attempting to call process on the class proxy.
|
|
7
|
+
This behavior was recently deprecated. In order to process
|
|
8
|
+
the overrides hash, pass two block arguments:
|
|
9
|
+
|
|
10
|
+
define_builder(Foo) do |klass, overrides|
|
|
11
|
+
overrides.process(:bar) do |bar|
|
|
12
|
+
overrides[:bar] = 'overridden'
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
klass.new(:name => 'fizz')
|
|
16
|
+
end
|
|
17
|
+
END
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
Fixjour::MergingProxy.send :include, Fixjour::Deprecation::MergingProxy
|
data/lib/fixjour/errors.rb
CHANGED
|
@@ -23,4 +23,11 @@ module Fixjour
|
|
|
23
23
|
# Raised when a builder is defined for a class that already
|
|
24
24
|
# has one.
|
|
25
25
|
class RedundantBuilder < StandardError; end
|
|
26
|
+
|
|
27
|
+
# Raised when a builder is defined with one block argument and
|
|
28
|
+
# the user assumes that it's the overrides hash. This used to
|
|
29
|
+
# be the standard behavior, but now blocks with one argument
|
|
30
|
+
# are passed the class proxy, and getting access to the overrides
|
|
31
|
+
# hash requires you pass two block arguments.
|
|
32
|
+
class DeprecatedMergeAttempt < StandardError; end
|
|
26
33
|
end
|
data/lib/fixjour/generator.rb
CHANGED
data/lib/fixjour.rb
CHANGED
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.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pat Nakajima
|
|
@@ -37,6 +37,7 @@ files:
|
|
|
37
37
|
- lib/fixjour
|
|
38
38
|
- lib/fixjour/builders.rb
|
|
39
39
|
- lib/fixjour/definitions.rb
|
|
40
|
+
- lib/fixjour/deprecation.rb
|
|
40
41
|
- lib/fixjour/errors.rb
|
|
41
42
|
- lib/fixjour/generator.rb
|
|
42
43
|
- lib/fixjour/merging_proxy.rb
|