Class: Fixturizer::Services

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/fixturizer/services.rb

Constant Summary collapse

@@settings =
Fixturizer::Settings.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeServices



17
18
19
20
21
22
# File 'lib/fixturizer/services.rb', line 17

def initialize
  linter(filename: @@settings.configuration_filename).validate! unless detect_rake_lint
  @configuration = Fixturizer::Configuration.new filename: @@settings.configuration_filename
  @log = Logger.new(Fixturizer::Services.settings.log_target)
  log.info 'Starting new Fixturing'
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



15
16
17
# File 'lib/fixturizer/services.rb', line 15

def configuration
  @configuration
end

#logObject (readonly)

Returns the value of attribute log.



15
16
17
# File 'lib/fixturizer/services.rb', line 15

def log
  @log
end

Class Method Details

.configure {|@@settings| ... } ⇒ Object

Yields:



11
12
13
# File 'lib/fixturizer/services.rb', line 11

def self.configure
  yield(@@settings)
end

.settingsObject



7
8
9
# File 'lib/fixturizer/services.rb', line 7

def self.settings
  @@settings
end

Instance Method Details

#engine(name:, parameters: nil) ⇒ Object



35
36
37
# File 'lib/fixturizer/services.rb', line 35

def engine(name:, parameters: nil)
  service(type: :engines, name:, parameters:)
end

#getter(name:, parameters: nil) ⇒ Object



39
40
41
# File 'lib/fixturizer/services.rb', line 39

def getter(name:, parameters: nil)
  service(type: :getters, name:, parameters:)
end

#linter(filename: @@settings.configuration_filename) ⇒ Object



47
48
49
# File 'lib/fixturizer/services.rb', line 47

def linter(filename: @@settings.configuration_filename)
  Fixturizer::ConfigurationLinter.new filename: filename
end

#serializer(name:, parameters: nil) ⇒ Object



43
44
45
# File 'lib/fixturizer/services.rb', line 43

def serializer(name:, parameters: nil)
  service(type: :serializers, name:, parameters:)
end

#service(type:, name:, parameters: nil) ⇒ Object



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

def service(type:, name:, parameters: nil)
  service = "Fixturizer::#{type.to_s.capitalize}::#{name.to_s.capitalize}"
  log.info "running Service : #{service}"
  if parameters.nil?
    Object.const_get(service).new
  else
    log.info "  => params : #{parameters}"
    Object.const_get(service).new(**parameters)
  end
end