Class: KongSchema::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/kong_schema/adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:) ⇒ Adapter

Returns a new instance of Adapter.



9
10
11
# File 'lib/kong_schema/adapter.rb', line 9

def initialize(model:)
  @model = model
end

Class Method Details

.for(model) ⇒ Object



5
6
7
# File 'lib/kong_schema/adapter.rb', line 5

def self.for(model)
  new(model: model)
end

Instance Method Details

#changed?(current_attributes, next_attributes) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/kong_schema/adapter.rb', line 17

def changed?(current_attributes, next_attributes)
  next_attributes.keys.any? do |key|
    !current_attributes[key].eql?(next_attributes[key])
  end
end

#create(params) ⇒ Object



13
14
15
# File 'lib/kong_schema/adapter.rb', line 13

def create(params)
  @model.create(params)
end

#delete(record) ⇒ Object



31
32
33
# File 'lib/kong_schema/adapter.rb', line 31

def delete(record)
  record.delete
end

#update(record, params) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/kong_schema/adapter.rb', line 23

def update(record, params)
  params.keys.each do |key|
    record.attributes[key] = params[key]
  end

  record.save
end