blob: 6cf4c6b02f1ece78eb50cad7b928d105a699becb (
plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
class Export::Base < ActiveRecord::Base
self.table_name = "exports"
belongs_to :referential
validates :type, :referential_id, presence: true
def self.messages_class_name
"Export::Message"
end
def self.resources_class_name
"Export::Resource"
end
def self.human_name
I18n.t("export.#{self.name.demodulize.underscore}")
end
def self.file_extension_whitelist
%w(zip csv json)
end
if Rails.env.development?
def self.force_load_descendants
path = Rails.root.join 'app/models/export'
Dir.chdir path do
Dir['**/*.rb'].each do |src|
next if src =~ /^base/
klass_name = "Export::#{src[0..-4].camelize}"
Rails.logger.info "Loading #{klass_name}"
begin
klass_name.constantize
rescue => e
Rails.logger.info "Failed: #{e.message}"
nil
end
end
end
end
end
def self.user_visible?
false
end
def self.inherited child
super child
child.instance_eval do
def self.user_visible?
true
end
end
end
def self.option name, opts={}
store_accessor :options, name
if opts[:serialize]
define_method name do
JSON.parse(options[name.to_s]) rescue opts[:serialize].new
end
end
if !!opts[:required]
validates name, presence: true
end
@options ||= {}
@options[name] = opts
end
def self.options
@options ||= {}
end
def self.options= options
@options = options
end
include IevInterfaces::Task
def self.model_name
ActiveModel::Name.new Export::Base, Export::Base, "Export"
end
def self.user_visible_descendants
descendants.select &:user_visible?
end
def self.user_visible?
true
end
def visible_options
options.select{|k, v| ! k.match /^_/}
end
def display_option_value option_name, context
option = self.class.options[option_name.to_sym]
val = self.options[option_name.to_s]
if option[:display]
context.instance_exec(val, &option[:display])
else
val
end
end
private
def initialize_fields
super
self.token_upload = SecureRandom.urlsafe_base64
end
end
|