Class: RealDataTests::Configuration
- Inherits:
-
Object
- Object
- RealDataTests::Configuration
show all
- Defined in:
- lib/real_data_tests/configuration.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Configuration.
6
7
8
9
10
11
|
# File 'lib/real_data_tests/configuration.rb', line 6
def initialize
@dump_path = 'spec/fixtures/real_data_dumps'
@presets = {}
@current_preset = nil
create_preset(:default)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/real_data_tests/configuration.rb', line 48
def method_missing(method_name, *args, &block)
if @current_preset.respond_to?(method_name)
@current_preset.public_send(method_name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#current_preset ⇒ Object
Returns the value of attribute current_preset.
3
4
5
|
# File 'lib/real_data_tests/configuration.rb', line 3
def current_preset
@current_preset
end
|
#dump_path ⇒ Object
Returns the value of attribute dump_path.
3
4
5
|
# File 'lib/real_data_tests/configuration.rb', line 3
def dump_path
@dump_path
end
|
#presets ⇒ Object
Returns the value of attribute presets.
4
5
6
|
# File 'lib/real_data_tests/configuration.rb', line 4
def presets
@presets
end
|
Instance Method Details
#get_association_limit(record_class, association_name) ⇒ Object
18
19
20
|
# File 'lib/real_data_tests/configuration.rb', line 18
def get_association_limit(record_class, association_name)
current_preset&.get_association_limit(record_class, association_name)
end
|
#preset(name) {|@current_preset| ... } ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/real_data_tests/configuration.rb', line 26
def preset(name, &block)
name = name.to_sym
@presets[name] = PresetConfig.new
@current_preset = @presets[name]
yield(@current_preset) if block_given?
@current_preset = @presets[:default]
end
|
#prevent_reciprocal?(record_class, association_name) ⇒ Boolean
22
23
24
|
# File 'lib/real_data_tests/configuration.rb', line 22
def prevent_reciprocal?(record_class, association_name)
current_preset&.prevent_reciprocal?(record_class, association_name)
end
|
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
56
57
58
|
# File 'lib/real_data_tests/configuration.rb', line 56
def respond_to_missing?(method_name, include_private = false)
@current_preset.respond_to?(method_name) || super
end
|
#use_preset(name) ⇒ Object
34
35
36
37
38
|
# File 'lib/real_data_tests/configuration.rb', line 34
def use_preset(name)
name = name.to_sym
raise Error, "Preset '#{name}' not found" unless @presets.key?(name)
@current_preset = @presets[name]
end
|
#with_preset(name) ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/real_data_tests/configuration.rb', line 40
def with_preset(name)
previous_preset = @current_preset
use_preset(name)
yield if block_given?
ensure
@current_preset = previous_preset
end
|