Skip to content

Instantly share code, notes, and snippets.

@lightman76
Created August 25, 2016 15:01
Show Gist options
  • Save lightman76/53832347f145cfdc65394c617b40ea6e to your computer and use it in GitHub Desktop.
Save lightman76/53832347f145cfdc65394c617b40ea6e to your computer and use it in GitHub Desktop.
Proposed modification to the attribute? method of the attributes module to use the unobservable_read_attribute when available
def attribute?(key)
# this method is used only for conditional type access.
# When included on an object with read observations, don't count this as an observable read
if respond_to? :unobservable_read_attribute
value = unobservable_read_attribute key
else
value = read_attribute key
end
return false if value.nil?
return false if value.respond_to?(:empty?) && value.empty?
value.to_s !~ /^(false|no|never)$/i
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment