k_domain 0.0.20 → 0.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.builders/config/_.rb +3 -0
- data/.builders/setup.rb +30 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +1 -2
- data/Guardfile +1 -0
- data/README.md +15 -0
- data/lib/k_domain/domain_model/transform.rb +23 -13
- data/lib/k_domain/domain_model/transform_steps/_.rb +7 -5
- data/lib/k_domain/domain_model/transform_steps/step.rb +20 -0
- data/lib/k_domain/domain_model/transform_steps/{step1_attach_db_schema.rb → step1_db_schema.rb} +2 -1
- data/lib/k_domain/domain_model/transform_steps/{step6_attach_dictionary.rb → step20_dictionary.rb} +6 -6
- data/lib/k_domain/domain_model/transform_steps/step2_domain_models.rb +123 -0
- data/lib/k_domain/domain_model/transform_steps/step4_rails_resource_models.rb +3 -3
- data/lib/k_domain/domain_model/transform_steps/step5_rails_resource_routes.rb +36 -0
- data/lib/k_domain/domain_model/transform_steps/step6_rails_structure_models.rb +90 -0
- data/lib/k_domain/domain_model/transform_steps/step7_rails_structure_controllers.rb +109 -0
- data/lib/k_domain/domain_model/transform_steps/{step3_attach_columns.rb → step8_domain_columns.rb} +40 -73
- data/lib/k_domain/rails_code_extractor/_.rb +5 -0
- data/lib/k_domain/rails_code_extractor/extract_controller.rb +59 -0
- data/lib/k_domain/rails_code_extractor/extract_model.rb +19 -8
- data/lib/k_domain/rails_code_extractor/shim_loader.rb +1 -0
- data/lib/k_domain/raw_db_schema/load.rb +1 -1
- data/lib/k_domain/raw_db_schema/transform.rb +2 -1
- data/lib/k_domain/schemas/_.rb +2 -2
- data/lib/k_domain/schemas/database.rb +86 -0
- data/lib/k_domain/schemas/domain.rb +154 -0
- data/lib/k_domain/schemas/domain_model.rb +2 -2
- data/lib/k_domain/schemas/rails_resource.rb +43 -6
- data/lib/k_domain/schemas/rails_structure.rb +94 -14
- data/lib/k_domain/version.rb +1 -1
- data/lib/k_domain.rb +1 -2
- data/templates/custom/action_controller.rb +36 -0
- data/templates/custom/controller_interceptors.rb +78 -0
- data/templates/custom/model_interceptors.rb +71 -0
- data/templates/load_schema.rb +7 -0
- data/templates/old_printspeek_schema copy.rb +231 -0
- data/templates/old_printspeek_schema.rb +233 -0
- data/templates/rails/action_controller.rb +301 -0
- data/templates/{active_record_shims.rb → rails/active_record.rb} +21 -41
- data/templates/ruby_code_extractor/attach_class_info.rb +13 -0
- data/templates/ruby_code_extractor/behaviour_accessors.rb +39 -0
- data/templates/simple/controller_interceptors.rb +2 -0
- metadata +26 -18
- data/lib/k_domain/domain_model/transform_steps/step2_attach_models.rb +0 -62
- data/lib/k_domain/domain_model/transform_steps/step5_rails_models.rb +0 -71
- data/lib/k_domain/schemas/database/_.rb +0 -7
- data/lib/k_domain/schemas/database/foreign_key.rb +0 -14
- data/lib/k_domain/schemas/database/index.rb +0 -14
- data/lib/k_domain/schemas/database/schema.rb +0 -31
- data/lib/k_domain/schemas/database/table.rb +0 -32
- data/lib/k_domain/schemas/domain/domain.rb +0 -11
- data/lib/k_domain/schemas/domain/models/column.rb +0 -49
- data/lib/k_domain/schemas/domain/models/model.rb +0 -111
- data/templates/fake_module_shims.rb +0 -42
@@ -0,0 +1,233 @@
|
|
1
|
+
class LoadSchema
|
2
|
+
attr_reader :schema
|
3
|
+
|
4
|
+
# XMEN
|
5
|
+
def initialize
|
6
|
+
@unique_keys = {}
|
7
|
+
@current_table = nil
|
8
|
+
@rails_version = 4
|
9
|
+
@schema = {
|
10
|
+
tables: [],
|
11
|
+
foreign_keys: [],
|
12
|
+
indexes: [],
|
13
|
+
views: [],
|
14
|
+
meta: {
|
15
|
+
rails: @rails_version,
|
16
|
+
db_info: {
|
17
|
+
type: 'postgres',
|
18
|
+
version: nil, # TODO
|
19
|
+
extensions: []
|
20
|
+
},
|
21
|
+
unique_keys: []
|
22
|
+
}
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# ----------------------------------------------------------------------
|
27
|
+
# Inject start
|
28
|
+
# original file: {{source_file}}
|
29
|
+
# ----------------------------------------------------------------------
|
30
|
+
def load_schema
|
31
|
+
{{rails_schema}}
|
32
|
+
end
|
33
|
+
|
34
|
+
# ----------------------------------------------------------------------
|
35
|
+
# original file: {{source_file}}
|
36
|
+
# Inject end
|
37
|
+
# ----------------------------------------------------------------------
|
38
|
+
|
39
|
+
def write_json(file)
|
40
|
+
schema[:meta][:rails] = @rails_version
|
41
|
+
File.write(file, JSON.pretty_generate(schema))
|
42
|
+
end
|
43
|
+
|
44
|
+
# This is the rails timestamp and will be replaced by the action rails version
|
45
|
+
def load(version:)
|
46
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
47
|
+
# puts 'about to load'
|
48
|
+
yield if block_given?
|
49
|
+
|
50
|
+
schema[:meta][:rails] = @rails_version
|
51
|
+
|
52
|
+
sort
|
53
|
+
# code to time
|
54
|
+
|
55
|
+
# log.kv 'extensions', schema[:db_info][:extensions].length
|
56
|
+
# log.kv 'tables', schema[:tables].length
|
57
|
+
# log.kv 'indexes', schema[:indexes].length
|
58
|
+
# # a low foreign_keys count is indicative of not using SQL referential integrity
|
59
|
+
# log.kv 'foreign_keys', schema[:foreign_keys].length
|
60
|
+
# log.kv 'Time Taken', (finish - start)
|
61
|
+
|
62
|
+
# puts schema[:db_info][:extensions]
|
63
|
+
# print_unique_keys(type: :foreign_keys, title: 'unique options for foreign_keys')
|
64
|
+
# print_unique_keys(type: :columns, title: 'unique options for columns')
|
65
|
+
# print_unique_keys(type: :fields, category: :integer , title: 'unique options for column - integer')
|
66
|
+
# print_unique_keys(type: :fields, category: :decimal , title: 'unique options for column - decimal')
|
67
|
+
# print_unique_keys(type: :fields, category: :string , title: 'unique options for column - string')
|
68
|
+
# print_unique_keys(type: :fields, category: :datetime, title: 'unique options for column - datetime')
|
69
|
+
# print_unique_keys(type: :fields, category: :date , title: 'unique options for column - date')
|
70
|
+
# print_unique_keys(type: :fields, category: :text , title: 'unique options for column - text')
|
71
|
+
# print_unique_keys(type: :fields, category: :boolean , title: 'unique options for column - boolean')
|
72
|
+
# print_unique_keys(type: :fields, category: :jsonb , title: 'unique options for column - jsonb')
|
73
|
+
# print_unique_keys(type: :fields, category: :hstore , title: 'unique options for column - hstore')
|
74
|
+
# print_unique_keys(type: :fields, category: :float , title: 'unique options for column - float')
|
75
|
+
end
|
76
|
+
|
77
|
+
def enable_extension(name)
|
78
|
+
# puts "enable_extension(#{name})"
|
79
|
+
schema[:meta][:db_info][:extensions] << name
|
80
|
+
end
|
81
|
+
|
82
|
+
def create_table(name, **opts)
|
83
|
+
id = opts[:id]
|
84
|
+
primary_key = opts[:primary_key] || (id == false ? nil : "id")
|
85
|
+
primary_key_type = if id == false
|
86
|
+
nil
|
87
|
+
elsif id.nil?
|
88
|
+
"bigint"
|
89
|
+
else
|
90
|
+
id
|
91
|
+
end
|
92
|
+
|
93
|
+
@current_table = {
|
94
|
+
name: name,
|
95
|
+
primary_key: primary_key, # infer the actual value that should be in the database
|
96
|
+
primary_key_type: primary_key_type, # infer the actual value that should be in the database
|
97
|
+
columns: [],
|
98
|
+
indexes: [],
|
99
|
+
rails_schema: { # as reported by the rails schema
|
100
|
+
primary_key: opts[:primary_key],
|
101
|
+
id: id,
|
102
|
+
force: opts[:force]
|
103
|
+
}
|
104
|
+
}
|
105
|
+
# schema[:tables][name] = @current_table
|
106
|
+
schema[:tables] << @current_table
|
107
|
+
|
108
|
+
yield(self) if block_given?
|
109
|
+
end
|
110
|
+
|
111
|
+
def add_field(name, type, **opts)
|
112
|
+
# puts "add_field(#{name}, #{type})"
|
113
|
+
row = { name: name, type: type, **opts }
|
114
|
+
@current_table[:columns] << row
|
115
|
+
|
116
|
+
add_unique_keys(row.keys, type: :columns)
|
117
|
+
add_unique_keys(row.keys, type: :fields, category: type)
|
118
|
+
end
|
119
|
+
|
120
|
+
def add_index(name, fields, **opts)
|
121
|
+
# puts "add_index(#{name})"
|
122
|
+
row = { name: name, fields: fields, **opts }
|
123
|
+
@current_table[:indexes] << row
|
124
|
+
schema[:indexes] << row
|
125
|
+
add_unique_keys(row.keys, type: :indexes)
|
126
|
+
end
|
127
|
+
|
128
|
+
# This method was introduced onto the schema in rails 5
|
129
|
+
def index(fields, **opts)
|
130
|
+
@rails_version = 5
|
131
|
+
name = opts[:name]
|
132
|
+
opts.delete(:name)
|
133
|
+
add_index(name, fields, **opts)
|
134
|
+
end
|
135
|
+
|
136
|
+
def create_view(name, **opts)
|
137
|
+
row = { name: name, **opts }
|
138
|
+
schema[:views] << row
|
139
|
+
add_unique_keys(row.keys, type: :views)
|
140
|
+
end
|
141
|
+
|
142
|
+
def add_foreign_key(left_table, right_table, **opts)
|
143
|
+
# puts "add_foreign_key(#{left_table}, #{right_table})"
|
144
|
+
row = { left: left_table, right: right_table, **opts }
|
145
|
+
schema[:foreign_keys] << row
|
146
|
+
add_unique_keys(row.keys, type: :foreign_keys)
|
147
|
+
end
|
148
|
+
|
149
|
+
def add_unique_keys(keys, type:, category: nil)
|
150
|
+
key = [type, category, keys.join('-')].compact.join('|')
|
151
|
+
return if @unique_keys.key?(key)
|
152
|
+
|
153
|
+
@unique_keys[key] = key
|
154
|
+
schema[:meta][:unique_keys] << { type: type, category: category, key: keys.join(','), keys: keys }
|
155
|
+
end
|
156
|
+
|
157
|
+
def print_unique_keys(type:, category: nil, title: )
|
158
|
+
log.section_heading(title)
|
159
|
+
|
160
|
+
filter_key_infos = schema[:meta][:unique_keys].select { |key_info| key_info[:type] == type && (category.nil? || key_info[:category] == category) }
|
161
|
+
|
162
|
+
# log.kv 'all', filter_key_infos.flat_map { |key_info| key_info[:keys] }.uniq, 50
|
163
|
+
|
164
|
+
filter_key_infos.each do |key_info|
|
165
|
+
log.kv key_info[:key], key_info[:keys], 50
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def integer(name, **opts)
|
170
|
+
add_field(name, :integer, **opts)
|
171
|
+
end
|
172
|
+
|
173
|
+
def bigint(name, **opts)
|
174
|
+
add_field(name, :bigint, **opts)
|
175
|
+
end
|
176
|
+
|
177
|
+
def decimal(name, **opts)
|
178
|
+
add_field(name, :decimal, **opts)
|
179
|
+
end
|
180
|
+
|
181
|
+
def string(name, **opts)
|
182
|
+
add_field(name, :string, **opts)
|
183
|
+
end
|
184
|
+
|
185
|
+
def datetime(name, **opts)
|
186
|
+
add_field(name, :datetime, **opts)
|
187
|
+
end
|
188
|
+
|
189
|
+
def date(name, **opts)
|
190
|
+
add_field(name, :date, **opts)
|
191
|
+
end
|
192
|
+
|
193
|
+
def text(name, **opts)
|
194
|
+
add_field(name, :text, **opts)
|
195
|
+
end
|
196
|
+
|
197
|
+
def boolean(name, **opts)
|
198
|
+
add_field(name, :boolean, **opts)
|
199
|
+
end
|
200
|
+
|
201
|
+
def jsonb(name, **opts)
|
202
|
+
add_field(name, :jsonb, **opts)
|
203
|
+
end
|
204
|
+
|
205
|
+
def hstore(name, **opts)
|
206
|
+
add_field(name, :hstore, **opts)
|
207
|
+
end
|
208
|
+
|
209
|
+
def float(name, **opts)
|
210
|
+
add_field(name, :float, **opts)
|
211
|
+
end
|
212
|
+
|
213
|
+
def sort
|
214
|
+
schema[:indexes].sort_by! { |i| i[:name] }
|
215
|
+
schema[:tables].each { |table| table[:indexes].sort_by! { |i| i[:name] } }
|
216
|
+
|
217
|
+
# Insert a key that represents all unique keys, and then sort
|
218
|
+
unique_keys_per_group = schema[:meta][:unique_keys]
|
219
|
+
.group_by { |key_info| [key_info[:type], key_info[:category]] }
|
220
|
+
.map do |group, values|
|
221
|
+
all_keys = values.flat_map { |key_info| key_info[:keys] }.uniq
|
222
|
+
{
|
223
|
+
type: group[0],
|
224
|
+
category: group[01],
|
225
|
+
key: 'all',
|
226
|
+
keys: all_keys
|
227
|
+
}
|
228
|
+
end
|
229
|
+
|
230
|
+
schema[:meta][:unique_keys].concat(unique_keys_per_group)
|
231
|
+
schema[:meta][:unique_keys].sort! { |a,b| ([a[:type], a[:category],a[:key]] <=> [b[:type], b[:category],b[:key]]) }
|
232
|
+
end
|
233
|
+
end
|
@@ -0,0 +1,301 @@
|
|
1
|
+
# Implement data capture methods for the Rails Action Controller class
|
2
|
+
#
|
3
|
+
# This Shim will intercept any DSL methods and convert their paramaters into a data hash
|
4
|
+
module ActionController
|
5
|
+
extend RubyCodeExtractor::AttachClassInfo
|
6
|
+
|
7
|
+
class Base
|
8
|
+
extend RubyCodeExtractor::BehaviourAccessors
|
9
|
+
|
10
|
+
def self.singleton_class
|
11
|
+
Class.new do
|
12
|
+
def send(*_p, **_o); end
|
13
|
+
end.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.class_info
|
17
|
+
return ActionController.class_info if ActionController.class_info
|
18
|
+
|
19
|
+
ActionController.class_info = {
|
20
|
+
class_name: name
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.after_action(name, **opts)
|
25
|
+
add(:after_action, {
|
26
|
+
name: name,
|
27
|
+
opts: opts
|
28
|
+
})
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.around_action(name, **opts)
|
32
|
+
add(:around_action, {
|
33
|
+
name: name,
|
34
|
+
opts: opts
|
35
|
+
})
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.before_action(name, **opts)
|
39
|
+
add(:before_action, {
|
40
|
+
name: name,
|
41
|
+
opts: opts
|
42
|
+
})
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.prepend_before_action(name, **opts)
|
46
|
+
add(:prepend_before_action, {
|
47
|
+
name: name,
|
48
|
+
opts: opts
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.skip_before_action(name, **opts)
|
53
|
+
add(:skip_before_action, {
|
54
|
+
name: name,
|
55
|
+
opts: opts
|
56
|
+
})
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.before_filter(name, **opts)
|
60
|
+
add(:before_filter, {
|
61
|
+
name: name,
|
62
|
+
opts: opts
|
63
|
+
})
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.skip_before_filter(name, **opts)
|
67
|
+
add(:skip_before_filter, {
|
68
|
+
name: name,
|
69
|
+
opts: opts
|
70
|
+
})
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.layout(name, **opts)
|
74
|
+
set(:layout, {
|
75
|
+
name: name,
|
76
|
+
opts: opts
|
77
|
+
})
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.rescue_from(type)#, &block)
|
81
|
+
# block_source = nil
|
82
|
+
# block_source = lambda_source(block, 'default_scope') if block_given?
|
83
|
+
|
84
|
+
add(:rescue_from, {
|
85
|
+
type: type#,
|
86
|
+
# block: block_source
|
87
|
+
})
|
88
|
+
end
|
89
|
+
|
90
|
+
# TODO: https://apidock.com/rails/ActionController/Helpers/ClassMethods/helper_method (MAYBE DEPRECATED?)
|
91
|
+
def self.helper_method(*names)
|
92
|
+
add(:helper_method, {
|
93
|
+
names: names
|
94
|
+
})
|
95
|
+
end
|
96
|
+
|
97
|
+
# TODO: https://apidock.com/rails/ActionController/Helpers/ClassMethods/helper
|
98
|
+
def self.helper(name)
|
99
|
+
add(:helper, {
|
100
|
+
name: name
|
101
|
+
})
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.http_basic_authenticate_with(**opts)
|
105
|
+
set(:http_basic_authenticate_with, {
|
106
|
+
opts: opts
|
107
|
+
})
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.protect_from_forgery(**opts)
|
111
|
+
set(:protect_from_forgery, {
|
112
|
+
opts: opts
|
113
|
+
})
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
# after_action
|
119
|
+
# after_filter
|
120
|
+
# append_after_action
|
121
|
+
# append_after_filter
|
122
|
+
# append_around_action
|
123
|
+
# append_around_filter
|
124
|
+
# append_before_action
|
125
|
+
# append_before_filter
|
126
|
+
# append_view_path
|
127
|
+
# around_action
|
128
|
+
# around_filter
|
129
|
+
# before_action
|
130
|
+
# before_filter
|
131
|
+
# controller_name
|
132
|
+
# controller_path
|
133
|
+
# helper
|
134
|
+
# helper_attr
|
135
|
+
# helper_method
|
136
|
+
# helpers
|
137
|
+
# helpers_path
|
138
|
+
# hide_action
|
139
|
+
# http_basic_authenticate_with
|
140
|
+
# layout
|
141
|
+
# prepend_after_action
|
142
|
+
# prepend_after_filter
|
143
|
+
# prepend_around_action
|
144
|
+
# prepend_around_filter
|
145
|
+
# prepend_before_action
|
146
|
+
# prepend_before_filter
|
147
|
+
# prepend_view_path
|
148
|
+
# protect_from_forgery
|
149
|
+
# protected_instance_variables
|
150
|
+
# rescue_from
|
151
|
+
# reset_callbacks
|
152
|
+
# skip_action_callback
|
153
|
+
# skip_after_action
|
154
|
+
# skip_after_filter
|
155
|
+
# skip_around_action
|
156
|
+
# skip_around_filter
|
157
|
+
# skip_before_action
|
158
|
+
# skip_before_filter
|
159
|
+
# skip_callback
|
160
|
+
# skip_filter
|
161
|
+
|
162
|
+
# METHOD LIST - Just from running self.class.methods - Object.methods on a running controller
|
163
|
+
# action
|
164
|
+
# action_methods
|
165
|
+
# add_flash_types
|
166
|
+
# after_action
|
167
|
+
# after_filter
|
168
|
+
# all_helpers_from_path
|
169
|
+
# allow_forgery_protection
|
170
|
+
# allow_forgery_protection=
|
171
|
+
# append_after_action
|
172
|
+
# append_after_filter
|
173
|
+
# append_around_action
|
174
|
+
# append_around_filter
|
175
|
+
# append_before_action
|
176
|
+
# append_before_filter
|
177
|
+
# append_view_path
|
178
|
+
# around_action
|
179
|
+
# around_filter
|
180
|
+
# asset_host
|
181
|
+
# asset_host=
|
182
|
+
# assets_dir
|
183
|
+
# assets_dir=
|
184
|
+
# before_action
|
185
|
+
# before_filter
|
186
|
+
# cache_store
|
187
|
+
# cache_store=
|
188
|
+
# call
|
189
|
+
# clear_action_methods!
|
190
|
+
# clear_helpers
|
191
|
+
# clear_respond_to
|
192
|
+
# config
|
193
|
+
# config_accessor
|
194
|
+
# configure
|
195
|
+
# controller_name
|
196
|
+
# controller_path
|
197
|
+
# default_asset_host_protocol
|
198
|
+
# default_asset_host_protocol=
|
199
|
+
# default_static_extension
|
200
|
+
# default_static_extension=
|
201
|
+
# default_url_options
|
202
|
+
# default_url_options=
|
203
|
+
# default_url_options?
|
204
|
+
# define_callbacks
|
205
|
+
# devise_group
|
206
|
+
# direct_descendants
|
207
|
+
# etag
|
208
|
+
# etag_with_template_digest
|
209
|
+
# etag_with_template_digest=
|
210
|
+
# etag_with_template_digest?
|
211
|
+
# etaggers
|
212
|
+
# etaggers=
|
213
|
+
# etaggers?
|
214
|
+
# force_ssl
|
215
|
+
# forgery_protection_strategy
|
216
|
+
# forgery_protection_strategy=
|
217
|
+
# get_callbacks
|
218
|
+
# helper
|
219
|
+
# helper_attr
|
220
|
+
# helper_method
|
221
|
+
# helpers
|
222
|
+
# helpers_path
|
223
|
+
# helpers_path=
|
224
|
+
# helpers_path?
|
225
|
+
# hidden_actions
|
226
|
+
# hidden_actions=
|
227
|
+
# hidden_actions?
|
228
|
+
# hide_action
|
229
|
+
# http_basic_authenticate_with
|
230
|
+
# include_all_helpers
|
231
|
+
# include_all_helpers=
|
232
|
+
# include_all_helpers?
|
233
|
+
# inherited
|
234
|
+
# internal_methods
|
235
|
+
# javascripts_dir
|
236
|
+
# javascripts_dir=
|
237
|
+
# layout
|
238
|
+
# log_process_action
|
239
|
+
# log_warning_on_csrf_failure
|
240
|
+
# log_warning_on_csrf_failure=
|
241
|
+
# logger
|
242
|
+
# logger=
|
243
|
+
# method_added
|
244
|
+
# middleware
|
245
|
+
# middleware_stack
|
246
|
+
# middleware_stack=
|
247
|
+
# middleware_stack?
|
248
|
+
# mimes_for_respond_to
|
249
|
+
# mimes_for_respond_to=
|
250
|
+
# mimes_for_respond_to?
|
251
|
+
# modules_for_helpers
|
252
|
+
# normalize_callback_params
|
253
|
+
# perform_caching
|
254
|
+
# perform_caching=
|
255
|
+
# prepend_after_action
|
256
|
+
# prepend_after_filter
|
257
|
+
# prepend_around_action
|
258
|
+
# prepend_around_filter
|
259
|
+
# prepend_before_action
|
260
|
+
# prepend_before_filter
|
261
|
+
# prepend_view_path
|
262
|
+
# protect_from_forgery
|
263
|
+
# protected_instance_variables
|
264
|
+
# relative_url_root
|
265
|
+
# relative_url_root=
|
266
|
+
# request_forgery_protection_token
|
267
|
+
# request_forgery_protection_token=
|
268
|
+
# rescue_from
|
269
|
+
# rescue_handlers
|
270
|
+
# rescue_handlers=
|
271
|
+
# rescue_handlers?
|
272
|
+
# reset_callbacks
|
273
|
+
# respond_to
|
274
|
+
# responder
|
275
|
+
# responder=
|
276
|
+
# responder?
|
277
|
+
# responders
|
278
|
+
# set_callback
|
279
|
+
# set_callbacks
|
280
|
+
# skip_action_callback
|
281
|
+
# skip_after_action
|
282
|
+
# skip_after_filter
|
283
|
+
# skip_around_action
|
284
|
+
# skip_around_filter
|
285
|
+
# skip_before_action
|
286
|
+
# skip_before_filter
|
287
|
+
# skip_callback
|
288
|
+
# skip_filter
|
289
|
+
# stylesheets_dir
|
290
|
+
# stylesheets_dir=
|
291
|
+
# supports_path?
|
292
|
+
# use
|
293
|
+
# use_renderer
|
294
|
+
# use_renderers
|
295
|
+
# view_cache_dependency
|
296
|
+
# view_context_class
|
297
|
+
# view_paths
|
298
|
+
# view_paths=
|
299
|
+
# visible_action?
|
300
|
+
# without_modules
|
301
|
+
# wrap_parameters
|
@@ -1,13 +1,9 @@
|
|
1
1
|
module ActiveRecord
|
2
|
-
|
3
|
-
@current_class ||= nil
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.current_class=(value)
|
7
|
-
@current_class = value
|
8
|
-
end
|
2
|
+
extend RubyCodeExtractor::AttachClassInfo
|
9
3
|
|
10
4
|
class Base
|
5
|
+
extend RubyCodeExtractor::BehaviourAccessors
|
6
|
+
|
11
7
|
def self.singleton_class
|
12
8
|
Class.new do
|
13
9
|
def send(*_p, **_o); end
|
@@ -15,42 +11,22 @@ module ActiveRecord
|
|
15
11
|
end
|
16
12
|
|
17
13
|
def self.class_info
|
18
|
-
return ActiveRecord.
|
14
|
+
return ActiveRecord.class_info if ActiveRecord.class_info
|
19
15
|
|
20
|
-
ActiveRecord.
|
16
|
+
ActiveRecord.class_info = {
|
21
17
|
class_name: name
|
22
18
|
}
|
23
19
|
end
|
24
20
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.add(key, value)
|
31
|
-
class_info[key] = class_info[key] || []
|
32
|
-
if value.is_a?(Array)
|
33
|
-
class_info[key] = class_info[key] + value
|
34
|
-
else
|
35
|
-
class_info[key] << value
|
36
|
-
end
|
37
|
-
end
|
21
|
+
# -------------------------
|
22
|
+
# Intercept methods
|
23
|
+
# -------------------------
|
38
24
|
|
39
|
-
def self.
|
40
|
-
class_info[:custom] = {} unless class_info[:custom]
|
41
|
-
class_info[:custom][key] = class_info[:custom][key] || {}
|
42
|
-
class_info[:custom][key] = value
|
43
|
-
end
|
25
|
+
def self.clear_active_connections!; end
|
44
26
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
if value.is_a?(Array)
|
49
|
-
class_info[:custom][key] = class_info[:custom][key] + value
|
50
|
-
else
|
51
|
-
class_info[:custom][key] << value
|
52
|
-
end
|
53
|
-
end
|
27
|
+
# -------------------------
|
28
|
+
# Behaviour storage methods
|
29
|
+
# -------------------------
|
54
30
|
|
55
31
|
# examples:
|
56
32
|
# enum status: { active: 0, archived: 1 }
|
@@ -133,11 +109,15 @@ module ActiveRecord
|
|
133
109
|
def self.belongs_to(name, on_the_lamb = nil, **opts)
|
134
110
|
lamb_source = lambda_source(on_the_lamb, "belongs_to :#{name},")
|
135
111
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
112
|
+
value = {
|
113
|
+
name: name,
|
114
|
+
opts: opts,
|
115
|
+
block: lamb_source
|
116
|
+
}
|
117
|
+
|
118
|
+
value[:opts][:foreign_key] = "#{name}_id" unless value[:opts][:foreign_key]
|
119
|
+
|
120
|
+
add(:belongs_to, value)
|
141
121
|
end
|
142
122
|
|
143
123
|
def self.has_many(name, on_the_lamb = nil, **opts)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module RubyCodeExtractor
|
2
|
+
# Class Info hash that contains the class name and any other key/values
|
3
|
+
# that could be useful when capturing Class information.
|
4
|
+
module AttachClassInfo
|
5
|
+
def class_info
|
6
|
+
@class_info ||= nil
|
7
|
+
end
|
8
|
+
|
9
|
+
def class_info=(value)
|
10
|
+
@class_info = value
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module RubyCodeExtractor
|
2
|
+
# When you intercept a method call, you can persist the captured paramaters
|
3
|
+
# into a Hash, the Hash Key should be the method name and the value should
|
4
|
+
# be a Hash with captured values.
|
5
|
+
#
|
6
|
+
# Use set/add for standard Rails DSL methods
|
7
|
+
# Use custom_set/custom_add for non standard or 3rd party GEM methods
|
8
|
+
module BehaviourAccessors
|
9
|
+
def set(key, value)
|
10
|
+
class_info[key] = class_info[key] || {}
|
11
|
+
class_info[key] = value
|
12
|
+
end
|
13
|
+
|
14
|
+
def add(key, value)
|
15
|
+
class_info[key] = class_info[key] || []
|
16
|
+
if value.is_a?(Array)
|
17
|
+
class_info[key] = class_info[key] + value
|
18
|
+
else
|
19
|
+
class_info[key] << value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def custom_set(key, value = {})
|
24
|
+
class_info[:custom] = {} unless class_info[:custom]
|
25
|
+
class_info[:custom][key] = class_info[:custom][key] || {}
|
26
|
+
class_info[:custom][key] = value
|
27
|
+
end
|
28
|
+
|
29
|
+
def custom_add(key, value)
|
30
|
+
class_info[:custom] = {} unless class_info[:custom]
|
31
|
+
class_info[:custom][key] = class_info[:custom][key] || []
|
32
|
+
if value.is_a?(Array)
|
33
|
+
class_info[:custom][key] = class_info[:custom][key] + value
|
34
|
+
else
|
35
|
+
class_info[:custom][key] << value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|