Module: OpenidRegistrable::ClassMethods
- Defined in:
- lib/openid_registrable/openid_registrable.rb
Instance Method Summary collapse
Instance Method Details
#openid_registrable(options) ⇒ Object
Using:
class User < ActiveRecord::Base
openid_registrable :required_fields => {
:email => 'http://axschema.org/contact/email',
},
:optional_fields => {
:first_name => 'http://axschema.org/namePerson/first',
:last_name => 'http://axschema.org/namePerson/last',
}
end
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/openid_registrable/openid_registrable.rb', line 23 def openid_registrable() [:required_fields, :optional_fields].each do |fields| unless [fields].empty? (class << self; self; end).instance_eval do # define methods openid_require_fields and openid_optional_fields # methods returns array generated from options given in #openid_registrable, e.g.: # => ['http://axschema.org/namePerson/first', 'http://axschema.org/namePerson/last'] define_method "openid_#{fields}" do [fields].values end end end end # define method :openid_fields_to_model_fields_mapping # method returns hash genered from options given in #openid_registrable, e.g.: # => {:first_name=>"http://axschema.org/namePerson/first", # :last_name=>"http://axschema.org/namePerson/last"} if [:required_fields] or [:optional_fields] (class << self; self; end).instance_eval do define_method :openid_fields_to_model_fields_mapping do mapping = {} mapping.merge!([:required_fields]) if [:required_fields] mapping.merge!([:optional_fields]) if [:optional_fields] end end end send :include, InstanceMethods end |