Class: PostsFake

Inherits:
Object
  • Object
show all
Defined in:
lib/fake.rb

Defined Under Namespace

Classes: Fake

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (PostsFake) initialize(posts)

A new instance of PostsFake



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fake.rb', line 5

def initialize(posts)
  author_ids = []
  posts.each do |p|
    author_ids << p.author_id
    p.comments.each do |c|
      author_ids << c.author_id
    end
  end

  people = Person.where(:id => author_ids).includes(:profile)
  @people_hash = {}
  people.each{|person| @people_hash[person.id] = person}

  @post_fakes = posts.map do |post|
    f = Fake.new(post, self)
    f.comments = post.comments.map do |comment|
      Fake.new(comment, self)
    end
    f
  end
end

Instance Attribute Details

- (Object) people_hash (readonly)

Returns the value of attribute people_hash



2
3
4
# File 'lib/fake.rb', line 2

def people_hash
  @people_hash
end

- (Object) post_fakes (readonly)

Returns the value of attribute post_fakes



2
3
4
# File 'lib/fake.rb', line 2

def post_fakes
  @post_fakes
end

Instance Method Details

- (Object) models



27
28
29
# File 'lib/fake.rb', line 27

def models
  self.post_fakes.map{|a| a.model }
end