Module: ActiveGit::ActiveRecord::ClassMethods
- Defined in:
- lib/active_git/active_record_extension.rb
Instance Method Summary collapse
- #git_deep_included_associations(arg) ⇒ Object
- #git_included_associations ⇒ Object
- #git_included_in(model) ⇒ Object
- #git_included_models ⇒ Object
- #git_options ⇒ Object
- #git_versioned(options = {}) ⇒ Object
Instance Method Details
#git_deep_included_associations(arg) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_git/active_record_extension.rb', line 22 def git_deep_included_associations(arg) return [] if arg.nil? if arg.is_a? Array arg elsif arg.is_a? Hash arg.keys + git_deep_included_associations(arg.map{|k,v| v[:include]}) else [arg] end end |
#git_included_associations ⇒ Object
18 19 20 |
# File 'lib/active_git/active_record_extension.rb', line 18 def git_included_associations git_deep_included_associations [:include] end |
#git_included_in(model) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/active_git/active_record_extension.rb', line 48 def git_included_in(model) after_save do instance = send model #TODO: Ver si se puede optimizar el reload para que no lo haga siempre ActiveGit.synchronize FileSave.new(instance.reload) if instance end after_destroy do instance = send model ActiveGit.synchronize FileSave.new(instance.reload) if instance end end |
#git_included_models ⇒ Object
14 15 16 |
# File 'lib/active_git/active_record_extension.rb', line 14 def git_included_models git_included_associations.map { |a| reflections[a] ? reflections[a].klass : a.to_s.classify.constantize } end |
#git_options ⇒ Object
10 11 12 |
# File 'lib/active_git/active_record_extension.rb', line 10 def @options end |
#git_versioned(options = {}) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 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 42 43 44 45 46 |
# File 'lib/active_git/active_record_extension.rb', line 6 def git_versioned(={}) @options = .merge root: false def @options end def git_included_models git_included_associations.map { |a| reflections[a] ? reflections[a].klass : a.to_s.classify.constantize } end def git_included_associations git_deep_included_associations [:include] end def git_deep_included_associations(arg) return [] if arg.nil? if arg.is_a? Array arg elsif arg.is_a? Hash arg.keys + git_deep_included_associations(arg.map{|k,v| v[:include]}) else [arg] end end include InstanceMethods ActiveGit.models << self after_save do |record| ActiveGit.synchronize FileSave.new(record) end after_destroy do |record| ActiveGit.synchronize FileDelete.new(record) end end |