Class: LC::Bytes

Inherits:
Object
  • Object
show all
Defined in:
lib/leancloud/datatypes.rb

Overview

Bytes


Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Bytes

Returns a new instance of Bytes.



134
135
136
137
# File 'lib/leancloud/datatypes.rb', line 134

def initialize(data)
  bytes = data["base64"]
  @value = Base64.decode64(bytes)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



154
155
156
157
158
159
160
# File 'lib/leancloud/datatypes.rb', line 154

def method_missing(method, *args, &block)
  if value.respond_to?(method)
    value.send(method, *args, &block)
  else
    super(method)
  end
end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



132
133
134
# File 'lib/leancloud/datatypes.rb', line 132

def value
  @value
end

Instance Method Details

#<=>(other) ⇒ Object



150
151
152
# File 'lib/leancloud/datatypes.rb', line 150

def <=>(other)
  value <=> other.value
end

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


139
140
141
142
# File 'lib/leancloud/datatypes.rb', line 139

def eql?(other)
  self.class.equal?(other.class) &&
    value == other.value
end

#hashObject



146
147
148
# File 'lib/leancloud/datatypes.rb', line 146

def hash
  value.hash
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/leancloud/datatypes.rb', line 162

def respond_to?(method, include_private = false)
  super || value.respond_to?(method, include_private)
end

#to_h(*a) ⇒ Object Also known as: as_json



166
167
168
169
170
171
# File 'lib/leancloud/datatypes.rb', line 166

def to_h(*a)
  {
      Protocol::KEY_TYPE => Protocol::TYPE_BYTES,
      "base64" => Base64.encode64(@value)
  }
end

#to_json(*a) ⇒ Object



174
175
176
# File 'lib/leancloud/datatypes.rb', line 174

def to_json(*a)
  to_h.to_json(*a)
end