Module: Sumaki::Model::InstanceMethods

Defined in:
lib/sumaki/model.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



216
217
218
# File 'lib/sumaki/model.rb', line 216

def object
  @object
end

#parentObject (readonly)

Returns the value of attribute parent.



216
217
218
# File 'lib/sumaki/model.rb', line 216

def parent
  @parent
end

Instance Method Details

#assign(attrs) ⇒ Object



235
236
237
238
239
# File 'lib/sumaki/model.rb', line 235

def assign(attrs)
  attrs.each do |attr, value|
    public_send(:"#{attr}=", value)
  end
end

#get(name) ⇒ Object



227
228
229
# File 'lib/sumaki/model.rb', line 227

def get(name)
  object_accessor.get(name)
end

#initialize(object, parent: nil) ⇒ Object



218
219
220
221
# File 'lib/sumaki/model.rb', line 218

def initialize(object, parent: nil)
  @object = object
  @parent = parent
end

#inspectObject



241
242
243
244
245
246
# File 'lib/sumaki/model.rb', line 241

def inspect
  inspection = attributes
               .map { |name, value| "#{name}: #{value.inspect}" }
               .join(', ')
  "#<#{self.class.name} #{inspection}>"
end

#object_accessorObject



223
224
225
# File 'lib/sumaki/model.rb', line 223

def object_accessor
  @object_accessor ||= ObjectAccessor.new(object, self.class.adapter)
end

#pretty_print(pp) ⇒ Object

rubocop:disable Metrics/MethodLength



248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/sumaki/model.rb', line 248

def pretty_print(pp) # rubocop:disable Metrics/MethodLength
  pp.object_address_group(self) do
    pp.seplist(attributes, -> { pp.text ',' }) do |attribute, value|
      pp.breakable
      pp.group(1) do
        pp.text attribute.to_s
        pp.text ':'
        pp.breakable
        pp.pp value
      end
    end
  end
end

#set(name, value) ⇒ Object



231
232
233
# File 'lib/sumaki/model.rb', line 231

def set(name, value)
  object_accessor.set(name, value)
end