Class: Praxis::Collection

Inherits:
Attributor::Collection
  • Object
show all
Includes:
Types::MediaTypeCommon
Defined in:
lib/praxis/collection.rb

Class Method Summary collapse

Class Method Details

.domain_modelObject



41
42
43
# File 'lib/praxis/collection.rb', line 41

def self.domain_model
  @member_type.domain_model
end

.member_type(type = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/praxis/collection.rb', line 23

def self.member_type(type=nil)
  unless type.nil?
    @member_type = type
    @views = nil
    self.identifier(type.identifier + ';type=collection') unless type.identifier.nil?
  end

  @member_type
end

.of(type) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/praxis/collection.rb', line 5

def self.of(type)
  if defined?(type::Collection)
    return type::Collection
  end

  klass = super
  klass.anonymous_type

  if type < Praxis::Types::MediaTypeCommon
    klass.member_type type
    type.const_set :Collection, klass
  else
    warn "DEPRECATION: Praxis::Collection.of() for non-MediaTypes will be unsupported in 1.0. Use Attributor::Collection.of() instead."
    Attributor::Collection.of(type)
  end

end

.viewsObject



33
34
35
36
37
38
39
# File 'lib/praxis/collection.rb', line 33

def self.views
  @views ||= begin
    @member_type.views.each_with_object(Hash.new) do |(name, view), hash|
      hash[name] = Praxis::CollectionView.new(name, @member_type, view)
    end
  end
end