Module: Simplifyapi::Representer::ClassMethods

Defined in:
lib/simplifyapi/representer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#collectionsObject (readonly)

Returns the value of attribute collections.



21
22
23
# File 'lib/simplifyapi/representer.rb', line 21

def collections
  @collections
end

#propertiesObject (readonly)

Returns the value of attribute properties.



21
22
23
# File 'lib/simplifyapi/representer.rb', line 21

def properties
  @properties
end

Instance Method Details

#collection(name, representer, &block) ⇒ Object



29
30
31
32
33
# File 'lib/simplifyapi/representer.rb', line 29

def collection name, representer, &block
  @collections ||= {}

  @collections[name] = Collection.new(name, representer, &block)
end

#export(model) ⇒ Object



41
42
43
# File 'lib/simplifyapi/representer.rb', line 41

def export model
  @representation.export(self, model)
end

#import(model, hash) ⇒ Object



45
46
47
# File 'lib/simplifyapi/representer.rb', line 45

def import model, hash
  @representation.import(self, model, hash.with_indifferent_access)
end

#property(name, &block) ⇒ Object



23
24
25
26
27
# File 'lib/simplifyapi/representer.rb', line 23

def property name, &block
  @properties ||= {}

  @properties[name] = Property.new(name, &block)
end

#representation(&block) ⇒ Object



35
36
37
38
39
# File 'lib/simplifyapi/representer.rb', line 35

def representation &block
  return @representation unless block_given?

  @representation = Representation.new &block
end

#represents_collection?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/simplifyapi/representer.rb', line 53

def represents_collection?
  false
end

#represents_model?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/simplifyapi/representer.rb', line 49

def represents_model?
  true
end