Class: Starter::Import

Inherits:
Object
  • Object
show all
Extended by:
Shared::BaseFile
Defined in:
lib/starter/import.rb

Class Method Summary collapse

Methods included from Shared::BaseFile

add_mount_point, add_to_base, base_file, base_file_path, base_prefix, base_version, remove_from_base, remove_mount_point

Class Method Details

.create_files_from(spec) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/starter/import.rb', line 29

def create_files_from(spec)
  spec.namespaces.each_with_object([]) do |(name_of, paths), memo|
    @naming = Starter::Names.new(name_of)

    #   1. build content for file
    namespace = Starter::Importer::Namespace.new(
      naming: @naming,
      paths: paths,
      components: spec.components
    )

    break if ENV['RACK_ENV'] == 'test'

    #   2. create endpoint file
    FileOps.write_file(@naming.api_file_name, namespace.content)
    memo << @naming.api_file_name

    #   3. add mountpoint
    add_mount_point
  end
end

.do_it!(path) ⇒ Object



11
12
13
14
# File 'lib/starter/import.rb', line 11

def do_it!(path)
  spec = load_spec(path)
  create_files_from(spec)
end

.load_spec(path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/starter/import.rb', line 16

def load_spec(path)
  return nil if path.blank?

  spec = case File.extname(path)[1..]
         when 'yaml', 'yml'
           YAML.load_file(path)
         when 'json'
           JSON.load_file(path)
         end

  Importer::Specification.new(spec:)
end