Class: MediaTypes::Constructable
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- MediaTypes::Constructable
- Defined in:
- lib/media_types/constructable.rb
Defined Under Namespace
Classes: NoArgumentGiven
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object
- #===(other) ⇒ Object
- #collection ⇒ Object
- #collection? ⇒ Boolean
- #create ⇒ Object
- #create? ⇒ Boolean
- #hash ⇒ Object
- #index ⇒ Object
- #index? ⇒ Boolean
-
#initialize(klazz, **opts) ⇒ Constructable
constructor
A new instance of Constructable.
- #split(pattern = nil, *limit) ⇒ Object
- #suffix(suffix = NO_ARG) ⇒ Object
- #to_str(qualifier = nil) ⇒ Object (also: #inspect, #to_s)
- #type(name = NO_ARG) ⇒ Object
- #valid?(output, **validation_opts) ⇒ Boolean
- #validate!(output, **validation_opts) ⇒ Object
- #version(version = NO_ARG) ⇒ Object
- #view(view = NO_ARG) ⇒ Object
Constructor Details
#initialize(klazz, **opts) ⇒ Constructable
Returns a new instance of Constructable.
9 10 11 12 |
# File 'lib/media_types/constructable.rb', line 9 def initialize(klazz, **opts) super klazz self.opts = opts end |
Instance Method Details
#+(other) ⇒ Object
66 67 68 |
# File 'lib/media_types/constructable.rb', line 66 def +(other) to_str + other end |
#==(other) ⇒ Object
62 63 64 |
# File 'lib/media_types/constructable.rb', line 62 def ==(other) to_str.send(:==, other) end |
#===(other) ⇒ Object
58 59 60 |
# File 'lib/media_types/constructable.rb', line 58 def ===(other) to_str.send(:===, other) end |
#collection ⇒ Object
34 35 36 |
# File 'lib/media_types/constructable.rb', line 34 def collection view(COLLECTION_VIEW) end |
#collection? ⇒ Boolean
38 39 40 |
# File 'lib/media_types/constructable.rb', line 38 def collection? opts[:view] == COLLECTION_VIEW end |
#create ⇒ Object
42 43 44 |
# File 'lib/media_types/constructable.rb', line 42 def create view(CREATE_VIEW) end |
#create? ⇒ Boolean
46 47 48 |
# File 'lib/media_types/constructable.rb', line 46 def create? opts[:view] == CREATE_VIEW end |
#hash ⇒ Object
74 75 76 |
# File 'lib/media_types/constructable.rb', line 74 def hash to_str.hash end |
#index ⇒ Object
50 51 52 |
# File 'lib/media_types/constructable.rb', line 50 def index view(INDEX_VIEW) end |
#index? ⇒ Boolean
54 55 56 |
# File 'lib/media_types/constructable.rb', line 54 def index? opts[:view] == INDEX_VIEW end |
#split(pattern = nil, *limit) ⇒ Object
70 71 72 |
# File 'lib/media_types/constructable.rb', line 70 def split(pattern = nil, *limit) to_str.split(pattern, *limit) end |
#suffix(suffix = NO_ARG) ⇒ Object
29 30 31 32 |
# File 'lib/media_types/constructable.rb', line 29 def suffix(suffix = NO_ARG) return opts[:suffix] if suffix == NO_ARG Constructable.new(__getobj__, **with(suffix: suffix)) end |
#to_str(qualifier = nil) ⇒ Object Also known as: inspect, to_s
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/media_types/constructable.rb', line 78 def to_str(qualifier = nil) # TODO: remove warning by slicing out these arguments if they don't appear in the format qualified(qualifier, @to_str ||= format( opts.fetch(:format), version: opts.fetch(:version), suffix: opts.fetch(:suffix) { :json }, type: opts.fetch(:type), view: format_view(opts[:view]) )) end |
#type(name = NO_ARG) ⇒ Object
14 15 16 17 |
# File 'lib/media_types/constructable.rb', line 14 def type(name = NO_ARG) return opts[:type] if name == NO_ARG Constructable.new(__getobj__, **with(type: name)) end |
#valid?(output, **validation_opts) ⇒ Boolean
89 90 91 92 93 94 95 |
# File 'lib/media_types/constructable.rb', line 89 def valid?(output, **validation_opts) __getobj__.valid?( output, self, **validation_opts ) end |
#validate!(output, **validation_opts) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/media_types/constructable.rb', line 97 def validate!(output, **validation_opts) __getobj__.validate!( output, self, **validation_opts ) end |
#version(version = NO_ARG) ⇒ Object
19 20 21 22 |
# File 'lib/media_types/constructable.rb', line 19 def version(version = NO_ARG) return opts[:version] if version == NO_ARG Constructable.new(__getobj__, **with(version: version)) end |
#view(view = NO_ARG) ⇒ Object
24 25 26 27 |
# File 'lib/media_types/constructable.rb', line 24 def view(view = NO_ARG) return opts[:view] if view == NO_ARG Constructable.new(__getobj__, **with(view: view)) end |