Module: PaperTrail::Rails
- Defined in:
- lib/paper_trail/rails.rb,
lib/paper_trail/rails/console.rb,
lib/paper_trail/rails/general.rb,
lib/paper_trail/rails/railtie.rb,
lib/paper_trail/rails/version.rb,
lib/paper_trail/rails/configuration.rb,
lib/paper_trail/rails/migration_extensions.rb,
lib/paper_trail/rails/runner_command_extensions.rb,
lib/paper_trail/rails/runner_command_extensions.rb
Overview
This is the main module for this gem. Can’t make it a class because paper_trail gem already defines this module; otherwise I would have made this a class.
Defined Under Namespace
Modules: Console, General, RecordMigrationNameInVersion, RunnerCommandExtensions
Classes: Configuration, Railtie
Class Method Summary
collapse
Class Method Details
.configuration ⇒ Object
Also known as:
config
22
23
24
|
# File 'lib/paper_trail/rails.rb', line 22
def configuration
@configuration ||= Configuration.new
end
|
27
28
29
|
# File 'lib/paper_trail/rails.rb', line 27
def configure
yield config
end
|
.default_command ⇒ Object
44
45
46
47
48
49
50
|
# File 'lib/paper_trail/rails.rb', line 44
def default_command
program_name = File.basename($PROGRAM_NAME)
returning = program_name
returning << " #{rails_subcommand}" if program_name == 'rails'
returning << " #{ARGV.join(' ')}" if ARGV.any?
returning
end
|
.get_reason(required: false) ⇒ Object
70
71
72
73
74
75
76
77
78
|
# File 'lib/paper_trail/rails.rb', line 70
def get_reason(required: false)
reason = nil
until reason.present? do
print "What is the reason for this change? "
reason = gets.chomp
break unless required
end
reason
end
|
.rails_subcommand ⇒ Object
52
53
54
55
56
57
|
# File 'lib/paper_trail/rails.rb', line 52
def rails_subcommand
regexp = %r{lib/rails/commands/\w+/(\w+)_command\.rb}
if (frame = caller.detect { |f| f =~ regexp })
frame.match(regexp)[1]
end
end
|
.select_user(required: false) ⇒ Object
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/paper_trail/rails.rb', line 59
def select_user(required: false)
other_allowed_values = config.select_user_other_allowed_values
other_values_prompt = " (or #{other_allowed_values.join(' or ')})" if other_allowed_values.present?
General.select_user(
filter: config.select_user_filter,
other_allowed_values: other_allowed_values,
prompt: "Please enter a User id#{other_values_prompt}",
required: required
)
end
|
Store some metadata about where the change came from
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/paper_trail/rails.rb', line 32
def set_default_metadata
PaperTrail.reverse_update_metadata(
command: default_command,
)
PaperTrail.update_metadata(
source_location: caller.find { |line|
line.starts_with? ::Rails.root.to_s and
config.source_location_filter.(line)
}
)
end
|
.version ⇒ Object
3
4
5
|
# File 'lib/paper_trail/rails/version.rb', line 3
def self.version
"0.6.1"
end
|