Class: Ki::Model

Inherits:
Object
  • Object
show all
Extended by:
QueryInterface, Restrictions
Includes:
Callbacks, ModelHelper
Defined in:
lib/ki/model.rb,
lib/ki/modules/callbacks.rb,
lib/ki/modules/model_helper.rb,
lib/ki/modules/restrictions.rb,
lib/ki/modules/query_interface.rb

Defined Under Namespace

Modules: Callbacks, ModelHelper, QueryInterface, Restrictions

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from QueryInterface

class_name, count, find_or_create

Methods included from Restrictions

forbid, forbidden_actions, required_attributes, requires, unique, unique_attributes

Methods included from ModelHelper

#delete?, #forbidden_actions, #get?, #post?, #put?, #required_attributes, #skipped_params, #unique_attributes

Methods included from Callbacks

#after_all, #after_create, #after_delete, #after_find, #after_update, #before_all, #before_create, #before_delete, #before_find, #before_update

Constructor Details

#initialize(action, params) ⇒ Model

Returns a new instance of Model.



10
11
12
13
14
15
16
17
18
# File 'lib/ki/model.rb', line 10

def initialize(action, params)
  @action = action
  @params = params
  @status = 200

  fail ForbiddenAction if forbidden_actions.include? @action

  ccall
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



8
9
10
# File 'lib/ki/model.rb', line 8

def action
  @action
end

#paramsObject

Returns the value of attribute params.



8
9
10
# File 'lib/ki/model.rb', line 8

def params
  @params
end

#resultObject

Returns the value of attribute result.



8
9
10
# File 'lib/ki/model.rb', line 8

def result
  @result
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/ki/model.rb', line 8

def status
  @status
end

Instance Method Details

#createObject



24
25
26
27
28
# File 'lib/ki/model.rb', line 24

def create
  check_for_required_attributes
  check_for_unique_attributes
  @result = self.class.create @params
end

#deleteObject



36
37
38
# File 'lib/ki/model.rb', line 36

def delete
  @result = self.class.delete @params
end

#findObject



20
21
22
# File 'lib/ki/model.rb', line 20

def find
  @result = self.class.find @params
end

#updateObject



30
31
32
33
34
# File 'lib/ki/model.rb', line 30

def update
  check_for_required_attributes
  check_for_unique_attributes
  @result = self.class.update @params
end