Class: Fig::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/repository.rb

Overview

Overall management of a repository. Handles local operations itself; defers remote operations to others.

Constant Summary collapse

METADATA_SUBDIRECTORY =
'_meta'
PACKAGE_FILE_IN_REPO =
'.fig'
RESOURCES_FILE =
'resources.tar.gz'
VERSION_FILE_NAME =
'repository-format-version'
LOCAL_VERSION_SUPPORTED =
2
REMOTE_VERSION_SUPPORTED =
1

Instance Method Summary collapse

Constructor Details

#initialize(application_configuration, options, operating_system, local_repository_directory, remote_repository_url, parser, publish_listeners) ⇒ Repository

Returns a new instance of Repository.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fig/repository.rb', line 32

def initialize(
  application_configuration,
  options,
  operating_system,
  local_repository_directory,
  remote_repository_url,
  parser,
  publish_listeners
)
  @application_configuration    = application_configuration
  @options                      = options
  @operating_system             = operating_system
  @local_repository_directory   = local_repository_directory
  @remote_repository_url        = remote_repository_url
  @parser                       = parser
  @publish_listeners            = publish_listeners

  initialize_local_repository()
  reset_cached_data()
end

Instance Method Details

#clean(descriptor) ⇒ Object



123
124
125
126
127
128
129
130
131
# File 'lib/fig/repository.rb', line 123

def clean(descriptor)
  check_local_repository_format()

  @package_cache.remove_package(descriptor.name, descriptor.version)

  nuke_package descriptor

  return
end

#get_package(descriptor, allow_any_version = false) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/fig/repository.rb', line 86

def get_package(
  descriptor,
  allow_any_version = false
)
  check_local_repository_format()

  if not descriptor.version
    if allow_any_version
      package = @package_cache.get_any_version_of_package(descriptor.name)
      if package
        Fig::Logging.warn(
          "Picked version #{package.version} of #{package.name} at random."
        )
        return package
      end
    end

    raise Fig::RepositoryError.new(
      %Q<Cannot retrieve "#{descriptor.name}" without a version.>
    )
  end

  package = @package_cache.get_package(descriptor.name, descriptor.version)
  return package if package

  Fig::Logging.debug \
    "Considering #{Fig::PackageDescriptor.format(descriptor.name, descriptor.version, nil)}."

  if should_update?(descriptor)
    check_remote_repository_format()

    update_package(descriptor)
  end

  return read_local_package(descriptor)
end

#list_packagesObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fig/repository.rb', line 57

def list_packages
  check_local_repository_format

  results = []
  if File.exist?(local_package_directory)
    @operating_system.list(local_package_directory).each do
      |name|

      @operating_system.list(
        File.join local_package_directory(), name
      ).each do
        |version|

        results << Fig::PackageDescriptor.format(name, version, nil)
      end
    end
  end

  return results
end

#list_remote_packagesObject



78
79
80
81
82
83
84
# File 'lib/fig/repository.rb', line 78

def list_remote_packages
  check_remote_repository_format()

  paths = @operating_system.download_list(remote_repository_url())

  return paths.reject { |path| path =~ %r< ^ #{METADATA_SUBDIRECTORY} / >xs }
end

#publish_package(package_statements, descriptor, local_only, source_package, was_forced) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/fig/repository.rb', line 133

def publish_package(
  package_statements, descriptor, local_only, source_package, was_forced
)
  check_local_repository_format()
  if not local_only
    check_remote_repository_format()
  end

  publisher = Fig::RepositoryPackagePublisher.new
  publisher.application_configuration    = @application_configuration
  publisher.options                      = @options
  publisher.operating_system             = @operating_system
  publisher.publish_listeners            = @publish_listeners
  publisher.package_statements           = package_statements
  publisher.descriptor                   = descriptor
  publisher.source_package               = source_package
  publisher.was_forced                   = was_forced
  publisher.base_temp_dir                = base_temp_dir
  publisher.runtime_for_package          = runtime_for_package(descriptor)
  publisher.local_only                   = local_only
  publisher.local_directory_for_package  =
    local_directory_for_package(descriptor)
  publisher.local_fig_file_for_package =
    local_fig_file_for_package(descriptor)

  if not local_only
    publisher.remote_directory_for_package =
      remote_directory_for_package(descriptor)
    publisher.remote_fig_file_for_package =
      remote_fig_file_for_package(descriptor)
  end

  return publisher.publish_package()
end

#reset_cached_dataObject



53
54
55
# File 'lib/fig/repository.rb', line 53

def reset_cached_data()
  @package_cache = Fig::PackageCache.new()
end

#update_if_missingObject



172
173
174
# File 'lib/fig/repository.rb', line 172

def update_if_missing()
  @update_condition = :if_missing
end

#update_unconditionallyObject



168
169
170
# File 'lib/fig/repository.rb', line 168

def update_unconditionally()
  @update_condition = :unconditionally
end