active_mocker 1.8.4 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/README.md +4 -2
- data/lib/active_mocker.rb +9 -25
- data/lib/active_mocker/config.rb +26 -46
- data/lib/active_mocker/generate.rb +115 -110
- data/lib/active_mocker/loaded_mocks.rb +76 -65
- data/lib/active_mocker/mock/base.rb +283 -287
- data/lib/active_mocker/mock/has_many.rb +2 -0
- data/lib/active_mocker/mock_creator.rb +262 -0
- data/lib/active_mocker/mock_template.erb +9 -186
- data/lib/active_mocker/mock_template/_associations.erb +82 -0
- data/lib/active_mocker/mock_template/_attributes.erb +11 -0
- data/lib/active_mocker/mock_template/_class_methods.erb +41 -0
- data/lib/active_mocker/mock_template/_defined_methods.erb +10 -0
- data/lib/active_mocker/mock_template/_modules_constants.erb +10 -0
- data/lib/active_mocker/mock_template/_scopes.erb +23 -0
- data/lib/active_mocker/null_progress.rb +9 -0
- data/lib/active_mocker/output_capture.rb +32 -0
- data/lib/active_mocker/parent_class.rb +64 -0
- data/lib/active_mocker/progress.rb +13 -0
- data/lib/active_mocker/public_methods.rb +15 -23
- data/lib/active_mocker/rspec.rb +16 -0
- data/lib/active_mocker/rspec_helper.rb +10 -8
- data/lib/active_mocker/task.rake +6 -1
- data/lib/active_mocker/template_creator.rb +22 -0
- data/lib/active_mocker/version.rb +1 -1
- metadata +43 -103
- data/lib/active_mocker/active_record.rb +0 -74
- data/lib/active_mocker/active_record/field.rb +0 -39
- data/lib/active_mocker/active_record/relationships.rb +0 -110
- data/lib/active_mocker/active_record/schema.rb +0 -81
- data/lib/active_mocker/active_record/scope.rb +0 -22
- data/lib/active_mocker/active_record/table.rb +0 -26
- data/lib/active_mocker/active_record/unknown_class_method.rb +0 -17
- data/lib/active_mocker/active_record/unknown_module.rb +0 -30
- data/lib/active_mocker/db_to_ruby_type.rb +0 -29
- data/lib/active_mocker/file_reader.rb +0 -11
- data/lib/active_mocker/model_reader.rb +0 -191
- data/lib/active_mocker/model_schema.rb +0 -285
- data/lib/active_mocker/model_schema/assemble.rb +0 -220
- data/lib/active_mocker/reparameterize.rb +0 -41
- data/lib/active_mocker/ruby_parse.rb +0 -68
- data/lib/active_mocker/schema_reader.rb +0 -30
- data/lib/active_mocker/string_reader.rb +0 -18
@@ -1,81 +0,0 @@
|
|
1
|
-
module ActiveMocker
|
2
|
-
module ActiveRecord
|
3
|
-
|
4
|
-
class Schema
|
5
|
-
|
6
|
-
def self.define(options, &block)
|
7
|
-
version = options[:version]
|
8
|
-
search_result = search_cache(@table_search)
|
9
|
-
search_result unless search_result.nil?
|
10
|
-
schema = parse
|
11
|
-
schema.instance_eval(&block)
|
12
|
-
schema
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.parse
|
16
|
-
SchemaParser.new(@table_search)
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.add_to_cache(table)
|
20
|
-
@tables_cache ||= []
|
21
|
-
@tables_cache << table unless table.nil?
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.search_cache(table_name)
|
25
|
-
@tables_cache ||= []
|
26
|
-
@tables_cache.find do |h|
|
27
|
-
h.name == table_name
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.clear_cache
|
32
|
-
@tables_cache = []
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.search(table_name)
|
36
|
-
@table_search = table_name
|
37
|
-
search_cache(table_name)
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
class SchemaParser
|
43
|
-
|
44
|
-
attr_reader :tables, :table_search
|
45
|
-
|
46
|
-
def initialize(table_search)
|
47
|
-
@table_search = table_search
|
48
|
-
@tables = []
|
49
|
-
end
|
50
|
-
|
51
|
-
def create_table(name, options={}, &block)
|
52
|
-
tables << Table.new(name, options[:id], CreateTable.new.instance_eval(&block))
|
53
|
-
end
|
54
|
-
|
55
|
-
def method_missing(meth, *args)
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
class CreateTable
|
62
|
-
|
63
|
-
attr_reader :fields
|
64
|
-
|
65
|
-
def initialize
|
66
|
-
@fields = []
|
67
|
-
end
|
68
|
-
|
69
|
-
def method_missing(meth, *args)
|
70
|
-
base_field meth, args
|
71
|
-
end
|
72
|
-
|
73
|
-
def base_field(type, args)
|
74
|
-
fields << ActiveRecord::Field.new(args.shift, type, args)
|
75
|
-
end
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
end
|
80
|
-
|
81
|
-
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module ActiveMocker
|
2
|
-
module ActiveRecord
|
3
|
-
# @api private
|
4
|
-
class Table
|
5
|
-
|
6
|
-
attr_reader :name, :fields
|
7
|
-
|
8
|
-
def initialize(name, id=true, fields=[])
|
9
|
-
@name = name
|
10
|
-
@fields = fields
|
11
|
-
fields.unshift Field.new('id', :integer, [{primary_key: true}]) if id.nil?
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_h
|
15
|
-
{name: name, fields: fields.to_h}
|
16
|
-
end
|
17
|
-
|
18
|
-
alias_method :to_hash, :to_h
|
19
|
-
|
20
|
-
def column_names
|
21
|
-
fields.map { |f| f.name }
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module ActiveMocker
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
|
5
|
-
module UnknownClassMethod
|
6
|
-
|
7
|
-
def method_missing(meth, *args)
|
8
|
-
Config.logger.warn "#{meth} called from class #{self.name.demodulize}" +
|
9
|
-
" is unknown and will not be available in mock.\n #{caller.first}"
|
10
|
-
end
|
11
|
-
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
17
|
-
|
@@ -1,30 +0,0 @@
|
|
1
|
-
module ActiveMocker
|
2
|
-
|
3
|
-
module ActiveRecord
|
4
|
-
|
5
|
-
module UnknownModule
|
6
|
-
|
7
|
-
def include(_module)
|
8
|
-
try_and_log('include', _module, caller)
|
9
|
-
end
|
10
|
-
|
11
|
-
def extend(_module)
|
12
|
-
try_and_log('extend', _module, caller)
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def try_and_log(method, name, _caller)
|
18
|
-
begin
|
19
|
-
super _module
|
20
|
-
rescue => e
|
21
|
-
Config.logger.debug "#{method} module #{name} from class #{self.name}.\n #{_caller}\n #{e}"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
|
30
|
-
end
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module ActiveMocker
|
2
|
-
# @api private
|
3
|
-
class DBToRubyType
|
4
|
-
|
5
|
-
def self.call(type)
|
6
|
-
case type
|
7
|
-
when :integer
|
8
|
-
Fixnum
|
9
|
-
when :float
|
10
|
-
Float
|
11
|
-
when :decimal
|
12
|
-
BigDecimal
|
13
|
-
when :timestamp, :time
|
14
|
-
Time
|
15
|
-
when :datetime
|
16
|
-
DateTime
|
17
|
-
when :date
|
18
|
-
Date
|
19
|
-
when :text, :string, :binary
|
20
|
-
String
|
21
|
-
when :boolean
|
22
|
-
Axiom::Types::Boolean
|
23
|
-
when :hstore
|
24
|
-
Hash
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
@@ -1,191 +0,0 @@
|
|
1
|
-
module ActiveMocker
|
2
|
-
# @api private
|
3
|
-
|
4
|
-
class ModelReader
|
5
|
-
|
6
|
-
attr_reader :model_name
|
7
|
-
|
8
|
-
def parse(model_name)
|
9
|
-
@model_name = model_name
|
10
|
-
return ParsedProperties.new(klass, parent_class, model_name) if klass
|
11
|
-
false
|
12
|
-
end
|
13
|
-
|
14
|
-
def klass
|
15
|
-
@klass ||= eval_file(sandbox_model, file_path)
|
16
|
-
end
|
17
|
-
|
18
|
-
def sandbox_model
|
19
|
-
source = RubyParse.new(read_file)
|
20
|
-
has_no_parent_class!(source)
|
21
|
-
get_non_active_record_parent_class(source)
|
22
|
-
source.modify_parent_class('ActiveMocker::ActiveRecord::Base')
|
23
|
-
end
|
24
|
-
|
25
|
-
def get_non_active_record_parent_class(source)
|
26
|
-
@parent_class = source.parent_class_name unless Config.model_base_classes.include?(source.parent_class_name)
|
27
|
-
end
|
28
|
-
|
29
|
-
def has_no_parent_class!(source)
|
30
|
-
raise ModelLoadError::HasNoParentClass.new("#{model_name}") unless source.has_parent_class?
|
31
|
-
end
|
32
|
-
|
33
|
-
def module_namespace
|
34
|
-
@module ||= Module.new
|
35
|
-
end
|
36
|
-
|
37
|
-
def eval_file(string, file_path)
|
38
|
-
failure = false
|
39
|
-
begin
|
40
|
-
module_namespace.module_eval(string, file_path)
|
41
|
-
_klass = module_namespace.const_get(module_namespace.constants.last)
|
42
|
-
rescue SyntaxError => e
|
43
|
-
log_loading_error(e, true)
|
44
|
-
failure = true
|
45
|
-
rescue Exception => e
|
46
|
-
log_loading_error(e, false)
|
47
|
-
failure = true
|
48
|
-
end
|
49
|
-
return false if failure
|
50
|
-
_klass
|
51
|
-
end
|
52
|
-
|
53
|
-
def log_loading_error(msg, print_to_stdout=false)
|
54
|
-
main = "Error loading Model: #{model_name} \n\t#{msg}\n"
|
55
|
-
file = "\t#{file_path}\n"
|
56
|
-
stack_trace = msg.backtrace_locations.map{|e| "\t#{e}"}.join("\n")
|
57
|
-
str = main + file + stack_trace
|
58
|
-
Config.logger.error str
|
59
|
-
print str if print_to_stdout
|
60
|
-
end
|
61
|
-
|
62
|
-
def parent_class
|
63
|
-
@parent_class
|
64
|
-
end
|
65
|
-
|
66
|
-
def read_file(m_name=model_name)
|
67
|
-
Config.file_reader.read(file_path(m_name))
|
68
|
-
end
|
69
|
-
|
70
|
-
def file_path(m_name=model_name)
|
71
|
-
"#{Config.model_dir}/#{m_name}.rb"
|
72
|
-
end
|
73
|
-
|
74
|
-
class ParsedProperties
|
75
|
-
|
76
|
-
attr_reader :klass, :parent_class, :model_name
|
77
|
-
|
78
|
-
def initialize(klass, parent_class, model_name)
|
79
|
-
@klass = klass
|
80
|
-
@parent_class = parent_class
|
81
|
-
@model_name = model_name
|
82
|
-
end
|
83
|
-
|
84
|
-
def rails_version
|
85
|
-
begin
|
86
|
-
@rails_version ||= model_name.camelize.constantize
|
87
|
-
rescue
|
88
|
-
raise ModelLoadError::LoadingModelInRails.new($!, model_name)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def abstract_class
|
93
|
-
rails_version.try(:abstract_class)
|
94
|
-
end
|
95
|
-
|
96
|
-
def select_only_current_class(type)
|
97
|
-
rails_version.reflect_on_all_associations(type).select do |a|
|
98
|
-
klass.relationships.send(type).map(&:name).include?(a.name)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
def belongs_to
|
103
|
-
select_only_current_class(:belongs_to)
|
104
|
-
end
|
105
|
-
|
106
|
-
def has_one
|
107
|
-
select_only_current_class(:has_one)
|
108
|
-
end
|
109
|
-
|
110
|
-
def has_and_belongs_to_many
|
111
|
-
select_only_current_class(:has_and_belongs_to_many)
|
112
|
-
end
|
113
|
-
|
114
|
-
def has_many
|
115
|
-
select_only_current_class(:has_many)
|
116
|
-
end
|
117
|
-
|
118
|
-
def table_name
|
119
|
-
return rails_version.try(:table_name) if rails_version.try(:superclass).try(:name) == 'ActiveRecord::Base'
|
120
|
-
return nil if rails_version.superclass.try(:table_name) == rails_version.try(:table_name)
|
121
|
-
rails_version.try(:table_name)
|
122
|
-
end
|
123
|
-
|
124
|
-
def primary_key
|
125
|
-
rails_version.primary_key
|
126
|
-
end
|
127
|
-
|
128
|
-
def class_methods
|
129
|
-
klass.methods(false)
|
130
|
-
end
|
131
|
-
|
132
|
-
def scopes
|
133
|
-
klass.get_named_scopes
|
134
|
-
end
|
135
|
-
|
136
|
-
def scopes_with_arguments
|
137
|
-
scopes.map do |name, proc|
|
138
|
-
{name => proc.parameters, :proc => proc}
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
def class_methods_with_arguments
|
143
|
-
class_methods.map do |m|
|
144
|
-
{m => klass.method(m).parameters}
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
def instance_methods_with_arguments
|
149
|
-
instance_methods.map do |m|
|
150
|
-
{m => klass.instance_method(m).parameters}
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def instance_methods
|
155
|
-
methods = klass.public_instance_methods(false)
|
156
|
-
methods << klass.superclass.public_instance_methods(false) if klass.superclass != ActiveRecord::Base
|
157
|
-
methods.flatten
|
158
|
-
end
|
159
|
-
|
160
|
-
def constants
|
161
|
-
const = {}
|
162
|
-
klass.constants.each { |c| const[c] = klass.const_get(c) }
|
163
|
-
const = const.reject do |c, v|
|
164
|
-
v.class == Module || v.class == Class
|
165
|
-
end
|
166
|
-
const
|
167
|
-
end
|
168
|
-
|
169
|
-
def modules
|
170
|
-
{included: process_module_names(klass._included),
|
171
|
-
extended: process_module_names(klass._extended)}
|
172
|
-
end
|
173
|
-
|
174
|
-
def process_module_names(names)
|
175
|
-
names.reject { |m| /#{klass.inspect}/ =~ m.name }.map(&:inspect)
|
176
|
-
end
|
177
|
-
|
178
|
-
end
|
179
|
-
|
180
|
-
end
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
# Hack for CarrierWave error - undefined method `validate_integrity'
|
185
|
-
module ActiveRecord
|
186
|
-
class Base
|
187
|
-
def self.mount_uploader(*args)
|
188
|
-
super unless ActiveMocker::Config.build_in_progress
|
189
|
-
end
|
190
|
-
end
|
191
|
-
end
|
@@ -1,285 +0,0 @@
|
|
1
|
-
module ActiveMocker
|
2
|
-
# @api private
|
3
|
-
module LoggerToJson
|
4
|
-
|
5
|
-
def initialize(*args)
|
6
|
-
super(args)
|
7
|
-
UnitLogger.unit.info "#{caller_locations[1]}\n"
|
8
|
-
obj = JSON.parse(self.to_hash.to_json)
|
9
|
-
UnitLogger.unit.info "#{self.class.name}: #{JSON.pretty_unparse(obj)}\n"
|
10
|
-
puts "#{self.class.name}: #{JSON.pretty_unparse(obj)}\n"
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
# @api private
|
16
|
-
class ModelSchemaCollection
|
17
|
-
|
18
|
-
include Enumerable
|
19
|
-
|
20
|
-
attr_accessor :collection
|
21
|
-
|
22
|
-
def initialize(collection)
|
23
|
-
@collection = collection
|
24
|
-
end
|
25
|
-
|
26
|
-
def each(&block)
|
27
|
-
collection.each do |item|
|
28
|
-
block.call(item)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def find_by(options={})
|
33
|
-
collection.select{|c| c.send(options.keys.first) == options.values.first}.first
|
34
|
-
end
|
35
|
-
|
36
|
-
def find_by_in_relationships(options={})
|
37
|
-
result = nil
|
38
|
-
collection.each do |item|
|
39
|
-
result = item.relationships.select do |attr|
|
40
|
-
attr.send(options.keys.first) == options.values.first
|
41
|
-
end
|
42
|
-
end
|
43
|
-
result
|
44
|
-
end
|
45
|
-
|
46
|
-
|
47
|
-
def [](val)
|
48
|
-
collection[val]
|
49
|
-
end
|
50
|
-
|
51
|
-
end
|
52
|
-
|
53
|
-
class ModelSchema < AttrPermit
|
54
|
-
attr_permit :class_name,
|
55
|
-
:table_name,
|
56
|
-
:attributes,
|
57
|
-
:relationships,
|
58
|
-
:_methods,
|
59
|
-
:modules,
|
60
|
-
:constants,
|
61
|
-
:parent_class,
|
62
|
-
:abstract_class
|
63
|
-
|
64
|
-
def abstract_class
|
65
|
-
!!call_method(:abstract_class)
|
66
|
-
end
|
67
|
-
|
68
|
-
def constants
|
69
|
-
call_method(:constants) || []
|
70
|
-
end
|
71
|
-
|
72
|
-
def has_many
|
73
|
-
relation_find(:type, :has_many)
|
74
|
-
end
|
75
|
-
|
76
|
-
def has_one
|
77
|
-
relation_find(:type, :has_one)
|
78
|
-
end
|
79
|
-
|
80
|
-
def belongs_to
|
81
|
-
relation_find(:type, :belongs_to)
|
82
|
-
end
|
83
|
-
|
84
|
-
def has_and_belongs_to_many
|
85
|
-
relation_find(:type, :has_and_belongs_to_many)
|
86
|
-
end
|
87
|
-
|
88
|
-
def belongs_to_foreign_key(foreign_key)
|
89
|
-
belongs_to.select { |r| r.foreign_key.to_sym == foreign_key.to_sym }.first
|
90
|
-
end
|
91
|
-
|
92
|
-
def relation_find(key, value)
|
93
|
-
relationships.select { |r| r.send(key).to_sym == value }
|
94
|
-
end
|
95
|
-
|
96
|
-
def instance_methods
|
97
|
-
method_find(:instance)
|
98
|
-
end
|
99
|
-
|
100
|
-
def class_methods
|
101
|
-
method_find(:class)
|
102
|
-
end
|
103
|
-
|
104
|
-
def scope_methods
|
105
|
-
method_find(:scope)
|
106
|
-
end
|
107
|
-
|
108
|
-
def methods
|
109
|
-
call_method(:_methods) || []
|
110
|
-
end
|
111
|
-
|
112
|
-
def method_find(type)
|
113
|
-
return [] if methods.nil?
|
114
|
-
methods.select { |r| r.type.to_sym == type }
|
115
|
-
end
|
116
|
-
|
117
|
-
def attribute_names
|
118
|
-
attributes.map(&:name)
|
119
|
-
end
|
120
|
-
|
121
|
-
def types_hash
|
122
|
-
types = {}
|
123
|
-
attributes.each do |attr|
|
124
|
-
types[attr.name] = "#{attr.ruby_type}"
|
125
|
-
end
|
126
|
-
|
127
|
-
type_array = types.map do |name, type|
|
128
|
-
"#{name}: #{type}"
|
129
|
-
end
|
130
|
-
'{ ' + type_array.join(', ') + ' }'
|
131
|
-
end
|
132
|
-
|
133
|
-
def attributes_with_defaults
|
134
|
-
hash = {}
|
135
|
-
attributes.each do |attr|
|
136
|
-
hash[attr.name] = attr.default_value
|
137
|
-
end
|
138
|
-
hash
|
139
|
-
end
|
140
|
-
|
141
|
-
def associations
|
142
|
-
hash = {}
|
143
|
-
relationships.each do |r|
|
144
|
-
hash[r.name] = nil
|
145
|
-
end
|
146
|
-
hash
|
147
|
-
end
|
148
|
-
|
149
|
-
def associations_by_class
|
150
|
-
hash = {}
|
151
|
-
relationships.each do |r|
|
152
|
-
hash[r.class_name] ||= {}
|
153
|
-
hash[r.class_name][r.type] ||= []
|
154
|
-
hash[r.class_name][r.type] << r.name
|
155
|
-
end
|
156
|
-
hash
|
157
|
-
end
|
158
|
-
|
159
|
-
def mock_name(klass_name)
|
160
|
-
klass_name + "Mock"
|
161
|
-
end
|
162
|
-
|
163
|
-
def mockable_class_methods
|
164
|
-
class_methods.map(&:name).each_with_object({}) { |val, hash| hash[val] = nil }
|
165
|
-
end
|
166
|
-
|
167
|
-
def mockable_instance_methods
|
168
|
-
instance_methods.map(&:name).each_with_object({}) { |val, hash| hash[val] = nil }
|
169
|
-
end
|
170
|
-
|
171
|
-
def parent_class
|
172
|
-
return mock_name(call_method(:parent_class)) if call_method(:parent_class).present?
|
173
|
-
'ActiveMocker::Mock::Base'
|
174
|
-
end
|
175
|
-
|
176
|
-
def is_child_class?
|
177
|
-
call_method(:parent_class).present?
|
178
|
-
end
|
179
|
-
|
180
|
-
def render(template, mock_append_name)
|
181
|
-
@mock_append_name = mock_append_name
|
182
|
-
ERB.new(template, nil, '-').result(binding)
|
183
|
-
end
|
184
|
-
|
185
|
-
private :relation_find
|
186
|
-
|
187
|
-
def primary_key
|
188
|
-
key_attribute = attributes.select { |attr| attr.primary_key }.first
|
189
|
-
return key_attribute if key_attribute
|
190
|
-
default_primary_key
|
191
|
-
end
|
192
|
-
|
193
|
-
def default_primary_key
|
194
|
-
default_id = Attributes.new(name: 'id', primary_key: true, type: :integer)
|
195
|
-
call_method(:attributes).unshift(default_id)
|
196
|
-
default_id
|
197
|
-
end
|
198
|
-
|
199
|
-
class Attributes
|
200
|
-
|
201
|
-
attr_reader :name, :type, :precision, :scale, :default_value, :primary_key
|
202
|
-
attr_writer :primary_key
|
203
|
-
def initialize(name:,
|
204
|
-
type:,
|
205
|
-
precision: nil,
|
206
|
-
scale: nil,
|
207
|
-
default_value: nil,
|
208
|
-
primary_key: nil
|
209
|
-
)
|
210
|
-
@name = name
|
211
|
-
@type = type
|
212
|
-
@precision = precision unless precision.nil?
|
213
|
-
@scale = scale unless scale.nil?
|
214
|
-
@default_value = default_value unless default_value.nil?
|
215
|
-
@primary_key = primary_key unless primary_key.nil?
|
216
|
-
end
|
217
|
-
|
218
|
-
def ruby_type
|
219
|
-
ActiveMocker::DBToRubyType.call(type)
|
220
|
-
end
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
class Relationships
|
225
|
-
|
226
|
-
attr_reader :name, :class_name, :type, :through, :source, :foreign_key, :join_table
|
227
|
-
|
228
|
-
def initialize(name:,
|
229
|
-
class_name:,
|
230
|
-
type:,
|
231
|
-
through:,
|
232
|
-
source:,
|
233
|
-
foreign_key:,
|
234
|
-
join_table:
|
235
|
-
)
|
236
|
-
@name = name
|
237
|
-
@class_name = class_name
|
238
|
-
@type = type
|
239
|
-
@through = through
|
240
|
-
@source = source
|
241
|
-
@foreign_key = foreign_key
|
242
|
-
@join_table = join_table
|
243
|
-
end
|
244
|
-
|
245
|
-
end
|
246
|
-
|
247
|
-
class Methods < AttrPermit
|
248
|
-
|
249
|
-
attr_permit :name, :arguments, :type
|
250
|
-
|
251
|
-
def arguments
|
252
|
-
Arguments.new(call_method(:arguments))
|
253
|
-
end
|
254
|
-
|
255
|
-
class Arguments
|
256
|
-
|
257
|
-
attr_reader :arguments
|
258
|
-
|
259
|
-
def initialize(arguments)
|
260
|
-
@arguments = arguments
|
261
|
-
end
|
262
|
-
|
263
|
-
def to_hash
|
264
|
-
@arguments
|
265
|
-
end
|
266
|
-
|
267
|
-
def empty?
|
268
|
-
@arguments.empty?
|
269
|
-
end
|
270
|
-
|
271
|
-
def to_s
|
272
|
-
Reparameterize.method_arguments(arguments)
|
273
|
-
end
|
274
|
-
|
275
|
-
def passable
|
276
|
-
Reparameterize.method_parameters(arguments)
|
277
|
-
end
|
278
|
-
|
279
|
-
end
|
280
|
-
|
281
|
-
end
|
282
|
-
|
283
|
-
end
|
284
|
-
|
285
|
-
end
|