Class: Cure::Dsl::Exporters

Inherits:
Object
  • Object
show all
Defined in:
lib/cure/dsl/exporters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExporters

Returns a new instance of Exporters.



12
13
14
# File 'lib/cure/dsl/exporters.rb', line 12

def initialize
  @processors = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, **args) ⇒ Cure::Export::BaseBuilder

Parameters:

  • method_name (Symbol)

Returns:

  • (Cure::Export::BaseBuilder)


25
26
27
28
29
30
31
32
33
# File 'lib/cure/dsl/exporters.rb', line 25

def method_missing(method_name, **args)
  klass_name = "Cure::Export::#{method_name.to_s.split("_").map(&:capitalize).join("")}Processor"
  raise "#{method_name} is not valid" unless class_exists?(klass_name)

  @processors << Kernel.const_get(klass_name).new(
    args[:named_range] || "_default",
    args || {}
  )
end

Instance Attribute Details

#processorsObject (readonly)

Returns the value of attribute processors.



10
11
12
# File 'lib/cure/dsl/exporters.rb', line 10

def processors
  @processors
end

Instance Method Details

#class_exists?(klass_name) ⇒ TrueClass, FalseClass

Parameters:

Returns:

  • (TrueClass, FalseClass)


37
38
39
40
41
42
# File 'lib/cure/dsl/exporters.rb', line 37

def class_exists?(klass_name)
  klass = Module.const_get(klass_name)
  klass.is_a?(Class)
rescue NameError
  false
end

#respond_to_missing?(_method_name, _include_private = false) ⇒ TrueClass

Parameters:

  • _method_name (String, Symbol)
  • _include_private (TrueClass, FalseClass) (defaults to: false)

Returns:

  • (TrueClass)


19
20
21
# File 'lib/cure/dsl/exporters.rb', line 19

def respond_to_missing?(_method_name, _include_private=false)
  true
end