Class: SimpleAMS::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_ams/document.rb

Direct Known Subclasses

Folder

Defined Under Namespace

Classes: Fields, Folder, Forms, Generics, Links, Metas, PrimaryId, Relations

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, embedded_options = nil) ⇒ Document

Returns a new instance of Document.



6
7
8
9
10
11
# File 'lib/simple_ams/document.rb', line 6

def initialize(options, embedded_options = nil)
  @options = options
  @embedded_options = embedded_options
  @serializer = options.serializer
  @resource = options.resource
end

Instance Attribute Details

#embedded_optionsObject (readonly)

Returns the value of attribute embedded_options.



4
5
6
# File 'lib/simple_ams/document.rb', line 4

def embedded_options
  @embedded_options
end

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/simple_ams/document.rb', line 4

def options
  @options
end

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/simple_ams/document.rb', line 4

def resource
  @resource
end

#serializerObject (readonly)

Returns the value of attribute serializer.



4
5
6
# File 'lib/simple_ams/document.rb', line 4

def serializer
  @serializer
end

Instance Method Details

#adapterObject



40
41
42
# File 'lib/simple_ams/document.rb', line 40

def adapter
  @adapter ||= options.adapter
end

#document?Boolean

rubocop:enable Naming/MemoizedInstanceVariableName

Returns:

  • (Boolean)


78
79
80
# File 'lib/simple_ams/document.rb', line 78

def document?
  !folder?
end

#embeddedObject



82
83
84
85
86
# File 'lib/simple_ams/document.rb', line 82

def embedded
  return nil unless embedded_options

  @embedded ||= SimpleAMS::Document.new(embedded_options)
end

#fieldsObject



17
18
19
20
21
22
# File 'lib/simple_ams/document.rb', line 17

def fields
  return @fields if defined?(@fields)
  return @fields = [] if options.fields.empty?

  @fields ||= self.class::Fields.new(options)
end

#folder?Boolean

rubocop:disable Naming/MemoizedInstanceVariableName

Returns:

  • (Boolean)


73
74
75
# File 'lib/simple_ams/document.rb', line 73

def folder?
  @is_folder ||= is_a?(self.class::Folder)
end

#formsObject



58
59
60
61
62
63
# File 'lib/simple_ams/document.rb', line 58

def forms
  return @forms if defined?(@forms)
  return @forms = {} if options.forms.empty?

  @forms ||= self.class::Forms.new(options)
end

#genericsObject



65
66
67
68
69
70
# File 'lib/simple_ams/document.rb', line 65

def generics
  return @generics if defined?(@generics)
  return @generics = {} if options.generics.empty?

  @generics ||= self.class::Generics.new(options)
end


44
45
46
47
48
49
# File 'lib/simple_ams/document.rb', line 44

def links
  return @links if defined?(@links)
  return @links = {} if options.links.empty?

  @links ||= self.class::Links.new(options)
end

#metasObject



51
52
53
54
55
56
# File 'lib/simple_ams/document.rb', line 51

def metas
  return @metas if defined?(@metas)
  return @metas = {} if options.metas.empty?

  @metas ||= self.class::Metas.new(options)
end

#nameObject



32
33
34
# File 'lib/simple_ams/document.rb', line 32

def name
  @name ||= options.name
end

#primary_idObject



13
14
15
# File 'lib/simple_ams/document.rb', line 13

def primary_id
  @primary_id ||= self.class::PrimaryId.new(options)
end

#relationsObject



24
25
26
27
28
29
30
# File 'lib/simple_ams/document.rb', line 24

def relations
  return @relations if defined?(@relations)

  @relations ||= self.class::Relations.new(
    options, options.relations
  )
end

#typeObject



36
37
38
# File 'lib/simple_ams/document.rb', line 36

def type
  @type ||= options.type
end