-
Notifications
You must be signed in to change notification settings - Fork 120
/
Copy pathsmart_answer_files.rb
67 lines (54 loc) · 1.53 KB
/
smart_answer_files.rb
1
2
3
4
5
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
class SmartAnswerFiles
def initialize(flow_name, *additional_files_paths)
@flow_name = flow_name
@additional_files_paths = additional_files_paths.map do |path|
Pathname.new(path)
end
end
def paths
relative_paths.map(&:to_s).uniq
end
def existing_paths
@existing_paths ||= paths.select { |path| File.exist?(path) }
end
def empty?
existing_paths.empty?
end
private
def relative_paths
@relative_paths ||= all_paths.collect do |path|
path.relative_path_from(Rails.root)
end
end
def all_paths
[
flow_path,
locale_path,
questions_and_responses_test_data_path,
responses_and_expected_results_test_data_path
] + erb_template_paths + additional_files_absolute_paths
end
def erb_template_directory
Rails.root.join('lib', 'smart_answer_flows', @flow_name)
end
def erb_template_paths
Dir[erb_template_directory.join('**/*.erb')].collect do |path|
Pathname.new(path)
end
end
def additional_files_absolute_paths
@additional_files_paths.select(&:exist?).map(&:realpath)
end
def flow_path
Rails.root.join('lib', 'smart_answer_flows', "#{@flow_name}.rb")
end
def locale_path
Rails.root.join('lib', 'smart_answer_flows', 'locales', 'en', "#{@flow_name}.yml")
end
def questions_and_responses_test_data_path
SmartAnswerTestHelper.new(@flow_name).question_and_responses_path
end
def responses_and_expected_results_test_data_path
SmartAnswerTestHelper.new(@flow_name).responses_and_expected_results_path
end
end