Class: MetadataPresenter::Metadata
- Inherits:
-
Object
- Object
- MetadataPresenter::Metadata
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(metadata, editor: false)
@metadata = OpenStruct.new(metadata)
@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 = metadata.send(method_name, *args, &block)
value.blank? && editor? ? MetadataPresenter::DefaultText[method_name] : value
end
|
Instance Attribute Details
Returns the value of attribute metadata.
5
6
7
|
# File 'app/models/metadata_presenter/metadata.rb', line 5
def metadata
@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
41
42
43
|
# File 'app/models/metadata_presenter/metadata.rb', line 41
def editor?
@editor.present?
end
|
#id ⇒ Object
20
21
22
|
# File 'app/models/metadata_presenter/metadata.rb', line 20
def id
metadata._id
end
|
#respond_to_missing?(method_name, _include_private = false) ⇒ Boolean
28
29
30
|
# File 'app/models/metadata_presenter/metadata.rb', line 28
def respond_to_missing?(method_name, _include_private = false)
metadata.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
|
#type ⇒ Object
24
25
26
|
# File 'app/models/metadata_presenter/metadata.rb', line 24
def type
metadata._type
end
|
#uuid ⇒ Object
16
17
18
|
# File 'app/models/metadata_presenter/metadata.rb', line 16
def uuid
metadata._uuid
end
|