Module: SyncableModels::Controller::ClassMethods
- Defined in:
- lib/syncable_models/controller.rb
Instance Method Summary collapse
- #authorize_by_key(key = nil) ⇒ Object
- #sync_for(subject, id_key: :uuid, class_name: nil, sync_method: nil, fetch_method: nil) ⇒ Object
Instance Method Details
#authorize_by_key(key = nil) ⇒ Object
25 26 27 28 |
# File 'lib/syncable_models/controller.rb', line 25 def (key=nil) define_method(:api_key){ key } before_action :do_authorize_by_key end |
#sync_for(subject, id_key: :uuid, class_name: nil, sync_method: nil, fetch_method: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/syncable_models/controller.rb', line 7 def sync_for(subject, id_key: :uuid, class_name: nil, sync_method: nil, fetch_method: nil) klass = class_name || subject.to_s.singularize.camelize klass = klass.constantize unless klass.is_a?(Class) sync_method = sync_method || "sync_#{subject}" fetch_method = fetch_method || "#{subject}" class_eval """ def #{sync_method} set_synced #{klass.name}, :#{id_key.to_s} end def #{fetch_method} fetch #{klass.name} end """ end |