Skip to content

Commit 4a83326

Browse files
authored
Merge pull request #40 from bjeanes/master
Switch operands to test for undefined attribute
2 parents 1b7560e + fbbbd98 commit 4a83326

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/dry/initializer/builders/attribute.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,22 +60,22 @@ def definition_line
6060

6161
def default_line
6262
return unless @default
63-
"#{@val} = instance_exec(&#{@item}.default) if #{@val} == #{@null}"
63+
"#{@val} = instance_exec(&#{@item}.default) if #{@null} == #{@val}"
6464
end
6565

6666
def coercion_line
6767
return unless @type
6868
arity = @type.is_a?(Proc) ? @type.arity : @type.method(:call).arity
6969
if arity.abs == 1
70-
"#{@val} = #{@item}.type.call(#{@val}) unless #{@val} == #{@null}"
70+
"#{@val} = #{@item}.type.call(#{@val}) unless #{@null} == #{@val}"
7171
else
72-
"#{@val} = #{@item}.type.call(#{@val}, self) unless #{@val} == #{@null}"
72+
"#{@val} = #{@item}.type.call(#{@val}, self) unless #{@null} == #{@val}"
7373
end
7474
end
7575

7676
def assignment_line
7777
"#{@ivar} = #{@val}" \
78-
" unless #{@val} == #{@null} && instance_variable_defined?(:#{@ivar})"
78+
" unless #{@null} == #{@val} && instance_variable_defined?(:#{@ivar})"
7979
end
8080
end
8181
end

lib/dry/initializer/builders/reader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def method_lines
3838
return unless @null
3939
[
4040
"def #{@target}",
41-
" #{@ivar} unless #{@ivar} == Dry::Initializer::UNDEFINED",
41+
" #{@ivar} unless Dry::Initializer::UNDEFINED == #{@ivar}",
4242
"end"
4343
]
4444
end

0 commit comments

Comments
 (0)