class RailsBestPractices::Reviews::HashSyntaxReview
Check ruby 1.8 style hash and suggest to change hash syntax to 1.9.
Review
process:
check hash nodes in all files, if the sexp type of hash key nodes is not :@lable, then the hash is ruby 1.8 style.
Constants
- VALID_SYMBOL_KEY
Protected Instance Methods
empty_hash?(node)
click to toggle source
check if hash node is empty.
# File lib/rails_best_practices/reviews/hash_syntax_review.rb, line 27 def empty_hash?(node) s(:hash, nil) == node || s(:bare_assoc_hash, nil) == node end
hash_is_18?(node)
click to toggle source
check if hash key/value pairs are ruby 1.8 style.
# File lib/rails_best_practices/reviews/hash_syntax_review.rb, line 32 def hash_is_18?(node) pair_nodes = node.sexp_type == :hash ? node[1][1] : node[1] return false if pair_nodes.blank? pair_nodes.any? { |pair_node| pair_node[1].sexp_type == :symbol_literal } end
valid_keys?(node)
click to toggle source
check if the hash keys are valid to be converted to ruby 1.9 syntax.
# File lib/rails_best_practices/reviews/hash_syntax_review.rb, line 41 def valid_keys?(node) node.hash_keys.all? { |key| key =~ VALID_SYMBOL_KEY } end