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.



14
15
16
17
18
# File 'lib/steep/drivers/print_project.rb', line 14

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

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



10
11
12
# File 'lib/steep/drivers/print_project.rb', line 10

def files
  @files
end

Returns the value of attribute print_files.



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

def print_files
  @print_files
end

#stderrObject (readonly)

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

Instance Method Details

#as_json(project) ⇒ Object



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

def as_json(project)
  {
    steepfile: project.steepfile_path.to_s,
    targets: project.targets.map do |target|
      target_as_json(target)
    end
  }.stringify_keys
end

#group_as_json(group) ⇒ Object



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

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.each_group_signature_path(group, true) do |path|
      (json["signature_paths"] ||= []) << path.to_s

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

  json
end

#pattern_as_json(pattern) ⇒ Object



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

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

#runObject



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

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



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
64
# File 'lib/steep/drivers/print_project.rb', line 29

def target_as_json(target)
  json = {
    "name" => target.name.to_s,
    "source_pattern" => pattern_as_json(target.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.each_group_signature_path(target, true) do |path|
      (json["signature_paths"] ||= []) << path.to_s
    end
    files.each_group_source_path(target, true) do |path|
      (json["source_paths"] ||= []) << path.to_s
    end
  end

  json
end