elm_install 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 866f31dd5848df9cc5fdce2188f1de72c04d8863
4
- data.tar.gz: 5e78e0422f41adbcc320908a4d704429c4f030ff
3
+ metadata.gz: 37be0aa80902c18689f3c326dac58a7150bdbbbd
4
+ data.tar.gz: dcfc9bfb502d542eda6cbc3b50911253d35eb784
5
5
  SHA512:
6
- metadata.gz: 9807dde1aba8c797b9f9e4db38885ff67f54c132eb022bb2733ec75fcfa09863260332fbd2bcca97a6ec5501d8a718e26350e0a4bb05eb84610f1e7eb0ee755c
7
- data.tar.gz: 3877767e0e6038f564e01016d378ceae90120c68efc99accf0f3edfe523abd2b32f872fc2768a51872f5277c56e0bfba6d5f6ef0226bf4b1822fe5ad497c400c
6
+ metadata.gz: 68fda6c2faa66874538594da8c1656bc33ccd7100a7b728a4f7ab78d3895d1f5fb5b78be3f17fd29e77dd4c0f45f141fa2471dd8ff94dead8c0fcf9a17bb5b59
7
+ data.tar.gz: 4a6ec599550195f0a253f2702f833741a3c9cee21e2c504d7adb7bb5862e68fe4e0441d3eb312a347ce33f1daa456163ed901f1400c56413fbd274093ea2faf6
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
+ gem 'inch', '~> 0.7.1'
4
5
  gem 'rspec', '~> 3.5'
5
6
  gem 'rubocop', '~> 0.46.0'
6
7
  gem 'rubycritic', '~> 3.1', '>= 3.1.3'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- elm_install (0.1.2)
4
+ elm_install (0.1.3)
5
5
  commander (~> 4.4, >= 4.4.2)
6
6
  git (~> 1.3)
7
7
  git_clone_url (~> 2.0)
@@ -22,6 +22,7 @@ GEM
22
22
  thread_safe (~> 0.3, >= 0.3.1)
23
23
  codeclimate-engine-rb (0.4.0)
24
24
  virtus (~> 1.0)
25
+ coderay (1.1.1)
25
26
  coercible (1.0.0)
26
27
  descendants_tracker (~> 0.0.1)
27
28
  commander (4.4.2)
@@ -47,15 +48,25 @@ GEM
47
48
  hashdiff (0.3.1)
48
49
  highline (1.7.8)
49
50
  ice_nine (0.11.2)
51
+ inch (0.7.1)
52
+ pry
53
+ sparkr (>= 0.2.0)
54
+ term-ansicolor
55
+ yard (~> 0.8.7.5)
50
56
  indentation (0.1.1)
51
57
  json (2.0.2)
52
58
  launchy (2.4.3)
53
59
  addressable (~> 2.3)
60
+ method_source (0.8.2)
54
61
  molinillo (0.5.4)
55
62
  parser (2.3.3.1)
56
63
  ast (~> 2.2)
57
64
  path_expander (1.0.1)
58
65
  powerpack (0.1.1)
66
+ pry (0.10.4)
67
+ coderay (~> 1.1.0)
68
+ method_source (~> 0.8.1)
69
+ slop (~> 3.4)
59
70
  public_suffix (2.0.4)
60
71
  rainbow (2.1.0)
61
72
  reek (4.5.3)
@@ -100,11 +111,16 @@ GEM
100
111
  json (>= 1.8, < 3)
101
112
  simplecov-html (~> 0.10.0)
102
113
  simplecov-html (0.10.0)
114
+ slop (3.6.0)
103
115
  smart_colored (1.1.1)
104
116
  solve (3.1.0)
105
117
  molinillo (>= 0.5)
106
118
  semverse (>= 1.1, < 3.0)
119
+ sparkr (0.4.1)
120
+ term-ansicolor (1.4.0)
121
+ tins (~> 1.0)
107
122
  thread_safe (0.3.5)
123
+ tins (1.13.0)
108
124
  unicode-display_width (1.1.2)
109
125
  uri-ssh_git (2.0.0)
110
126
  virtus (1.0.5)
@@ -112,12 +128,14 @@ GEM
112
128
  coercible (~> 1.0)
113
129
  descendants_tracker (~> 0.0, >= 0.0.3)
114
130
  equalizer (~> 0.0, >= 0.0.9)
131
+ yard (0.8.7.6)
115
132
 
116
133
  PLATFORMS
117
134
  ruby
118
135
 
119
136
  DEPENDENCIES
120
137
  elm_install!
138
+ inch (~> 0.7.1)
121
139
  rspec (~> 3.5)
122
140
  rubocop (~> 0.46.0)
123
141
  rubycritic (~> 3.1, >= 3.1.3)
data/Rakefile CHANGED
@@ -6,4 +6,5 @@ task :ci do
6
6
  sh 'rspec'
7
7
  sh 'rubocop'
8
8
  sh 'rubycritic -m --no-browser -s 90 lib'
9
+ sh 'inch suggest lib --pedantic'
9
10
  end
data/Readme.md CHANGED
@@ -1,74 +1,87 @@
1
- # elm-github-install
1
+ # elm-install
2
2
 
3
- [![npm version](https://badge.fury.io/js/elm-github-install.svg)](https://badge.fury.io/js/elm-github-install)
3
+ [![Gem Version](https://badge.fury.io/rb/elm_install.svg)](https://badge.fury.io/rb/elm_install)
4
+ [![Code Climate](https://codeclimate.com/github/gdotdesign/elm-github-install/badges/gpa.svg)](https://codeclimate.com/github/gdotdesign/elm-github-install)
5
+ [![Inline docs](http://inch-ci.org/github/gdotdesign/elm-github-install.svg?branch=master)](http://inch-ci.org/github/gdotdesign/elm-github-install)
4
6
 
5
- This node script and package that allows you to install Elm packages **directly
6
- from Github**, bypassing the package repository (package.elm-lang.org) while also
7
- enabling restricted (effect manager and native) packages to be installed.
7
+ This gem allows you to install Elm packages **directly from any Git repository
8
+ (even private ones)**, bypassing the package repository (package.elm-lang.org)
9
+ while also enabling restricted (effect manager and native) packages to be
10
+ installed.
8
11
 
9
- ## Description
12
+ ## Installation
10
13
 
11
- There are some things that made this possible:
12
- * The basic design of Elm packages: using github, semantic versioning and tags
13
- * [Semver package](https://www.npmjs.com/package/semver) to validate versions
14
- * [SemverResolver package](https://github.com/pghalliday/semver-resolver) that
15
- does the actual resolving
16
-
17
- These are the steps the installer takes:
18
- * Reads the dependencies from `elm-package.json`
19
- * Transforms them to semver dependencies - **4.0.4 <= v < 5.0.0** becomes
20
- **>= 4.0.4 < 5.0.0**
21
- * Loads the dependencies of the packages form Github and transforms them also
22
- * Resolve the dependencies
23
- * Install resolved dependencies into `elm-stuff/packages`
24
- * Writes `elm-stuff/exact-dependencies.json` with the resolved dependencies
25
-
26
- ## Warnings
27
-
28
- There are some caveats though:
29
- * [TODO] This installer doesn't check the installed elm-version
30
- * [DEPENDENCY] Git tags (semver) are needed other references cannot be installed
31
- (branch-name, commit-hash)
32
- * [DEPENDENCY] Git is needed
33
- * [DEPENDENCY] Node is needed
34
-
35
- ## Usage
36
-
37
- Install it:
14
+ If you have ruby installed on your machine then you can install it directy from
15
+ [rubygems.org](https://rubygems.org/gems/elm_install):
38
16
  ```
39
- npm install -g elm-github-install
17
+ gem install elm-install
40
18
  ```
41
19
 
42
- Elm packages are name after their github repositories, so you can simply declare the
43
- github package you want the way you would declare any other package.
44
- For example, if you want to install [NoRedInk's Elm css](https://github.com/NoRedInk/nri-elm-css)
45
- at version 1.3.0, you would do the following:
20
+ There are also dependency free versions available for every release in the
21
+ [releases page](https://github.com/gdotdesign/elm-github-install/releases).
22
+
23
+ ## Basic Usage
24
+ Once installed `elm-install` can be used instead of `elm-package` as a
25
+ replacement:
46
26
 
27
+ `elm-package.json`:
47
28
  ```
48
- # elm-package.json
49
29
  {
50
30
  ...
51
31
  "dependencies": {
52
- ...
53
- "githubUser/repoName": "desiredVersion <= v < someLargerNumber",
54
- "NoRedInk/nri-elm-css": "1.3.0 <= 1.3.0 < 2.0.0",
55
- ...
32
+ "elm-lang/core": "5.0.0 <= v < 6.0.0",
33
+ "elm-lang/svg": "2.0.0 <= v < 3.0.0",
34
+ "elm-lang/dom": "1.1.1 <= v < 2.0.0"
56
35
  }
57
36
  ...
58
37
  }
59
38
  ```
60
39
 
61
- You can find the current version of the package in the repository's `elm-package.json`.
40
+ Command:
41
+ ```sh
42
+ $ elm-install install
62
43
 
63
- Use the command:
64
- ```
65
- elm-github-install
44
+ Resolving packages...
45
+ ▶ Package: git@github.com:elm-lang/core not found in cache, cloning...
46
+ ▶ Package: git@github.com:elm-lang/svg not found in cache, cloning...
47
+ ▶ Package: git@github.com:elm-lang/html not found in cache, cloning...
48
+ ▶ Package: git@github.com:elm-lang/virtual-dom not found in cache, cloning...
49
+ ▶ Package: git@github.com:elm-lang/dom not found in cache, cloning...
50
+ Solving dependencies...
51
+ Saving package cache...
52
+ ● elm-lang/core - 5.0.0 (5.0.0)
53
+ ● elm-lang/svg - 2.0.0 (2.0.0)
54
+ ● elm-lang/dom - 1.1.1 (1.1.1)
55
+ ● elm-lang/html - 2.0.0 (2.0.0)
56
+ ● elm-lang/virtual-dom - 2.0.2 (2.0.2)
57
+ Packages configured successfully!
66
58
  ```
67
59
 
68
- ## Demonstration
69
- The following repositories have their packages successfully installed and
70
- the main file successfully compiled (2016-06-12):
71
- * [STANDARD] https://github.com/debois/elm-mdl/tree/v7/demo - Demo.elm
72
- * [STANDARD] https://github.com/evancz/elm-sortable-table/tree/master/examples -
73
- 1-presidents.elm
74
- * [HAVE GITHUB DEPS] https://github.com/gdotdesign/elm-ui-website - source/Main.elm
60
+ ## Advanced Usage
61
+ Sources (urls for git repositories) can be defined in the `dependency-sources`
62
+ field in `elm-package.json` for any package defined the the `dependencies`
63
+ field. There is only one restriction: the pacakges name must match the path of
64
+ the url of the git repository, this is because it could cause conflicts.
65
+
66
+ The source can be defined by a string or a hash containing the url and the
67
+ reference (tag, commit hash, branch) to use. If a reference is defined then
68
+ the version in the `dependencies` field is ignored and the **version will be
69
+ used from the `elm-package.json` at that reference (= 2.0.0)**.
70
+
71
+ ```
72
+ ...
73
+ "dependencies": {
74
+ "gdotdesign/elm-install-test": "1.0.0 <= v < 2.0.0",
75
+ "elm-lang/core": "5.0.0 <= v < 6.0.0",
76
+ "elm-lang/svg": "2.0.0 <= v < 3.0.0",
77
+ "elm-lang/dom": "1.1.1 <= v < 2.0.0"
78
+ },
79
+ "dependency-sources": {
80
+ "elm-lang/core": "git@github.com:elm-lang/core",
81
+ "gdotdesign/elm-install-test": {
82
+ "url": "gdotdesign@bitbucket.org:gdotdesign/elm-install-test",
83
+ "ref": "master"
84
+ }
85
+ }
86
+ ...
87
+ ```
data/lib/elm_install.rb CHANGED
@@ -15,6 +15,11 @@ require_relative './elm_install/installer'
15
15
  module ElmInstall
16
16
  module_function
17
17
 
18
+ # Starts an install with the given isntallation.
19
+ #
20
+ # @param options [Hash] The options
21
+ #
22
+ # @return [void]
18
23
  def install(options = { verbose: false })
19
24
  Installer.new(options).install
20
25
  end
@@ -3,10 +3,14 @@ module ElmInstall
3
3
  class Base
4
4
  extend Forwardable
5
5
 
6
+ # @return [Hash] The current cache
6
7
  attr_reader :cache
7
8
 
8
9
  def_delegators :@cache, :each, :key?
9
10
 
11
+ # Initializes a new base for a cache.
12
+ #
13
+ # @param options [Hash] The options
10
14
  def initialize(options = {})
11
15
  @options = options
12
16
  @cache = {}
@@ -14,22 +18,31 @@ module ElmInstall
14
18
  end
15
19
 
16
20
  # Saves the cache into the json file.
21
+ #
22
+ # @return [void]
17
23
  def save
18
24
  File.binwrite(file, JSON.pretty_generate(@cache))
19
25
  end
20
26
 
21
27
  # Loads a cache from the json file.
28
+ #
29
+ # @return [void]
22
30
  def load
23
31
  @cache = JSON.parse(File.read(file))
24
32
  rescue
25
33
  @cache = {}
26
34
  end
27
35
 
36
+ # Returns the patch of the cache file.
37
+ #
38
+ # @return [String] The path
28
39
  def file
29
40
  File.join(directory, @file)
30
41
  end
31
42
 
32
- # Returns the directory where the cache is stored.
43
+ # Returns the path of the directory where the cache is stored.
44
+ #
45
+ # @return [String] The path
33
46
  def directory
34
47
  @options[:directory]
35
48
  end
@@ -8,6 +8,9 @@ module ElmInstall
8
8
  # home directory (~/.elm-install), this can be changed with
9
9
  # the `directory` option.
10
10
  class Cache < Base
11
+ # Initializes a cache with the given options.
12
+ #
13
+ # @param options [Hash] The options
11
14
  def initialize(options)
12
15
  @file = 'cache.json'
13
16
  super options
@@ -15,18 +18,33 @@ module ElmInstall
15
18
 
16
19
  # Adds a new dependency to the cache for a given package & version
17
20
  # combination.
21
+ #
22
+ # @param package [String] The url of the package
23
+ # @param version [String] The semver version (1.0.0 or 1.0.0+master)
24
+ # @param constraint [Array] The constraint ["pacakge", "<= 1.0.0"]
25
+ #
26
+ # @return [Array] The dependencies of the package & version combination
18
27
  def dependency(package, version, constraint)
19
28
  ensure_package version
20
29
  @cache[package][version] << constraint
21
30
  end
22
31
 
23
32
  # Ensures that a package & version combination exists in the cache.
33
+ #
34
+ # @param package [String] The url of the package
35
+ # @param version [String] The semver version (1.0.0 or 1.0.0+master)
36
+ #
37
+ # @return [Array] The dependencies of the package & version combination
24
38
  def ensure_version(package, version)
25
39
  ensure_package package
26
40
  @cache[package][version] ||= []
27
41
  end
28
42
 
29
43
  # Ensures that a package exists in the cache.
44
+ #
45
+ # @param package [String] The url of the package
46
+ #
47
+ # @return [Hash] The dependency hash of the package
30
48
  def ensure_package(package)
31
49
  @cache[package] ||= {}
32
50
  end
@@ -2,31 +2,104 @@ module ElmInstall
2
2
  # This is a class for reading the `elm-package`.json file and
3
3
  # transform it's `dependecies` field to a unified format.
4
4
  module ElmPackage
5
- # TODO: Error handling
5
+ # Returns the dependencies for the given `elm-package`.
6
+ #
7
+ # @param path [String] The path for the file
8
+ #
9
+ # @return [Hash] The hash of dependenceis (url => version or ref)
6
10
  def self.dependencies(path)
7
11
  json = read path
8
12
  transform_dependencies(
9
- json['dependencies'],
13
+ json['dependencies'].to_h,
10
14
  json['dependency-sources'].to_h
11
15
  )
12
16
  end
13
17
 
18
+ # Reads the given file as JSON.
19
+ #
20
+ # :reek:DuplicateMethodCall
21
+ #
22
+ # @param path [String] The path
23
+ #
24
+ # @return [Hash] The json
14
25
  def self.read(path)
15
26
  JSON.parse(File.read(path))
27
+ rescue JSON::ParserError
28
+ Logger.arrow "Invalid JSON in file: #{path.bold}."
29
+ Process.exit
30
+ rescue Errno::ENOENT
31
+ Logger.arrow "Could not find file: #{path.bold}."
32
+ Process.exit
16
33
  end
17
34
 
35
+ # Transform dependencies from (package name => version) to
36
+ # (url => version or ref) format using the `depdendency-sources` field.
37
+ #
38
+ # @param raw_dependencies [Hash] The raw dependencies
39
+ # @param sources [Hash] The sources for the dependencies
40
+ #
41
+ # @return [Hash] The dependencies
18
42
  def self.transform_dependencies(raw_dependencies, sources)
19
43
  raw_dependencies.each_with_object({}) do |(package, constraint), memo|
20
44
  value = sources.fetch(package, package)
21
45
 
22
- if value.is_a?(Hash)
23
- memo[value['url']] = value['ref']
24
- else
25
- memo[transform_package(value)] = constraint
26
- end
46
+ transform_dependency package, value, constraint, memo
27
47
  end
28
48
  end
29
49
 
50
+ # Transforms a dependecy.
51
+ #
52
+ # :reek:LongParameterList
53
+ # :reek:DuplicateMethodCall
54
+ #
55
+ # @param package [String] The package
56
+ # @param value [String] The version
57
+ # @param constraint [String] The constarint
58
+ # @param memo [Hash] The hash to save the dependency to
59
+ #
60
+ # @return [Hash] The memo object
61
+ def self.transform_dependency(package, value, constraint, memo)
62
+ if value.is_a?(Hash)
63
+ check_path package, value['url']
64
+ memo[value['url']] = value['ref']
65
+ else
66
+ url = transform_package(value)
67
+ check_path package, url
68
+ memo[url] = constraint
69
+ end
70
+ end
71
+
72
+ # Checks if the given url matches the given package.
73
+ #
74
+ # :reek:DuplicateMethodCall
75
+ #
76
+ # @param package [String] The package
77
+ # @param url [String] The url
78
+ #
79
+ # @return [void]
80
+ def self.check_path(package, url)
81
+ uri = GitCloneUrl.parse(url)
82
+ path = uri.path.sub(%r{^/}, '')
83
+
84
+ return if path == package
85
+
86
+ puts "
87
+ The source of package #{package.bold} is set to #{url.bold} which would
88
+ be install to #{"elm-stuff/#{path}".bold}. This would cause a conflict
89
+ when trying to compile anything.
90
+
91
+ The name of a package must match the source url's path.
92
+
93
+ #{package.bold} <=> #{path.bold}
94
+ "
95
+ Process.exit
96
+ end
97
+
98
+ # Transforms a package to it's url for if needed.
99
+ #
100
+ # @param key [String] The package
101
+ #
102
+ # @return [String] The url
30
103
  def self.transform_package(key)
31
104
  GitCloneUrl.parse(key).to_s
32
105
  rescue
@@ -4,6 +4,9 @@ module ElmInstall
4
4
  # This class if for cloning and fetching repositories based
5
5
  # on a cache.
6
6
  class GitResolver < Base
7
+ # Initializes a git resolver with the given options.
8
+ #
9
+ # @param options [Hash] The options
7
10
  def initialize(options)
8
11
  @file = 'ref-cache.json'
9
12
  super options
@@ -11,36 +14,71 @@ module ElmInstall
11
14
  @cache.keys.each_with_object({}) { |key, memo| memo[key] = true }
12
15
  end
13
16
 
17
+ # Returns the refs for a given url.
18
+ #
19
+ # @param url [String] the url
20
+ #
21
+ # @return [Hash] The refs
14
22
  def refs(url)
15
23
  self.class.refs(url)
16
24
  end
17
25
 
26
+ # Clears the cache
27
+ #
28
+ # @return [void]
18
29
  def clear
19
30
  @check_cache = {}
20
31
  end
21
32
 
33
+ # Returns the refs for a given url.
34
+ #
35
+ # @param url [String] the url
36
+ #
37
+ # @return [Hash] The refs
22
38
  def self.refs(url)
23
39
  refs = Git.ls_remote url
24
40
  refs.delete 'head'
25
41
  JSON.parse(refs.to_json)
26
42
  end
27
43
 
44
+ # Returns if the given package (url) is in the cache.
45
+ #
46
+ # @param url [String] The url
47
+ #
48
+ # @return [Boolean] True if exists false if not
28
49
  def package?(url)
29
50
  @check_cache.key?(repository_path(url))
30
51
  end
31
52
 
53
+ # Returns the path of the repository for a given url.
54
+ #
32
55
  # :reek:FeatureEnvy
56
+ #
57
+ # @param url [String] The url
58
+ #
59
+ # @return [String] The path
33
60
  def repository_path(url)
34
61
  uri = GitCloneUrl.parse(url)
35
62
  File.join(directory, uri.host, uri.path)
36
63
  end
37
64
 
65
+ # Returns a git repository object for the given url, cloning it
66
+ # if it does not exists.
67
+ #
68
+ # @param url [String] The url
69
+ #
70
+ # @return [Git::Base] The repository
38
71
  def repository(url)
39
72
  open(url) do |repo|
40
73
  update_cache repo
41
74
  end
42
75
  end
43
76
 
77
+ # Updates a repository checking it's refs and fetching changes if needed.
78
+ #
79
+ # @param repo [Git::Base] The repository
80
+ #
81
+ # @return [void]
44
82
  def update_cache(repo)
45
83
  directory = File.dirname(repo.repo.path)
46
84
  url = repo.remote.url
@@ -55,6 +93,11 @@ module ElmInstall
55
93
  cache[directory] = refs
56
94
  end
57
95
 
96
+ # Opens a git repository cloning if it's not exists.
97
+ #
98
+ # @param url [String] The url
99
+ #
100
+ # @return [Git::Base] The repository
58
101
  def open(url)
59
102
  path = repository_path(url)
60
103
 
@@ -68,6 +111,12 @@ module ElmInstall
68
111
  repo
69
112
  end
70
113
 
114
+ # Clones the repostiry from the given url to the given path.
115
+ #
116
+ # @param url [String] The url
117
+ # @param path [String] The path
118
+ #
119
+ # @return [Git::Base] The repository
71
120
  def clone(url, path)
72
121
  Logger.arrow "Package: #{url.bold} not found in cache, cloning..."
73
122
  FileUtils.mkdir_p path
@@ -1,16 +1,25 @@
1
1
  module ElmInstall
2
2
  # This class is for building dependency graphs from a cache.
3
3
  class GraphBuilder
4
+ # @return [Solve::Graph] The graph
4
5
  attr_reader :graph
5
6
 
6
- # Returns a graph from a cache.
7
+ # Returns a graph from a cache and options.
8
+ #
9
+ # @param cache [Cache] The cache to generate the graph from.
10
+ # @param options [Hash] The options to use.
11
+ #
12
+ # @return [Solve::Graph] The graph
7
13
  def self.graph_from_cache(cache, options = { verbose: false })
8
14
  graph = new cache, options
9
15
  graph.build
10
16
  graph.graph
11
17
  end
12
18
 
13
- # Initialies a graph build with a cache
19
+ # Initialies a graph build with a cache and options.
20
+ #
21
+ # @param cache [Cache] The cache to generate the graph from.
22
+ # @param options [Hash] The options to use.
14
23
  def initialize(cache, options = { verbose: false })
15
24
  @graph = Solve::Graph.new
16
25
  @options = options
@@ -18,6 +27,8 @@ module ElmInstall
18
27
  end
19
28
 
20
29
  # Builds the graph.
30
+ #
31
+ # @return [void]
21
32
  def build
22
33
  @cache.each do |package, versions|
23
34
  add_versions package, versions
@@ -9,9 +9,9 @@ module ElmInstall
9
9
  # file and populating the `elm-stuff` directory with the packages and
10
10
  # writing the `elm-stuff/exact-dependencies.json`.
11
11
  class Installer
12
- extend Forwardable
13
-
14
12
  # Initializes a new installer with the given options.
13
+ #
14
+ # @param options [Hash] The options
15
15
  def initialize(options)
16
16
  init_options options
17
17
  @git_resolver = GitResolver.new directory: cache_directory
@@ -20,11 +20,19 @@ module ElmInstall
20
20
  @options = options
21
21
  end
22
22
 
23
+ # Initializes the options setting default values.
24
+ #
25
+ # @param options [Hash] The options
26
+ #
27
+ # @return [Hash] The options
23
28
  def init_options(options = { verbose: false })
24
29
  options[:cache_directory] ||= File.join(Dir.home, '.elm-install')
25
30
  @options = options
26
31
  end
27
32
 
33
+ # Returns the path to the cache directory
34
+ #
35
+ # @return [String] The path
28
36
  def cache_directory
29
37
  @options[:cache_directory]
30
38
  end
@@ -32,6 +40,8 @@ module ElmInstall
32
40
  # Executes the installation
33
41
  #
34
42
  # :reek:TooManyStatements { max_statements: 7 }
43
+ #
44
+ # @return [void]
35
45
  def install
36
46
  puts 'Resolving packages...'
37
47
  resolver.add_constraints dependencies
@@ -42,12 +52,18 @@ module ElmInstall
42
52
  retry_install
43
53
  end
44
54
 
55
+ # Saves the caches
56
+ #
57
+ # @return [void]
45
58
  def save
46
59
  puts 'Saving package cache...'
47
60
  @git_resolver.save
48
61
  @cache.save
49
62
  end
50
63
 
64
+ # Clears the reference cache and retries installation.
65
+ #
66
+ # @return [void]
51
67
  def retry_install
52
68
  Logger.arrow(
53
69
  'Could not find a solution in local cache, refreshing packages...'
@@ -66,6 +82,8 @@ module ElmInstall
66
82
 
67
83
  # Populates the `elm-stuff` directory with the packages from
68
84
  # the solution.
85
+ #
86
+ # @return [void]
69
87
  def populate_elm_stuff
70
88
  save
71
89
  @populator.populate calculate_solution
@@ -73,11 +91,15 @@ module ElmInstall
73
91
  end
74
92
 
75
93
  # Returns the resolver to calculate the solution.
94
+ #
95
+ # @return [Resolver] The resolver
76
96
  def resolver
77
97
  @resolver ||= Resolver.new @cache, @git_resolver
78
98
  end
79
99
 
80
100
  # Returns the solution for the given `elm-package.json` file.
101
+ #
102
+ # @return [Hash] The solution
81
103
  def calculate_solution
82
104
  Solve.it!(
83
105
  GraphBuilder.graph_from_cache(@cache, @options),
@@ -85,6 +107,9 @@ module ElmInstall
85
107
  )
86
108
  end
87
109
 
110
+ # Returns the dependencies form `elm-package.json`.
111
+ #
112
+ # @return [Hash] The dependencies
88
113
  def dependencies
89
114
  @dependencies ||= ElmPackage.dependencies 'elm-package.json'
90
115
  end
@@ -2,10 +2,20 @@ module ElmInstall
2
2
  # This is a helper module for logging.
3
3
  module Logger
4
4
  # :nocov:
5
+ # Logs the given message prefixed a green dot.
6
+ #
7
+ # @param message [String] The message to log
8
+ #
9
+ # @return [void]
5
10
  def self.dot(message)
6
11
  puts ' ● '.green + message
7
12
  end
8
13
 
14
+ # Logs the given message prefixed an arrow.
15
+ #
16
+ # @param message [String] The message to log
17
+ #
18
+ # @return [void]
9
19
  def self.arrow(message)
10
20
  puts " ▶ #{message}"
11
21
  end
@@ -1,10 +1,18 @@
1
1
  module ElmInstall
2
2
  # This class is responsible for populating the `elm-stuff` directory.
3
3
  class Populator
4
+ # Initializes a new populator.
5
+ #
6
+ # @param git_resolver [GitResolver] The git resolver to use.
4
7
  def initialize(git_resolver)
5
8
  @git_resolver = git_resolver
6
9
  end
7
10
 
11
+ # Populates `elm-stuff` from the given solution.
12
+ #
13
+ # @param solution [Hash] The solution.
14
+ #
15
+ # @return [void]
8
16
  def populate(solution)
9
17
  solution.each do |package, version|
10
18
  resolve_package package, version
@@ -17,22 +25,13 @@ module ElmInstall
17
25
  # directory.
18
26
  #
19
27
  # :reek:TooManyStatements { max_statements: 9 }
28
+ #
29
+ # @param package [String] The package
30
+ # @param version_str [String] The resolved version
31
+ #
32
+ # @return [void]
20
33
  def resolve_package(package, version_str)
21
- match = version_str.match /(.+)\+(.+)/
22
-
23
- version =
24
- if match
25
- match[1]
26
- else
27
- version_str
28
- end
29
-
30
- ref =
31
- if match
32
- match[2]
33
- else
34
- version_str
35
- end
34
+ version, ref = self.class.version_and_ref(version_str)
36
35
 
37
36
  package_name, package_path = Utils.package_version_path package, version
38
37
 
@@ -46,6 +45,11 @@ module ElmInstall
46
45
  end
47
46
 
48
47
  # Copies the given package from it's repository to the given path.
48
+ #
49
+ # @param package [String] The package to copy
50
+ # @param package_path [String] The destination
51
+ #
52
+ # @return [void]
49
53
  def copy_package(package, package_path)
50
54
  repository_path = File.join(@git_resolver.repository_path(package), '.')
51
55
 
@@ -55,6 +59,10 @@ module ElmInstall
55
59
  end
56
60
 
57
61
  # Writes the `elm-stuff/exact-dependencies.json` file.
62
+ #
63
+ # @param solution [Hash] The solution
64
+ #
65
+ # @return [void]
58
66
  def write_exact_dependencies(solution)
59
67
  File.binwrite(
60
68
  File.join('elm-stuff', 'exact-dependencies.json'),
@@ -63,19 +71,30 @@ module ElmInstall
63
71
  end
64
72
 
65
73
  # Returns the exact dependencies from the solution.
74
+ #
75
+ # @param solution [Hash] The solution
76
+ #
77
+ # @return [void]
66
78
  def self.exact_dependencies(solution)
67
79
  solution.each_with_object({}) do |(key, value), memo|
68
- match = value.match /(.+)\+(.+)/
69
-
70
- version =
71
- if match
72
- match[1]
73
- else
74
- value
75
- end
80
+ version, = version_and_ref value
76
81
 
77
82
  memo[GitCloneUrl.parse(key).path.sub(%r{^/}, '')] = version
78
83
  end
79
84
  end
85
+
86
+ # Retruns the version and the ref from the given string.
87
+ #
88
+ # @param value [String] The input
89
+ #
90
+ # @return [Array] The version and the ref as an array
91
+ def self.version_and_ref(value)
92
+ match = value.match(/(.+)\+(.+)/)
93
+
94
+ version = match ? match[1] : value
95
+ ref = match ? match[2] : value
96
+
97
+ [version, ref]
98
+ end
80
99
  end
81
100
  end
@@ -4,9 +4,13 @@ require_relative './utils'
4
4
  module ElmInstall
5
5
  # Resolves git dependencies into the cache.
6
6
  class Resolver
7
+ # @return [Array] The constraints
7
8
  attr_reader :constraints
8
9
 
9
- # Initializes a resolver for a chace.
10
+ # Initializes a resolver with a chace and git resolver.
11
+ #
12
+ # @param cache [Cache] The cache
13
+ # @param git_resolver [GitResolver] The git resolver
10
14
  def initialize(cache, git_resolver)
11
15
  @git_resolver = git_resolver
12
16
  @constraints = []
@@ -14,6 +18,10 @@ module ElmInstall
14
18
  end
15
19
 
16
20
  # Add constraints, usually from the `elm-package.json`.
21
+ #
22
+ # @param constraints [Hash] The constraints
23
+ #
24
+ # @return [void]
17
25
  def add_constraints(constraints)
18
26
  @constraints = add_dependencies(constraints) do |package, constraint|
19
27
  [package, constraint]
@@ -23,7 +31,11 @@ module ElmInstall
23
31
  # Adds dependencies, usually from any `elm-package.json` file.
24
32
  #
25
33
  # :reek:NestedIterators { max_allowed_nesting: 2 }
26
- # :reek:TooManyStatements { max_statements: 6 }
34
+ #
35
+ # @param dependencies [Hash] The dependencies
36
+ #
37
+ # @yieldreturn [Array] A constraint
38
+ # @return [void]
27
39
  def add_dependencies(dependencies)
28
40
  dependencies.flat_map do |package, constraint|
29
41
  add_package(package)
@@ -38,15 +50,17 @@ module ElmInstall
38
50
  end
39
51
 
40
52
  # Adds a dependency by git reference.
53
+ #
54
+ # @param package [String] The package
55
+ # @param ref [String] The reference
56
+ #
57
+ # @return [void]
41
58
  def add_ref_dependency(package, ref)
42
59
  @git_resolver.repository(package).checkout(ref)
43
60
  pkg_version = elm_package(package)['version']
44
61
  version = "#{pkg_version}+#{ref}"
45
62
  @cache.ensure_version(package, version)
46
- add_dependencies(elm_dependencies(package)) do |dep_package, constraint|
47
- add_package(dep_package)
48
- @cache.dependency(package, version, [dep_package, constraint])
49
- end
63
+ add_package_dependencies(package, version)
50
64
  [[package, "= #{version}"]]
51
65
  end
52
66
 
@@ -55,6 +69,10 @@ module ElmInstall
55
69
  # * Getting all the tags and adding the valid ones to the cache
56
70
  # * Checking out and getting the `elm-package.json` for each version
57
71
  # and adding them recursivly
72
+ #
73
+ # @param package [String] The package
74
+ #
75
+ # @return [void]
58
76
  def add_package(package)
59
77
  return if @git_resolver.package?(package) && @cache.key?(package)
60
78
 
@@ -68,29 +86,58 @@ module ElmInstall
68
86
  end
69
87
  end
70
88
 
89
+ # Adds a package's dependencies to the cache.
90
+ #
91
+ # @param package [String] The package
92
+ # @param version [String] The version
93
+ #
94
+ # @return [void]
95
+ def add_package_dependencies(package, version)
96
+ add_dependencies(elm_dependencies(package)) do |dep_package, constraint|
97
+ add_package(dep_package)
98
+ @cache.dependency(package, version, [dep_package, constraint])
99
+ end
100
+ end
101
+
71
102
  # Adds a version and it's dependencies to the cache.
103
+ #
104
+ # @param package [String] The package
105
+ # @param version [String] The version
106
+ #
107
+ # @return [void]
72
108
  def add_version(package, version)
73
109
  @git_resolver
74
110
  .repository(package)
75
111
  .checkout(version)
76
112
 
77
- add_dependencies(elm_dependencies(package)) do |dep_package, constraint|
78
- add_package(dep_package)
79
- @cache.dependency(package, version, [dep_package, constraint])
80
- end
113
+ add_package_dependencies(package, version)
81
114
  end
82
115
 
83
116
  # Gets the `elm-package.json` for a package.
117
+ #
118
+ # @param package [String] The package
119
+ #
120
+ # @return [Hash] The dependencies
84
121
  def elm_dependencies(package)
85
122
  ElmPackage.dependencies elm_package_path(package)
86
123
  rescue
87
- []
124
+ {}
88
125
  end
89
126
 
127
+ # Retruns the contents of the `elm-pacakge.json` of the given package.
128
+ #
129
+ # @param package [String] The package
130
+ #
131
+ # @return [Hash] The contents
90
132
  def elm_package(package)
91
133
  ElmPackage.read elm_package_path(package)
92
134
  end
93
135
 
136
+ # Retruns the path of the `elm-pacakge.json` of the given package.
137
+ #
138
+ # @param package [String] The package
139
+ #
140
+ # @return [String] The path
94
141
  def elm_package_path(package)
95
142
  File.join(@git_resolver.repository_path(package), 'elm-package.json')
96
143
  end
@@ -3,6 +3,7 @@ module ElmInstall
3
3
  module Utils
4
4
  module_function
5
5
 
6
+ # Regexes for converting constraints.
6
7
  CONVERTERS = {
7
8
  /v<(?!=)(.*)/ => '<',
8
9
  /(.*)<=v/ => '>=',
@@ -10,6 +11,11 @@ module ElmInstall
10
11
  /(.*)<v/ => '>'
11
12
  }.freeze
12
13
 
14
+ # Transform constraints form Elm's package format to semver's.
15
+ #
16
+ # @param constraint [String] The input constraint
17
+ #
18
+ # @return [Array] The output constraints
13
19
  def transform_constraint(constraint)
14
20
  constraint.gsub!(/\s/, '')
15
21
 
@@ -19,6 +25,12 @@ module ElmInstall
19
25
  end.compact
20
26
  end
21
27
 
28
+ # Returns the path for a package with the given version.
29
+ #
30
+ # @param package [String] The package
31
+ # @param version [String] The version
32
+ #
33
+ # @return [Strin] The path
22
34
  def package_version_path(package, version)
23
35
  package_name = GitCloneUrl.parse(package).path.sub(%r{^/}, '')
24
36
  [package_name, File.join('elm-stuff', 'packages', package_name, version)]
@@ -1,3 +1,4 @@
1
1
  module ElmInstall
2
- VERSION = '0.1.2'.freeze
2
+ # The version of ElmInstall
3
+ VERSION = '0.1.3'.freeze
3
4
  end
@@ -3,11 +3,12 @@ GEM
3
3
  specs:
4
4
  commander (4.4.2)
5
5
  highline (~> 1.7.2)
6
- elm_install (0.1.1)
6
+ elm_install (0.1.2)
7
7
  commander (~> 4.4, >= 4.4.2)
8
8
  git (~> 1.3)
9
9
  git_clone_url (~> 2.0)
10
10
  hashdiff (~> 0.3.1)
11
+ indentation (~> 0.1.1)
11
12
  smart_colored (~> 1.1, >= 1.1.1)
12
13
  solve (~> 3.1)
13
14
  git (1.3.0)
@@ -15,6 +16,7 @@ GEM
15
16
  uri-ssh_git (>= 2.0)
16
17
  hashdiff (0.3.1)
17
18
  highline (1.7.8)
19
+ indentation (0.1.1)
18
20
  molinillo (0.5.4)
19
21
  semverse (2.0.0)
20
22
  smart_colored (1.1.1)
@@ -33,4 +35,4 @@ RUBY VERSION
33
35
  ruby 2.2.2p95
34
36
 
35
37
  BUNDLED WITH
36
- 1.13.6
38
+ 1.13.7
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: elm_install
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusztáv Szikszai
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-26 00:00:00.000000000 Z
11
+ date: 2016-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -188,3 +188,4 @@ signing_key:
188
188
  specification_version: 4
189
189
  summary: Install Elm packages from git repositories.
190
190
  test_files: []
191
+ has_rdoc: