Class: NinshoController

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/ninsho_controller.rb

Direct Known Subclasses

Ninsho::SessionsController

Instance Method Summary collapse

Instance Method Details

#build_resource_from_omniauthObject

Build a ninsho resource, from the omniauth hash



48
49
50
# File 'app/controllers/ninsho_controller.rb', line 48

def build_resource_from_omniauth 
  self.resource = resource_class.from_omniauth(resource_params)
end

#flash_message(key, action) ⇒ Object

Sets the flash message with :key, using I18n. Example (i18n locale file):

en:
  ninsho:
    :sessions
      signed_in: "Signed in successfully"


11
12
13
14
# File 'app/controllers/ninsho_controller.rb', line 11

def flash_message(key, action) 
  message = I18n.t("ninsho.sessions.#{action}")
  flash[key] = message if message.present?
end

#parent_resourceObject

Parent resource, commonly user



43
44
45
# File 'app/controllers/ninsho_controller.rb', line 43

def parent_resource
  resource_class.reflect_on_all_associations(:belongs_to).first.name.to_s
end

#resourceObject

Gets the actual resource stored in the instance variable



17
18
19
# File 'app/controllers/ninsho_controller.rb', line 17

def resource
  instance_variable_get(:"@#{resource_name}")
end

#resource=(new_resource) ⇒ Object

Sets the resource creating an instance variable



38
39
40
# File 'app/controllers/ninsho_controller.rb', line 38

def resource=(new_resource)
  instance_variable_set(:"@#{resource_name}", new_resource)
end

#resource_classObject

Class name for the ninsho model commonly Authentication



33
34
35
# File 'app/controllers/ninsho_controller.rb', line 33

def resource_class
  Ninsho.resource_class 
end

#resource_nameObject

Proxy to ninsho map name



27
28
29
# File 'app/controllers/ninsho_controller.rb', line 27

def resource_name
  Ninsho.resource_name #authentication
end

#resource_paramsObject

Omniauth hash for creating the records



22
23
24
# File 'app/controllers/ninsho_controller.rb', line 22

def resource_params
  env['omniauth.auth']
end