tangle 0.8.1 → 0.8.2

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
  SHA256:
3
- metadata.gz: efb56e340da69ed1ce24355b02a36f0f630895889084e4784e2313d9b576aa07
4
- data.tar.gz: 13c17c0ab9687c0e559b733cb006e3eac83fda8d3e7e8a6c7470c558dc35e9ea
3
+ metadata.gz: 7ee56b345a6f81de14bbc7bb9d16fbb10f9e2174b2588140a6881bd1ff31d0d5
4
+ data.tar.gz: 2172244bbb6ab3a91dff9fb4e6491fadc1f56762d984edf75c7f325b1ce9bed5
5
5
  SHA512:
6
- metadata.gz: 0c4431ab32f47bc77c90354857c39efe4623b090a3bc77f5e01a7490b79925d708429fa2abfe9beead93ff97a70b06de82a1bb8f505d3b84cb9b2cddabaed45c
7
- data.tar.gz: b12e907d5bb60f4940a01965c9088264e14b2b60511c1643dc6f9fb6d22953e14a5692e7a79c84121e89dfa99754ae2a8be16f36453eae1357e5f8678060f71a
6
+ metadata.gz: 7bb4eeacbdf97538cef1a19738ac0260e47b56a19a6854d2de4dd735203001f7000f09239fbd3d6dcce377d8acf24a3b9647f1ddbbb2c152129b16e78de5fb16
7
+ data.tar.gz: 71837d3d43769c939200f450fb823ce6e82aec754527989e93ffac3db58eac2a8a99c816c9afc648dbbf97bf101b63e78656af86e487f6d3568f40333e2fa078
data/.rubocop.yml CHANGED
@@ -5,3 +5,8 @@ Metrics/BlockLength:
5
5
  Style/BlockDelimiters:
6
6
  Exclude:
7
7
  - 'spec/*_spec.rb'
8
+
9
+ # Rubocop 0.56 causes false positives
10
+ # https://github.com/bbatsov/rubocop/issues/5887
11
+ Lint/SplatKeywordArguments:
12
+ Enabled: false
data/Rakefile CHANGED
@@ -1,14 +1,26 @@
1
1
  require 'bundler/setup'
2
2
  require 'bundler/gem_tasks'
3
3
 
4
- desc 'Run RuboCop'
5
4
  require 'rubocop/rake_task'
6
- RuboCop::RakeTask.new(:rubocop) do |task|
5
+ RuboCop::RakeTask.new do |task|
7
6
  task.options << '--display-cop-names'
8
7
  end
9
8
 
10
- desc 'Run RSpec'
11
9
  require 'rspec/core/rake_task'
12
- RSpec::Core::RakeTask.new(:spec)
10
+ RSpec::Core::RakeTask.new
13
11
 
14
- task default: %i[rubocop spec]
12
+ desc 'Run Fasterer'
13
+ task :fasterer do
14
+ require 'fasterer/cli'
15
+ Fasterer::CLI.execute
16
+ end
17
+
18
+ desc 'Check if version is fit for release'
19
+ task :check_version do
20
+ raise 'Internal revision!' unless GVB.internal_revision.empty?
21
+ end
22
+
23
+ task test: %i[spec rubocop]
24
+ task build: %i[spec]
25
+ task release: %i[rubocop check_version]
26
+ task default: %i[test]
@@ -16,7 +16,7 @@ module Tangle
16
16
 
17
17
  # Return the direct predecessors of +vertex+
18
18
  def direct_predecessors(vertex)
19
- Set.new(in_edges(vertex).map(&:tail))
19
+ in_edges(vertex).map(&:tail).to_set
20
20
  end
21
21
 
22
22
  # Is +other+ a direct predecessor of +vertex+?
@@ -31,7 +31,7 @@ module Tangle
31
31
 
32
32
  # Is +other+ a predecessor of +vertex+?
33
33
  def predecessor?(vertex, other)
34
- predecessors(vertex).include?(other)
34
+ predecessors(vertex).any? { |vtx| other.eql?(vtx) }
35
35
  end
36
36
 
37
37
  # Return a subgraph with all predecessors of a +vertex+
@@ -46,7 +46,7 @@ module Tangle
46
46
 
47
47
  # Return the direct successors of +vertex+
48
48
  def direct_successors(vertex)
49
- Set.new(out_edges(vertex).map(&:head))
49
+ out_edges(vertex).map(&:head).to_set
50
50
  end
51
51
 
52
52
  # Is +other+ a direct successor of +vertex+?
@@ -61,7 +61,7 @@ module Tangle
61
61
 
62
62
  # Is +other+ a successor of +vertex+?
63
63
  def successor?(vertex, other)
64
- successors(vertex).include?(other)
64
+ successors(vertex).any? { |vtx| other.eql?(vtx) }
65
65
  end
66
66
 
67
67
  # Return a subgraph with all successors of a +vertex+
@@ -3,14 +3,27 @@ require 'set'
3
3
  module Tangle
4
4
  # Vertex related methods in a graph
5
5
  module GraphVertices
6
+ # Fetch a vertex by its name
7
+ def fetch(name)
8
+ @vertices_by_name.fetch(name)
9
+ end
10
+
11
+ # Return a named vertex
12
+ def [](name)
13
+ @vertices_by_name[name]
14
+ end
15
+
6
16
  # Return all vertices in the graph
7
17
  def vertices
8
18
  @vertices.keys
9
19
  end
10
20
 
11
21
  # Add a vertex into the graph
12
- def add_vertex(vertex)
22
+ #
23
+ # If a name: is given, it will be registered by name
24
+ def add_vertex(vertex, name: nil)
13
25
  @vertices[vertex] = Set[]
26
+ @vertices_by_name[name] = vertex unless name.nil?
14
27
  self
15
28
  end
16
29
  alias << add_vertex
@@ -28,6 +41,7 @@ module Tangle
28
41
  # Initialize vertex related attributes
29
42
  def initialize_vertices
30
43
  @vertices = {}
44
+ @vertices_by_name = {}
31
45
  end
32
46
 
33
47
  # Yield each reachable vertex to a block, breadth first
@@ -0,0 +1,55 @@
1
+ module Tangle
2
+ module Mixin
3
+ # Tangle mixin for loading a directory structure as a graph
4
+ #
5
+ # Graph.new(directory: { options })
6
+ #
7
+ # options are:
8
+ # root: root directory for the structure (mandatory)
9
+ # loaders: list of object loader lambdas (mandatory)
10
+ # follow_links: bool for following symlinks to directories
11
+ # (default false)
12
+ #
13
+ # A loader lambda will be called like
14
+ # ->(graph, path, parent_path) { ... }
15
+ #
16
+ # The lambdas are called in order until one returns true
17
+ #
18
+ # Example:
19
+ # loader = lambda do |g, path, parent|
20
+ # vertex = File::Stat.new(path)
21
+ # g.add_vertex(vertex, name: path)
22
+ # g.add_edge(g[parent], vertex) unless parent.nil?
23
+ # end
24
+ # Tangle::DiGraph.new(mixins: [Tangle::Mixins::Directory],
25
+ # directory: { root: '.', loaders: [loader] })
26
+ module Directory
27
+ # Tangle::Graph mixin for loading a directory structure
28
+ module Graph
29
+ attr_reader :root_directory
30
+
31
+ private
32
+
33
+ def initialize_kwarg_directory(**options)
34
+ @root_directory = options.fetch(:root)
35
+ @directory_loaders = options.fetch(:loaders)
36
+ @follow_directory_links = options[:follow_links]
37
+ load_directory_graph(@root_directory)
38
+ end
39
+
40
+ def load_directory_graph(path, parent = nil)
41
+ @directory_loaders.any? do |loader|
42
+ loader.to_proc.call(self, path, parent)
43
+ end
44
+
45
+ return if File.symlink?(path) && !@follow_directory_links
46
+ return unless File.directory?(path)
47
+
48
+ Dir.each_child(path) do |file|
49
+ load_directory_graph(File.join(path, file), path)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
data/tangle.gemspec CHANGED
@@ -24,6 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'git-version-bump', '~> 0.15'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.16'
27
+ spec.add_development_dependency 'fasterer', '~> 0.4'
27
28
  spec.add_development_dependency 'rake', '~> 10.0'
28
29
  spec.add_development_dependency 'rspec', '~> 3.0'
29
30
  spec.add_development_dependency 'rubocop', '~> 0.52'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tangle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calle Englund
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-14 00:00:00.000000000 Z
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git-version-bump
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fasterer
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.4'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -110,6 +124,7 @@ files:
110
124
  - lib/tangle/graph_vertices.rb
111
125
  - lib/tangle/mixin.rb
112
126
  - lib/tangle/mixin/connectedness.rb
127
+ - lib/tangle/mixin/directory.rb
113
128
  - lib/tangle/simple/graph.rb
114
129
  - lib/tangle/version.rb
115
130
  - tangle.gemspec