Class: ActiveMocker::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mocker/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.build_in_progressObject

Returns the value of attribute build_in_progress.



6
7
8
# File 'lib/active_mocker/config.rb', line 6

def build_in_progress
  @build_in_progress
end

.clear_log_on_buildObject

Returns the value of attribute clear_log_on_build.



6
7
8
# File 'lib/active_mocker/config.rb', line 6

def clear_log_on_build
  @clear_log_on_build
end

.file_readerObject

Returns the value of attribute file_reader.



6
7
8
# File 'lib/active_mocker/config.rb', line 6

def file_reader
  @file_reader
end

.log_locationObject

Returns the value of attribute log_location.



6
7
8
# File 'lib/active_mocker/config.rb', line 6

def log_location
  @log_location
end

.mock_dirObject

Returns the value of attribute mock_dir.



6
7
8
# File 'lib/active_mocker/config.rb', line 6

def mock_dir
  @mock_dir
end

.model_base_classesObject

Returns the value of attribute model_base_classes.



6
7
8
# File 'lib/active_mocker/config.rb', line 6

def model_base_classes
  @model_base_classes
end

.model_dirObject

Returns the value of attribute model_dir.



6
7
8
# File 'lib/active_mocker/config.rb', line 6

def model_dir
  @model_dir
end

.schema_fileObject

Returns the value of attribute schema_file.



6
7
8
# File 'lib/active_mocker/config.rb', line 6

def schema_file
  @schema_file
end

Class Method Details

.clear_logObject



62
63
64
65
66
# File 'lib/active_mocker/config.rb', line 62

def clear_log
  if @clear_log_on_build && File.exist?(@log_location)
    FileUtils.rm(@log_location)
  end
end

.default_loggerObject



51
52
53
54
# File 'lib/active_mocker/config.rb', line 51

def default_logger
  FileUtils.mkdir_p(File.dirname(@log_location)) unless File.directory?(File.dirname(@log_location))
  ::Logger.new(@log_location)
end

.load_defaultsObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/active_mocker/config.rb', line 24

def load_defaults
  @schema_file        = nil unless @schema_file
  @model_dir          = nil unless @model_dir
  @mock_dir           = nil unless @mock_dir
  @model_base_classes = %w[ ActiveRecord::Base ] unless @model_base_classes
  @file_reader        = FileReader     unless @file_reader
  @log_location       = 'log/active_mocker.log' unless @log_location
  @clear_log_on_build = true
  rails_defaults if Object.const_defined?('Rails')
end

.loggerObject



35
36
37
# File 'lib/active_mocker/config.rb', line 35

def logger
  default_logger
end

.rails_defaultsObject



56
57
58
59
60
# File 'lib/active_mocker/config.rb', line 56

def rails_defaults
  @schema_file = File.join(Rails.root, 'db/schema.rb') unless @schema_file
  @model_dir   = File.join(Rails.root, 'app/models')   unless @model_dir
  @mock_dir    = File.join(Rails.root, 'spec/mocks')   unless @mock_dir
end

.reset_allObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/active_mocker/config.rb', line 39

def reset_all
  [ :@schema_file,
    :@model_dir,
    :@mock_dir,
    :@model_base_classes,
    :@file_reader,
    :@logger,
    :@schema_file,
    :@model_dir,
    :@mock_dir].each{|ivar| instance_variable_set(ivar, nil)}
end

.set {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



19
20
21
22
# File 'lib/active_mocker/config.rb', line 19

def set
  load_defaults
  yield self
end