Class: Steep::Drivers::PrintProject

Inherits:
Object
  • Object
show all
Includes:
Utils::DriverHelper
Defined in:
lib/steep/drivers/print_project.rb

Instance Attribute Summary collapse

Attributes included from Utils::DriverHelper

#disable_install_collection, #steepfile

Instance Method Summary collapse

Methods included from Utils::DriverHelper

#install_collection, #keep_diagnostic?, #load_config, #request_id, #shutdown_exit, #wait_for_message, #wait_for_response_id

Constructor Details

#initialize(stdout:, stderr:) ⇒ PrintProject

Returns a new instance of PrintProject.



12
13
14
15
16
# File 'lib/steep/drivers/print_project.rb', line 12

def initialize(stdout:, stderr:)
  @stdout = stdout
  @stderr = stderr
  @print_files = false
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



8
9
10
# File 'lib/steep/drivers/print_project.rb', line 8

def files
  @files
end

Returns the value of attribute print_files.



7
8
9
# File 'lib/steep/drivers/print_project.rb', line 7

def print_files
  @print_files
end

#stderrObject (readonly)

Returns the value of attribute stderr.



5
6
7
# File 'lib/steep/drivers/print_project.rb', line 5

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/steep/drivers/print_project.rb', line 4

def stdout
  @stdout
end

Instance Method Details

#as_json(project) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/steep/drivers/print_project.rb', line 18

def as_json(project)
  {
    "steepfile" => project.steepfile_path.to_s,
    "targets" => project.targets.map do |target|
      target_as_json(target)
    end
  }
end

#group_as_json(group) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/steep/drivers/print_project.rb', line 65

def group_as_json(group)
  json = {
    "name" => group.name.to_s,
    "source_pattern" => pattern_as_json(group.source_pattern),
    "signature_pattern" => pattern_as_json(group.signature_pattern)
  } #: group_json

  if files
    files.signature_paths.each_group_path(group) do |path,|
      (json["signature_paths"] ||= []) << path.to_s
    end

    files.source_paths.each_group_path(group) do |path,|
      (json["source_paths"] ||= []) << path.to_s
    end
  end

  json
end

#pattern_as_json(pattern) ⇒ Object



85
86
87
88
89
90
# File 'lib/steep/drivers/print_project.rb', line 85

def pattern_as_json(pattern)
  {
    "pattern" => pattern.patterns,
    "ignore" => pattern.ignores
  }
end

#runObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/steep/drivers/print_project.rb', line 92

def run
  project = load_config()
  if print_files
    loader = Services::FileLoader.new(base_dir: project.base_dir)
    @files = files = Server::TargetGroupFiles.new(project)
    project.targets.each do |target|
      loader.each_path_in_target(target) do |path|
        files.add_path(path)
      end
    end
  else
    @files = nil
  end

  stdout.puts YAML.dump(as_json(project))

  0
end

#target_as_json(target) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/steep/drivers/print_project.rb', line 27

def target_as_json(target)
  json = {
    "name" => target.name.to_s,
    "source_pattern" => pattern_as_json(target.source_pattern),
    "inline_source_pattern" => pattern_as_json(target.inline_source_pattern),
    "signature_pattern" => pattern_as_json(target.signature_pattern),
    "groups" => target.groups.map do |group|
      group_as_json(group)
    end,
    "libraries" => target.new_env_loader().yield_self do |loader|
      libs = [] #: Array[library_json]
      loader.each_dir do |lib, path|
        case lib
        when :core
          libs << { "name" => "__core__", "path" => path.to_s }
        when Pathname
          raise "Unexpected pathname from loader: path=#{path}"
        else
          libs << { "name" => lib.name, "version" => lib.version, "path" => path.to_s }
        end
      end
      libs
    end,
    "unreferenced" => target.unreferenced
  } #: target_json

  if files
    files.signature_paths.each_group_path(target) do |path,|
      (json["signature_paths"] ||= []) << path.to_s
    end
    files.source_paths.each_group_path(target) do |path,|
      (json["source_paths"] ||= []) << path.to_s
    end
  end

  json
end