Module: Hippo::Concerns::TrackModifications::ClassMethods

Defined in:
lib/hippo/access/track_modifications.rb

Instance Method Summary collapse

Instance Method Details

#should_record_user_modifications?Boolean

Returns:

  • (Boolean)

14
15
16
# File 'lib/hippo/access/track_modifications.rb', line 14

def should_record_user_modifications?
    record_user_modifications
end

#tracks_user_modificationsObject


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/hippo/access/track_modifications.rb', line 18

def tracks_user_modifications
    belongs_to :created_by, :class_name=>'Hippo::User'
    belongs_to :updated_by, :class_name=>'Hippo::User'

    before_update :record_update_modifications
    before_create :record_create_modifications

    self.export_scope :with_user_logins

    class_attribute :record_user_modifications
    self.record_user_modifications = true
end

#with_user_loginsObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hippo/access/track_modifications.rb', line 32

def with_user_logins
    q = self; t = table_name
    if current_scope.nil? || current_scope.select_values.exclude?("#{t}.*")
        q = q.select("#{t}.*")
    end
    if self.column_names.include?('created_by_id')
        q = q.select("created_by_user.login as created_by_login")
              .joins("left join hippo_users as created_by_user on " \
                     "created_by_user.id = #{t}.created_by_id")
    end
    if self.column_names.include?('updated_by_id')
        q = q.select("updated_by_user.login as updated_by_login")
              .joins("left join hippo_users as updated_by_user on " \
                     "updated_by_user.id = #{t}.updated_by_id")
    end
    q
end