Class: Ki::Model

Inherits:
Object
  • Object
show all
Extended by:
QueryInterface, Restrictions
Includes:
Ki::Middleware::Helpers::RedirectTo, 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 Ki::Middleware::Helpers::RedirectTo

#redirect_to

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(req) ⇒ Model

Returns a new instance of Model.



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

def initialize(req)
  @req = req
  @action = req.to_action
  @params = req.params
  @status = 200

  fail ForbiddenAction if forbidden_actions.include? @action

  ccall
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



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

def action
  @action
end

#paramsObject

Returns the value of attribute params.



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

def params
  @params
end

#reqObject

Returns the value of attribute req.



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

def req
  @req
end

#resultObject

Returns the value of attribute result.



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

def result
  @result
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#createObject



26
27
28
29
30
# File 'lib/ki/model.rb', line 26

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

#deleteObject



38
39
40
# File 'lib/ki/model.rb', line 38

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

#findObject



22
23
24
# File 'lib/ki/model.rb', line 22

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

#updateObject



32
33
34
35
36
# File 'lib/ki/model.rb', line 32

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