Class: SocialStream::Seed
- Inherits:
-
Object
- Object
- SocialStream::Seed
- Defined in:
- lib/social_stream/seed.rb
Overview
Seed you database with initial data for SocialStream
Instance Method Summary collapse
-
#initialize(config) ⇒ Seed
constructor
A new instance of Seed.
- #seed_activity_verbs ⇒ Object
- #seed_relations(rs) ⇒ Object
Constructor Details
#initialize(config) ⇒ Seed
Returns a new instance of Seed.
5 6 7 8 9 10 |
# File 'lib/social_stream/seed.rb', line 5 def initialize(config) s = YAML.load_file(config) seed_activity_verbs seed_relations(s['relations']) end |
Instance Method Details
#seed_activity_verbs ⇒ Object
12 13 14 15 16 |
# File 'lib/social_stream/seed.rb', line 12 def seed_activity_verbs ActivityVerb::Available.each do |value| ActivityVerb.find_or_create_by_name value end end |
#seed_relations(rs) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/social_stream/seed.rb', line 18 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(:reflexive, r['reflexive']) # FIXME: optimize relations[name]..destroy_all if (ps = r['permissions']).present? ps.each do |p| relations[name]. << 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 |