Sha256: f20b4994dfb03f77a1115fe41cb8f2aa70ca7b185e93a9bbf1902379fe723c63
Contents?: true
Size: 1.43 KB
Versions: 2
Compression:
Stored size: 1.43 KB
Contents
module SocialStream # Seed you database with initial data for SocialStream # class Seed def initialize(config) s = YAML.load_file(config) seed_activity_verbs seed_relations(s['relations']) end def seed_activity_verbs ActivityVerb::Available.each do |value| ActivityVerb.find_or_create_by_name value end end def seed_relations(rs) relations = {} rs.each_pair do |name, r| relations[name] = Relation. find_or_create_by_sender_type_and_receiver_type_and_name(r['sender_type'], r['receiver_type'], r['name']) relations[name].update_attribute(:default, r['default']) # FIXME: optimize relations[name].relation_permissions.destroy_all if (ps = r['permissions']).present? ps.each do |p| relations[name].permissions << Permission.find_or_create_by_action_and_object_and_parameter(*p) end end end # Parent, inverse and granted relations must be set after creation rs.each_pair do |name, r| %w( parent inverse granted ).each do |s| relations[name].__send__("#{ s }=", relations[r[s]]) # relations[name].parent = relations[r['parent']] end relations[name].save! end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
social_stream-0.0.3 | lib/social_stream/seed.rb |
social_stream-0.0.2 | lib/social_stream/seed.rb |