Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fake.rb « lib - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3466e018d9b563ae39221e24799d4834ac0deaa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
48
49
50
51
52
class PostsFake
  attr_reader :people_hash, :post_fakes
  delegate :length, :each, :to_ary, :last, :to => :post_fakes

  def initialize(posts)
    author_ids = []
    posts.each do |p|
      author_ids << p.author_id
    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
    end
  end

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

  class Fake
    attr_reader :model
    def initialize(model, fakes_collection)
      @fakes_collection = fakes_collection
      @model = model
    end

    def id
      @model.id
    end

    def to_s
      @model.id.to_s
    end

    def author
      @fakes_collection.people_hash[@model.author_id]
    end

    def respond_to?(*args)
      super(*args) || model.respond_to?(*args)
    end

    def method_missing(method, *args)
      @model.send(method, *args)
    end
  end
end