I have two classes; customer and reservation. And my project is consist of only ruby code, not rails project.
Class reservation reads bulk json file line by line which includes customer hash.
From that hash, I create customer object.
Here's the code within the reservation class.
def parse_json
File.open(@filename, "r" ).each do |line|
@customers << Customer.new(JSON.parse(line))
end
return @customers
end
And in customer.rb I have the following;
validates_presence_of :hash
validate :hash_should_include_all_fields
attr_reader :name, :userid, :latitude, :longitude, :distance
def hash_should_include_all_fields
puts "I'm here #{hash}"
if hash.assert_valid_keys('user_id', 'name', 'latitude', 'longitude')
puts "Valid"
else
puts "Not valid"
end
end
However as I create customer objects, hash_should_include_all_fields
method is not called.
What do I miss in here, that would be great if you can help.
Thanks