Class: ModelTag::UserProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/app/models/model_tag.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model_tag) ⇒ UserProxy

Returns a new instance of UserProxy.



28
29
30
# File 'lib/app/models/model_tag.rb', line 28

def initialize(model_tag)
  @model_tag = model_tag
end

Instance Attribute Details

#model_tagObject

Returns the value of attribute model_tag.



26
27
28
# File 'lib/app/models/model_tag.rb', line 26

def model_tag
  @model_tag
end

Instance Method Details

#<<(user) ⇒ Object



65
66
67
68
# File 'lib/app/models/model_tag.rb', line 65

def << (user)
  model_tag.user_ids << user.id
  model_tag.send(:set_tagging_count)
end

#all(opts = {}) ⇒ Object



40
41
42
# File 'lib/app/models/model_tag.rb', line 40

def all(opts = {})
  fetch_all
end

#countObject Also known as: size



36
37
38
# File 'lib/app/models/model_tag.rb', line 36

def count
  model_tag.user_ids.size
end

#delete(user) ⇒ Object



70
71
72
73
# File 'lib/app/models/model_tag.rb', line 70

def delete(user)
  model_tag.user_ids.delete user.id
  model_tag.send(:set_tagging_count)
end

#each(&block) ⇒ Object



44
45
46
# File 'lib/app/models/model_tag.rb', line 44

def each(&block)
  fetch_all.each {|user| yield user}
end

#find(id) ⇒ Object



48
49
50
51
# File 'lib/app/models/model_tag.rb', line 48

def find(id)
  return nil unless model_tag.user_ids.include?(id)
  User.find(id)
end

#first(opts = {}) ⇒ Object



53
54
55
56
# File 'lib/app/models/model_tag.rb', line 53

def first(opts = {})
  return @first ||= User.find(model_tag.user_ids.first) if opts.empty?
  User.first(opts.merge(:_id.in => model_tag.user_ids))
end

#inspectObject



75
76
77
# File 'lib/app/models/model_tag.rb', line 75

def inspect
  all.inspect
end

#last(opts = {}) ⇒ Object



58
59
60
61
# File 'lib/app/models/model_tag.rb', line 58

def last(opts = {})
  return @last ||= User.find(model_tag.user_ids.last) if opts.empty?
  User.last(opts.merge(:_id.in => model_tag.user_ids))
end

#to_aObject



32
33
34
# File 'lib/app/models/model_tag.rb', line 32

def to_a
  fetch_all.to_a
end