Class: MediaTypes::Constructable

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/media_types/constructable.rb

Defined Under Namespace

Classes: NoArgumentGiven

Instance Method Summary collapse

Constructor Details

#initialize(klazz, **opts) ⇒ Constructable

Returns a new instance of Constructable.



11
12
13
14
# File 'lib/media_types/constructable.rb', line 11

def initialize(klazz, **opts)
  super klazz
  self.opts = opts
end

Instance Method Details

#+(other) ⇒ Object



68
69
70
# File 'lib/media_types/constructable.rb', line 68

def +(other)
  to_str + other
end

#==(other) ⇒ Object



64
65
66
# File 'lib/media_types/constructable.rb', line 64

def ==(other)
  to_str.send(:==, other)
end

#===(other) ⇒ Object



60
61
62
# File 'lib/media_types/constructable.rb', line 60

def ===(other)
  to_str.send(:===, other)
end

#collectionObject



36
37
38
# File 'lib/media_types/constructable.rb', line 36

def collection
  view(COLLECTION_VIEW)
end

#collection?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/media_types/constructable.rb', line 40

def collection?
  opts[:view] == COLLECTION_VIEW
end

#createObject



44
45
46
# File 'lib/media_types/constructable.rb', line 44

def create
  view(CREATE_VIEW)
end

#create?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/media_types/constructable.rb', line 48

def create?
  opts[:view] == CREATE_VIEW
end

#hashObject



76
77
78
# File 'lib/media_types/constructable.rb', line 76

def hash
  to_str.hash
end

#indexObject



52
53
54
# File 'lib/media_types/constructable.rb', line 52

def index
  view(INDEX_VIEW)
end

#index?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/media_types/constructable.rb', line 56

def index?
  opts[:view] == INDEX_VIEW
end

#split(pattern = nil, *limit) ⇒ Object



72
73
74
# File 'lib/media_types/constructable.rb', line 72

def split(pattern = nil, *limit)
  to_str.split(pattern, *limit)
end

#suffix(suffix = NO_ARG) ⇒ Object



31
32
33
34
# File 'lib/media_types/constructable.rb', line 31

def suffix(suffix = NO_ARG)
  return opts[:suffix] if suffix == NO_ARG
  with(suffix: suffix)
end

#to_str(qualifier = nil) ⇒ Object Also known as: inspect, to_s



80
81
82
83
84
85
86
# File 'lib/media_types/constructable.rb', line 80

def to_str(qualifier = nil)
  # TODO: remove warning by slicing out these arguments if they don't appear in the format
  qualified(
    qualifier,
    Formatter.call(opts)
  )
end

#type(name = NO_ARG) ⇒ Object



16
17
18
19
# File 'lib/media_types/constructable.rb', line 16

def type(name = NO_ARG)
  return opts[:type] if name == NO_ARG
  with(type: name)
end

#valid?(output, **validation_opts) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
92
93
94
# File 'lib/media_types/constructable.rb', line 88

def valid?(output, **validation_opts)
  __getobj__.valid?(
    output,
    self,
    **validation_opts
  )
end

#validatable?Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/media_types/constructable.rb', line 104

def validatable?
  __getobj__.validatable?(self)
end

#validate!(output, **validation_opts) ⇒ Object



96
97
98
99
100
101
102
# File 'lib/media_types/constructable.rb', line 96

def validate!(output, **validation_opts)
  __getobj__.validate!(
    output,
    self,
    **validation_opts
  )
end

#version(version = NO_ARG) ⇒ Object



21
22
23
24
# File 'lib/media_types/constructable.rb', line 21

def version(version = NO_ARG)
  return opts[:version] if version == NO_ARG
  with(version: version)
end

#view(view = NO_ARG) ⇒ Object



26
27
28
29
# File 'lib/media_types/constructable.rb', line 26

def view(view = NO_ARG)
  return opts[:view] if view == NO_ARG
  with(view: view)
end