Class: MetadataPresenter::Metadata

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming
Includes:
ActiveModel::Conversion
Defined in:
app/models/metadata_presenter/metadata.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata, editor: false) ⇒ Metadata

Returns a new instance of Metadata.



7
8
9
10
# File 'app/models/metadata_presenter/metadata.rb', line 7

def initialize(, editor: false)
  @metadata = OpenStruct.new()
  @editor = editor
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



32
33
34
35
# File 'app/models/metadata_presenter/metadata.rb', line 32

def method_missing(method_name, *args, &block)
  value = .send(method_name, *args, &block)
  value.blank? && editor? ? MetadataPresenter::DefaultText[method_name] : value
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



5
6
7
# File 'app/models/metadata_presenter/metadata.rb', line 5

def 
  @metadata
end

Instance Method Details

#==(other) ⇒ Object



37
38
39
# File 'app/models/metadata_presenter/metadata.rb', line 37

def ==(other)
  id == other.id if other.respond_to? :id
end

#editor?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/metadata_presenter/metadata.rb', line 41

def editor?
  @editor.present?
end

#idObject



20
21
22
# File 'app/models/metadata_presenter/metadata.rb', line 20

def id
  ._id
end

#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'app/models/metadata_presenter/metadata.rb', line 28

def respond_to_missing?(method_name, _include_private = false)
  .respond_to?(method_name)
end

#to_json(*_args) ⇒ Object



12
13
14
# File 'app/models/metadata_presenter/metadata.rb', line 12

def to_json(*_args)
  to_h.to_json
end

#typeObject



24
25
26
# File 'app/models/metadata_presenter/metadata.rb', line 24

def type
  ._type
end

#uuidObject



16
17
18
# File 'app/models/metadata_presenter/metadata.rb', line 16

def uuid
  ._uuid
end