drain 0.3.0 → 0.7.0

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: 5c577f08df5d0dd378a335824250d97008d3eb24896d101ecc1ed51a2281a1f0
4
- data.tar.gz: f35b4fd99afb4870ddb44991b776ef8e5621739d7d83d7ba4d9ae851b2713df1
3
+ metadata.gz: 8da4d9b373952c13931d7ed377565f1cd60297107413a4230f3cbdc2481af952
4
+ data.tar.gz: ba54f1c1946487b37916d0d6e0a14542d273f3dccd5f86109586cd275d8d2e32
5
5
  SHA512:
6
- metadata.gz: a889f20d3499a98ddc6da50f8cc14201881cf695271b250730ebc26024e657f2af2f7764f5e078979029559dd1dea3745a60a9df9c40ae8d5fc64f7903948a1e
7
- data.tar.gz: 1a95a1661230282f9339258e1b6a241bd4fe2e503fbb9f43ea20c220e220a093903356cd8e78fd36e62899189b919a5a4ee50a3261951fdfde1bceebb91cbae1
6
+ metadata.gz: 97028489d945221d6aed71741954a1dec636d2961cf8fa6c22988fa447e8c5548d8450f3c8f0d5dd9d2f25d35ad0e54a7a1d485cf1af667e8f47a462afe86538
7
+ data.tar.gz: bbd72c1baaf24811cc950c7003ec9d5911dadd73ee38cce08d2c80191376f17066e3494ce7b3d63556219fb35af6f30a9a4cdf99d33d3a29302cf87c64d736ae
@@ -0,0 +1,25 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+ jobs:
5
+ test:
6
+ strategy:
7
+ fail-fast: false
8
+ matrix:
9
+ os: [ ubuntu-latest, macos-latest ]
10
+ ruby: [ 2.3, 2.4, 2.5, 2.6, 2.7, jruby, truffleruby ]
11
+ runs-on: ${{ matrix.os }}
12
+ steps:
13
+ - name: 'Git checkout'
14
+ uses: actions/checkout@v2
15
+ - name: 'Setup ruby'
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: 'Install bundler and gems'
20
+ run: |
21
+ gem install bundler
22
+ bundle install --jobs 4 --retry 3
23
+ - name: "Run tests"
24
+ run: |
25
+ bundle exec rake test
@@ -1,9 +1,13 @@
1
1
  ---
2
2
  language: ruby
3
3
  rvm:
4
- - 2.5.1
5
- - 2.4.4
6
- - 2.3.7
4
+ - 2.7.0
5
+ - 2.6.5
6
+ - 2.5.7
7
+ - 2.4.9
8
+ - 2.3.8 #eol, but still used in debian
9
+ #- 2.2.10
10
+ #- 2.1.10
7
11
  #- ruby-head
8
12
  #- ruby-head-clang
9
13
  script: rake test
@@ -1,4 +1,161 @@
1
- ### 0.1.0 / 2015-02-24
1
+ == Release v0.7.0 (2020-07-09) ==
2
2
 
3
- * Initial release:
3
+ * Update test for new uri.rb API
4
+ * uri.rb: Add alias
5
+ * DR::URI
6
+ * utils.rb: switch to amazing_print
7
+ * graph.rb: <<
8
+
9
+ == Release v0.6.0 (2020-02-26) ==
10
+
11
+ * Add github actions for tests
12
+ * Add github action for tests
13
+ * Bump travis versions
14
+ * Fix ruby 2.7 warning
15
+ * graph.rb: add merge! and merge
16
+ * test: fix minitest warnings
17
+ * gemspec: add chronic and chronic_duration
18
+
19
+ == Release v0.5.1 (2020-02-18) ==
20
+
21
+ * DR::URI -> DR::URIEscape
22
+
23
+ == Release v0.5 (2020-02-18) ==
24
+
25
+ * Bump version
26
+ * DR::URI.escape
27
+ * Fixes for ruby 2.7
28
+ * URI.encode is obsolete
29
+
30
+ == Release v0.4 (2019-09-13) ==
31
+
32
+ * Bump version
33
+ * Delegator.access_methods
34
+ * delegate: add missing require
35
+ * Delegator.delegate_h
36
+ * Fix a bug in deep_merge
37
+ * Utils: pretty = true means color by default
38
+ * Utils: PPHelper and pretty_print colors
39
+ * time_parse: do not load active_support/time
40
+ * Fix test failures
41
+ * Update Rakefile
42
+ * Update Rakefile
43
+ * Comments
44
+ * graph: to_s and inspect
45
+ * Doc: add warning
46
+
47
+ == Release v0.3.0 (2018-09-07) ==
48
+
49
+ * Bump version
50
+ * test_date_parse.rb: set TZ to GMT to get test working on travis
51
+ * Update travis
52
+ * Utils.rsplit
53
+ * Formatter: clean ups
54
+ * simple_formatter: ability to expand messages
55
+ * Fix test
56
+ * Ad formatter/simple_formatter
57
+ * simple_keywords: strip by default + can now change delims
58
+ * simple_keywords: switch from a Module to a Class
59
+ * parse/simple_keywords
60
+ * URI: rename to_s to to_ssh
61
+ * URI::Ssh.parse: handle empty string
62
+ * SSH Uri: allow non standard hosts
63
+ * Hash#has_keys: bug fix
64
+ * URIWrapper::Ssh
65
+ * Hash#has_keys?
66
+ * Hash#add_to_key: configure behavior via keywords
67
+ * Hash#add_to_key, Hash#set_key
68
+ * Hash#deep_merge: configure how to merge arrays
69
+ * Hash#add_key
70
+ * Hash: add_key, dig_with_default
71
+ * bool.rb: allow to keep Strings/Symbols
72
+ * slice_with_default
73
+ * simple_parser: more parsing methods
74
+ * bool: bug fixes
75
+ * Copyright
76
+ * Hash#reverse_merge
77
+ * Graph#dump: be more flexible to how we dump
78
+ * Graph: allow to merge with a Hash
79
+ * to_caml_case and to_snake_case
80
+ * pretty_print: preserve options
81
+ * base: uri
82
+
83
+ == Release v0.2.0 (2018-02-01) ==
84
+
85
+ * Bump version
86
+ * Update tests
87
+ * utils: pretty_print
88
+ * eruby: add Eruby.process_eruby
89
+ * Eruby: indent Context the same way as other modules
90
+ * Move git.rb to git_helpers
91
+ * fix somg bug in refinements usage
92
+ * tests + more comments
93
+ * graph: Add Graph.build
94
+ * eruby: comments about a possible ruby bug fix in 2.4.1
95
+ * graph: allow to merge graphs
96
+ * graph: bug fixes
97
+ * Eruby: automatically wrap into unbound_instance if a block is passed
98
+ * eruby: streamline implementation and bug fixes
99
+ * eruby: more template possibilities
100
+ * eruby.rb: start adding features from Tilt
101
+ * Eruby: be uniform accross erubi/erubis/erb
102
+ * Clean up comments
103
+ * test_drain: test for Drain::VERSION
104
+ * Add drain.rb which calls dr.rb
105
+ * travis: test agains ruby HEAD
106
+ * Update drain.gemspec
107
+ * Configure travis and streamline rake and test files
108
+ * simple_parser: renders globalopts fully customisable
109
+ * I don't need bundler for travis
110
+ * travis
111
+ * gitignore
112
+ * Try to do a minimal example for ruby's segfault
113
+ * descendants/ancestors: propagate ourselves
114
+ * Correct a bug in graph.rb
115
+ * parse_string: allows to customize the splitting characters
116
+ * Remove Hash#set_keyed_value!
117
+ * Hash#set_keyed_value
118
+ * Copyright
119
+ * simple_parser: document the splitting order
120
+ * simple_parser: add tests
121
+ * Add missing require
122
+ * graph: allow ancestors and descendants on a node
123
+ * Deprecation warning
124
+ * Copyright
125
+ * tests + comments
126
+ * Still more tests for core_ext.rb
127
+ * Still more tests
128
+ * More tests
129
+ * Test Hash#deep_merge
130
+ * Add tests
131
+ * Useless use of slef
132
+ * Converter: test on recursive object
133
+ * git: get config
134
+ * Add Hash#leafs
135
+ * Add to_h to graph
136
+ * graph construction now accepts a lambda
137
+ * Add hash conversion ton graph.rb
138
+ * Add converter.rb (converts an object to an hash) and tests
139
+ * graph: add .compact in to_nodes
140
+ * graph: method to updat node attributes
141
+ * graph: show attributes
142
+ * Graph: improved unneeded, and bug fix in unneeded_descendants
143
+ * Graph#connected: bug fix
144
+ * Graph: check that children are of the same type
145
+ * Refinements: fix syntax errors
146
+ * unneeded_descendants(ancestors) is bigger than ancestors(unneeded_descendants)
147
+ * graph: bug fixes
148
+ * Use dr rather than drain for brevity
149
+ * Graph.rb
150
+ * Git: add a submodules command
151
+ * Graph#build_node
152
+ * Rework Graph#build
153
+ * Test includes_extends_host_with
154
+ * Split core_ext into two files
155
+
156
+ == Release v0.1.0 (2015-02-24) ==
157
+
158
+ * Description
159
+ * Add library files
160
+ * Initial commit.
4
161
 
data/Gemfile CHANGED
@@ -2,6 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
- group :development do
5
+ group :extra_devel do
6
+ gem 'minitest-reporters', '~> 1.4'
7
+ gem 'yard', '~> 0.9'
6
8
  gem 'kramdown'
9
+ gem 'rubygems-tasks', '~> 0.2'
7
10
  end
@@ -1,4 +1,4 @@
1
- Copyright © 2015–2018 Damien Robert
1
+ Copyright © 2015–2020 Damien Robert
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -3,9 +3,10 @@
3
3
  * [Homepage](https://github.com/DamienRobert/drain#readme)
4
4
  * [Issues](https://github.com/DamienRobert/drain/issues)
5
5
  * [Documentation](http://rubydoc.info/gems/drain)
6
- * [Email](mailto:Damien.Olivier.Robert+gems at gmail.com)
6
+ * [Email](mailto:Damien.Olivier.Robert+gems@gmail.com)
7
7
 
8
8
  [![Gem Version](https://img.shields.io/gem/v/drain.svg)](https://rubygems.org/gems/drain)
9
+ [![Ruby test result](https://github.com/DamienRobert/drain/workflows/Ruby/badge.svg)](https://github.com/DamienRobert/drain/actions?query=workflow%3ARuby)
9
10
  [![Build Status](https://travis-ci.org/DamienRobert/drain.svg?branch=master)](https://travis-ci.org/DamienRobert/drain)
10
11
 
11
12
  ## Description
@@ -17,15 +18,25 @@ The Api is far from stable yet, so use at your own risk!
17
18
 
18
19
  For now the API is experimental and some parts are not ready to use!
19
20
 
21
+ ## Examples
22
+
23
+ ~~~ ruby
24
+ require 'drain'
25
+ ~~~
26
+
27
+ ## Requirements
28
+
20
29
  ## Install
21
30
 
31
+ ~~~ sh
22
32
  $ gem install drain
33
+ ~~~
23
34
 
24
35
  ## Copyright
25
36
 
26
- Copyright © 2015–2018 Damien Robert
37
+ Copyright © 2015–2020 Damien Robert
27
38
 
28
- MIT License. See [LICENSE.txt](./LICENSE.txt) for details.
39
+ MIT License. See [`LICENSE.txt`](LICENSE.txt) for details.
29
40
 
30
41
  Some of the code is inspired by other project, in general I give proper
31
42
  acknowledgement in the corresponding file.
data/Rakefile CHANGED
@@ -1,15 +1,11 @@
1
+ ## Uncomment to use `rake` directly rather than `bundle exec rake`
2
+ #begin
3
+ # require 'bundler/setup'
4
+ #rescue LoadError => e
5
+ # warn "Could not setup bundler: #{e.message}"
6
+ #end
1
7
  require 'rake'
2
8
 
3
- begin
4
- require 'rubygems/tasks'
5
- Gem::Tasks.new(sign: {checksum: true, pgp: true},
6
- scm: {status: true}) do |tasks|
7
- tasks.console.command = 'pry'
8
- end
9
- rescue LoadError => e
10
- warn e.message
11
- end
12
-
13
9
  require 'rake/testtask'
14
10
  Rake::TestTask.new do |test|
15
11
  test.libs << 'test'
@@ -25,5 +21,14 @@ rescue LoadError => e
25
21
  warn e.message
26
22
  end
27
23
  end
24
+ desc 'Generate docs'
28
25
  task :doc => :yard
29
26
 
27
+ begin
28
+ require 'dr/rake_gems'
29
+ Gem::MyTasks.new
30
+ rescue LoadError => e
31
+ warn e.message
32
+ end
33
+
34
+ task :default => :test
@@ -33,6 +33,7 @@ Gem::Specification.new do |gem|
33
33
  end
34
34
  end
35
35
  gem.files = glob[gemspec['files']] if gemspec['files']
36
+ gem.files = gem.files + gemspec['extra_files'] if gemspec['extra_files']
36
37
 
37
38
  gem.executables = gemspec.fetch('executables') do
38
39
  glob['bin/*'].map { |path| File.basename(path) }
@@ -9,6 +9,6 @@ homepage: https://github.com/DamienRobert/drain#readme
9
9
 
10
10
  development_dependencies:
11
11
  minitest: "~> 5.0"
12
- rake: "~> 10"
13
- rubygems-tasks: "~> 0.2"
14
- yard: "~> 0.8"
12
+ rake: ">= 10"
13
+ chronic: "~> 0.10"
14
+ chronic_duration: "~> 0.10"
@@ -0,0 +1,28 @@
1
+ module DR
2
+ module Delegator
3
+ extend self
4
+ def delegate_h(klass, var)
5
+ require 'forwardable'
6
+ # put in a Module so that they are easier to distinguish from the
7
+ # 'real' functions
8
+ m=Module.new do
9
+ extend(Forwardable)
10
+ methods=[:[], :[]=, :any?, :assoc, :clear, :compact, :compact!, :delete, :delete_if, :dig, :each, :each_key, :each_pair, :each_value, :empty?, :fetch, :fetch_values, :has_key?, :has_value?, :include?, :index, :invert, :keep_if, :key, :key?, :keys, :length, :member?, :merge, :merge!, :rassoc, :reject, :reject!, :select, :select!, :shift, :size, :slice, :store, :to_a, :to_h, :to_s, :transform_keys, :transform_keys!, :transform_values, :transform_values!, :update, :value?, :values, :values_at]
11
+ include(Enumerable)
12
+ def_delegators var, *methods
13
+ end
14
+ klass.include(m)
15
+ end
16
+
17
+ def access_methods(klass, var, *methods)
18
+ methods.each do |k|
19
+ klass.define_method k do
20
+ instance_variable_get(var)[k]
21
+ end
22
+ klass.defined_method :"#{k}=" do |*args|
23
+ instance_variable_get(var).send(:[]=, k, *args)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -7,7 +7,7 @@ module DR
7
7
  attr_reader :graph
8
8
  attr_accessor :name, :attributes, :parents, :children
9
9
  def initialize(name, attributes: {}, graph: nil)
10
- @name = name.to_s
10
+ @name = name
11
11
  @children = []
12
12
  @parents = []
13
13
  @attributes = attributes
@@ -78,7 +78,7 @@ module DR
78
78
 
79
79
  STEP = 4
80
80
  def to_s(show_attr: true)
81
- @name + (show_attr && ! attributes.empty? ? " #{attributes}" : "")
81
+ @name.to_s + (show_attr && ! attributes.empty? ? " #{attributes}" : "")
82
82
  end
83
83
  def inspect
84
84
  "#{self.class}: #{to_s(show_attr: true)}"+(graph.nil? ? "" : " (#{graph})")
@@ -107,10 +107,12 @@ module DR
107
107
  class Graph
108
108
  attr_accessor :nodes
109
109
  include Enumerable
110
+ # note: passing a graph won't work
110
111
  def initialize(*nodes, attributes: {}, infos: nil)
111
112
  @nodes=[]
112
113
  # a node can be a Hash or a Node
113
- build(*nodes, attributes: {}, infos: infos)
114
+ # so nodes really is a list of subgraphs
115
+ build(*nodes, attributes: attributes, infos: infos)
114
116
  end
115
117
  def each(&b)
116
118
  @nodes.each(&b)
@@ -123,6 +125,10 @@ module DR
123
125
  def to_a
124
126
  return @nodes
125
127
  end
128
+ def names
129
+ @nodes.map(&:name)
130
+ end
131
+
126
132
  def to_hash(methods: [:children,:parents,:attributes], compact: true, recursive: true)
127
133
  require 'dr/base/converter'
128
134
  Converter.to_hash(@nodes, methods: methods, recursive: recursive, compact: compact)
@@ -142,7 +148,7 @@ module DR
142
148
  h=to_hash(methods: [:children])
143
149
  Hash[h.map {|k,v| [k.name, v.map(&:name)]}]
144
150
  end
145
- alias to_children to_h
151
+ #alias to_children to_h
146
152
 
147
153
  def to_children
148
154
  require 'dr/base/converter'
@@ -150,8 +156,11 @@ module DR
150
156
  end
151
157
 
152
158
  def inspect
153
- "#{self.class}: #{map {|x| x.to_s}}"
159
+ "#{self.class}: #{map {|x| x.to_s(show_attr: false)}}"
154
160
  end
161
+ # def to_s
162
+ # "#{self.class}: #{map {|x| x.to_s(show_attr: false)}}"
163
+ # end
155
164
 
156
165
  #construct a node (without edges)
157
166
  def new_node(node,**attributes)
@@ -204,6 +213,11 @@ module DR
204
213
  end
205
214
  self
206
215
  end
216
+
217
+ # alias << build
218
+ def <<(node, **opts)
219
+ build(node, **opts)
220
+ end
207
221
 
208
222
  def all
209
223
  @nodes.sort
@@ -216,14 +230,17 @@ module DR
216
230
  end
217
231
 
218
232
  # allow a hash too
219
- def |(graph)
220
- graph=Graph.new(graph) unless Graph===graph
233
+ def merge!(graph)
234
+ graph=Graph.new(graph, **{}) unless Graph===graph
221
235
  build(*graph.all, recursive: false)
222
236
  end
223
- def +(graph)
237
+ def merge(graph)
224
238
  clone.|(graph)
225
239
  end
226
240
 
241
+ alias | merge!
242
+ alias + merge
243
+
227
244
  def dump(mode: :graph, nodes_list: :roots, show_attr: true, out: [], **_opts)
228
245
  n=case nodes_list
229
246
  when :roots; roots
@@ -368,7 +385,7 @@ module DR
368
385
  while !new_nodes.empty?
369
386
  g2=yield(*new_nodes)
370
387
  g2=Graph.new(g2) unless g2.is_a?(Graph)
371
- g|g2
388
+ g.merge!(g2)
372
389
  nodes=nodes.concat(new_nodes)
373
390
  new_nodesg.nodes.map(&:name)-nodes
374
391
  end