Sha256: 7aab4d7f1967098af0e8e1c385cdb34bab6b191bea766e77731613e0276be4d0

Contents?: true

Size: 863 Bytes

Versions: 2

Compression:

Stored size: 863 Bytes

Contents

require 'ninsho/authentication'

module Ninsho
  module Interface
    def self.included(base)
      base.extend(ClassMethods)
    end

    module ClassMethods
      
      def belongs_to_ninsho(*args)
        options = args.extract_options!
        
        associations = args.collect(&:to_s).collect(&:downcase)
        association_keys = associations.collect { |association| "#{association}_id" } 

        #Set the belongs_to association by ActiveRecord
        associations.each do |associated_model|
          belongs_to associated_model.to_sym
          Ninsho.parent_resource_name = Ninsho.ref(associated_model.to_s.classify).get
        end
      end
      
      # Responsible for creating or find the record with the
      # omniauth hash
      def from_omniauth(omniauth = nil)
        Ninsho::Authentication.new(omniauth)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ninsho-0.0.3 lib/ninsho/interface.rb
ninsho-0.0.2 lib/ninsho/interface.rb