29. def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
fonte pequena?
30. def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
agora sim? fonte 16
31. 23...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
32. 23...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
33. mas e se... 23...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
34. mas eese...
mas se... 23...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
35. mas eese...
mas ese... 23...
mas se...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
36. mas eese...
mas ese... 23...
mas ese...
mas se...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
37. mas eese...
mas ese... 23...
mas ese...
mas ese...
mas se...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
38. mas eese...
mas ese... 23...
mas ese...
mas ese...
mas se...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
39. mas eese...
mas ese... 23...
mas ese...
mas ese...
mas ese...
mas se...
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
41. def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
42. o fluxo é COMPLEXO
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
43. o fluxo éSEMANTICA
não há COMPLEXO
def _read_attribute(attr_name)
attr_name = attr_name.to_s
attr_name = self.class.primary_key if attr_name == 'id'
value = @attributes[attr_name]
unless value.nil?
if column = column_for_attribute(attr_name)
if unserializable_attribute?(attr_name, column)
unserialize_attribute(attr_name)
else
column.type_cast(value)
end
else
value
end
end
end
51. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
52. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
53. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
for
54. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
UMA LINHA
for
55. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
UMA LINHA
for
if
56. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
UMA LINHA
for
for
if
57. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
UMA LINHA
for
for
for
if
58. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
UMA LINHA
for
for
for
oops... if
if
59. quantos fors tem aqui?
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
UMA LINHA
for
for
for
oops... if
if
Mein Gott. Coisa assim nonca vi!
64. menos palavras zoou seu código
um enter não mata
def cached_attributes
@cached_attributes ||= columns.select { |c| cacheable_column?(c) }.map { |col| col.name }.to_set
end
65. concisão = com o mínimo de
palavras, deixar claro
tarefa do bem
72. cliente.a
acontece o método b, c, d, e, f, ...
Quer ver uma mágica?
Meta meta meta meta programming.
meta-aspecto-meta-aspecto
programador
73. # Deletes the records according to the <tt>:dependent</tt> option.
def delete_records(records, method)
if method == :destroy
records.each { |r| r.destroy }
update_counter(-records.length) unless inverse_updates_counter_cache?
else
keys = records.map { |r| r[reflection.association_primary_key] }
scope = scoped.where(reflection.association_primary_key => keys)
if method == :delete_all
update_counter(-scope.delete_all)
else
update_counter(-scope.update_all(reflection.foreign_key => nil))
end
end
end
76. # Deletes the records according to the <tt>:dependent</tt> option.
def delete_records(records, method)
if method == :destroy
records.each { |r| r.destroy }
update_counter(-records.length) unless inverse_updates_counter_cache?
else
keys = records.map { |r| r[reflection.association_primary_key] }
scope = scoped.where(reflection.association_primary_key => keys)
if method == :delete_all
update_counter(-scope.delete_all)
else
update_counter(-scope.update_all(reflection.foreign_key => nil))
end
end
end
77. um “if if if if if if” dói
(aka. sanduíche íche íche pattern)
79. esse dói?
select * from Contatos where a=b or (c=d && e=f)
order by primeiro_campo
80. esse dói?
select * from Contatos where a=b or (c=d && e=f)
order by primeiro_campo
Maurício Aniche
81. esse dói?
select * from Contatos where a=b or (c=d && e=f)
order by primeiro_campo
Como você testaria isso?
Maurício Aniche
82. esse dói?
select * from Contatos where a=b or (c=d && e=f)
order by primeiro_campo
Como você testaria isso?
mock.assert(_.select(“select from ...”))?
Maurício Aniche
83. esse dói?
select * from Contatos where a=b or (c=d && e=f)
order by primeiro_campo
Como você testaria isso?
mock.assert(_.select(“select from ...”))?
1 teste?
Maurício Aniche
84. O objetivo não é usar outro, ou
esconder o controle de fluxo.
Quebre ele em dois. Mais faceis de
entender
85. O objetivo não é usar outro, ou
esconder o controle de fluxo.
Quebre ele em dois. Mais faceis de
entender
86. teste é moda, é positivo, é importante,
e garante várias coisas
93. Facinho...
select * from Contatos where a=b or (c=d && e=f)
order by primeiro_campo limit 2
Martin Fowler
94. Facinho...
select * from Contatos where a=b or (c=d && e=f)
order by primeiro_campo limit 2
sql também é linguagem...
Martin Fowler
95. Facinho...
select * from Contatos where a=b or (c=d && e=f)
order by primeiro_campo limit 2
sql também é linguagem...
mina gata hein...
Martin Fowler