Module: SocialStream::Models::Supertype::ClassMethods

Defined in:
lib/social_stream/models/supertype.rb

Instance Method Summary collapse

Instance Method Details

#normalize(a) ⇒ Object

Get supertype from object, if possible



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/social_stream/models/supertype.rb', line 48

def normalize(a)
  case a
  when self
    a
  when Integer
    find a
  when Array
    a.map{ |e| normalize(e) }
  else
    begin
      a.__send__ "#{ name.underscore }!" # a.actor!
    rescue
      raise "Unable to normalize #{ self } #{ a.inspect }"
    end
  end
end

#normalize_id(a) ⇒ Object

Get the supertype id from an object, if possible



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/social_stream/models/supertype.rb', line 34

def normalize_id(a)
  case a
  when Integer
    a
  when String
    a.to_i
  when Array
    a.map{ |e| normalize_id(e) }
  else
    normalize(a).id
  end
end

#subtypesObject



29
30
31
# File 'lib/social_stream/models/supertype.rb', line 29

def subtypes
  SocialStream.__send__ subtypes_name.to_s.tableize # SocialStream.subjects # => [:user, :group ]
end

#subtypes_nameObject

:subject



25
26
27
# File 'lib/social_stream/models/supertype.rb', line 25

def subtypes_name # :subject
  @subtypes_name
end