Module: Ninsho::Interface::ClassMethods
- Defined in:
- lib/ninsho/interface.rb
Instance Attribute Summary collapse
-
#auth_hash ⇒ Object
Returns the value of attribute auth_hash.
Instance Method Summary collapse
- #belongs_to_ninsho(*args) ⇒ Object
-
#from_omniauth(omniauth = nil) ⇒ Object
Responsible for creating or find the record with the omniauth hash.
Instance Attribute Details
#auth_hash ⇒ Object
Returns the value of attribute auth_hash.
15 16 17 |
# File 'lib/ninsho/interface.rb', line 15 def auth_hash @auth_hash end |
Instance Method Details
#belongs_to_ninsho(*args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ninsho/interface.rb', line 17 def belongs_to_ninsho(*args) = args. Ninsho.parent_resource_holding_attributes = [:hold_attributes] || [] .reject! { |k, v| k == :hold_attributes } 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 ## Attributes delegation Ninsho.parent_resource_holding_attributes.each do |attr| delegate attr, to: Ninsho.parent_resource_name.to_s.downcase.to_sym class_eval <<-RUBY def #{attr}=(value) self.#{Ninsho.parent_resource_name.to_s.downcase.to_sym}.#{attr} = value end RUBY end end |
#from_omniauth(omniauth = nil) ⇒ Object
Responsible for creating or find the record with the omniauth hash
45 46 47 48 |
# File 'lib/ninsho/interface.rb', line 45 def from_omniauth(omniauth = nil) self.auth_hash = omniauth Ninsho::Authentication.new(omniauth) end |