loom-core 0.0.6 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +31 -0
  3. data/Gemfile.lock +108 -56
  4. data/Rakefile +2 -0
  5. data/bin/loom +3 -0
  6. data/docs/architecture.jpg +0 -0
  7. data/gentags.sh +2 -0
  8. data/lib/loom/all.rb +1 -1
  9. data/lib/loom/config.rb +2 -2
  10. data/lib/loom/method_signature.rb +1 -1
  11. data/lib/loom/mods/action_proxy.rb +2 -2
  12. data/lib/loom/mods/mod_loader.rb +10 -5
  13. data/lib/loom/mods/module.rb +6 -5
  14. data/lib/loom/pattern/all.rb +1 -0
  15. data/lib/loom/pattern/definition_context.rb +7 -5
  16. data/lib/loom/pattern/dsl.rb +184 -119
  17. data/lib/loom/pattern/expanding_reference.rb +82 -6
  18. data/lib/loom/pattern/loader.rb +2 -18
  19. data/lib/loom/pattern/pattern.rb +52 -0
  20. data/lib/loom/pattern/reference.rb +17 -13
  21. data/lib/loom/pattern/reference_set.rb +71 -50
  22. data/lib/loom/runner/all.rb +2 -0
  23. data/lib/loom/runner/execution_context.rb +9 -0
  24. data/lib/loom/{dsl.rb → runner/sshkit_connector.rb} +5 -7
  25. data/lib/loom/runner.rb +46 -33
  26. data/lib/loom/shell/api.rb +3 -3
  27. data/lib/loom/shell/cmd_wrapper.rb +5 -2
  28. data/lib/loom/shell/core.rb +16 -16
  29. data/lib/loom/shell.rb +4 -2
  30. data/lib/loom/version.rb +1 -1
  31. data/lib/loomext/coremods/exec.rb +1 -0
  32. data/lib/loomext/coremods/systemd/all.rb +1 -0
  33. data/lib/loomext/coremods/systemd/hostname.rb +10 -0
  34. data/loom.TAGS +797 -0
  35. data/loom.gemspec +4 -3
  36. data/spec/.loom/error_handling.loom +1 -0
  37. data/spec/.loom/fail.loom +27 -13
  38. data/spec/.loom/files.loom +1 -0
  39. data/spec/.loom/inventory.yml +3 -0
  40. data/spec/.loom/net.loom +1 -0
  41. data/spec/.loom/pattern_context.loom +1 -0
  42. data/spec/.loom/pkg.loom +1 -0
  43. data/spec/.loom/regression.loom +23 -0
  44. data/spec/.loom/shell.loom +1 -0
  45. data/spec/.loom/test.loom +21 -4
  46. data/spec/.loom/user.loom +1 -0
  47. data/spec/.loom/vms.loom +1 -0
  48. data/spec/loom/host_spec_spec.rb +1 -1
  49. data/spec/loom/pattern/dsl_spec.rb +3 -2
  50. data/spec/shared/loom_internals_helper.rb +1 -1
  51. data/spec/test_loom_spec.rb +102 -42
  52. data/test +15 -0
  53. metadata +40 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11bd9487c4e4752e294000493fe1fe04537f97bfcea9385b1cf16e90c2c79a71
4
- data.tar.gz: 926227cb27d65b64103dd0f541acb1f523afdfac2df832180450f1aaaff4397f
3
+ metadata.gz: 76771b34a40961ff3eec048ed42682f49488cfd2f770d35ca2e19c255b534051
4
+ data.tar.gz: f9a8fec00bf59b419af9669b263ff09fa34224429640dd49d68aa110de49ea5c
5
5
  SHA512:
6
- metadata.gz: 687255010d7a4c709cb95b2022151a95175ae88decb368cfac503dd3bfdb24c677abdbd2ef055f16a80a783bad2d24762ab856bf20c085ec08d1f51734c78c01
7
- data.tar.gz: b789683f5aefd5a1997536e3f930f143bb7c12fc24be4e40d10fb0147e0c997c5af84798fad9e2da79d3cdbb7f5fe4a854d3f981f6deabe43ff08ab0092e3c68
6
+ metadata.gz: c1b14c69e8ce6a26d399f0f7bdc8fa71c2d41204b3199169d7c0ec00b37549c378bb50a7e30c4875661e43b0da7cead2aaa58936bf644d9bd9e716965bc39dd3
7
+ data.tar.gz: 152a387d0f25af816f35b6695c3a0827fe576acaf049be7c94931261d00f53b03402c2c79db0459854df0d25ba11aa4cb330649a786b67727bdf2d93b0250c2b
data/.rubocop.yml ADDED
@@ -0,0 +1,31 @@
1
+ # https://rubocop.readthedocs.io/en/latest/cops_layout/
2
+ Layout/EmptyLineAfterGuardClause:
3
+ Enabled: false
4
+ Layout/EmptyLinesAroundModuleBody:
5
+ Enabled: false
6
+ Layout/EmptyLinesAroundClassBody:
7
+ Enabled: false
8
+ Layout/MultilineMethodCallBrace:
9
+ Enabled: false
10
+ Layout/MultilineMethodCallIndentation:
11
+ EnforcedStyle: indented
12
+
13
+ Lint/BooleanSymbol:
14
+ Enabled: false
15
+
16
+ # https://rubocop.readthedocs.io/en/latest/cops_metrics/
17
+ Metrics/LineLength:
18
+ Max: 100
19
+
20
+ Naming/HeredocDelimiterNaming:
21
+ Enable: false
22
+
23
+ # https://rubocop.readthedocs.io/en/latest/cops_style/
24
+ Style/Alias:
25
+ Enabled: false
26
+ Style/ClassAndModuleChildren:
27
+ Enabled: false
28
+ Style/Encoding:
29
+ Enabled: false
30
+ Sylte/IfUnlessModifier:
31
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,33 +1,47 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- loom-core (0.0.6)
4
+ loom-core (0.0.8)
5
5
  bcrypt_pbkdf (>= 1.0, < 2.0)
6
6
  commander (~> 4.4)
7
7
  ed25519 (>= 1.0, < 2.0)
8
8
  net-ssh (>= 5)
9
- rbnacl-libsodium (= 1.0.10)
10
- sshkit (~> 1.11)
9
+ rbnacl-libsodium (= 1.0.16)
10
+ sshkit (~> 1.23)
11
11
 
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- bcrypt_pbkdf (1.0.0)
16
- byebug (9.0.6)
17
- coderay (1.1.1)
18
- commander (4.4.6)
19
- highline (~> 1.7.2)
20
- diff-lcs (1.2.5)
21
- ed25519 (1.2.4)
22
- ffi (1.9.14)
23
- formatador (0.2.5)
24
- guard (2.14.0)
15
+ ast (2.4.2)
16
+ base64 (0.2.0)
17
+ bcrypt_pbkdf (1.1.1)
18
+ bcrypt_pbkdf (1.1.1-arm64-darwin)
19
+ bcrypt_pbkdf (1.1.1-x86_64-darwin)
20
+ byebug (11.1.3)
21
+ coderay (1.1.3)
22
+ commander (4.6.0)
23
+ highline (~> 2.0.0)
24
+ diff-lcs (1.5.1)
25
+ ed25519 (1.3.0)
26
+ ffi (1.17.0)
27
+ ffi (1.17.0-aarch64-linux-gnu)
28
+ ffi (1.17.0-aarch64-linux-musl)
29
+ ffi (1.17.0-arm-linux-gnu)
30
+ ffi (1.17.0-arm-linux-musl)
31
+ ffi (1.17.0-arm64-darwin)
32
+ ffi (1.17.0-x86-linux-gnu)
33
+ ffi (1.17.0-x86-linux-musl)
34
+ ffi (1.17.0-x86_64-darwin)
35
+ ffi (1.17.0-x86_64-linux-gnu)
36
+ ffi (1.17.0-x86_64-linux-musl)
37
+ formatador (1.1.0)
38
+ guard (2.19.0)
25
39
  formatador (>= 0.2.4)
26
40
  listen (>= 2.7, < 4.0)
27
- lumberjack (~> 1.0)
41
+ lumberjack (>= 1.0.12, < 2.0)
28
42
  nenv (~> 0.1)
29
43
  notiffany (~> 0.0)
30
- pry (>= 0.9.12)
44
+ pry (>= 0.13.0)
31
45
  shellany (~> 0.0)
32
46
  thor (>= 0.18.1)
33
47
  guard-compat (1.2.1)
@@ -35,67 +49,105 @@ GEM
35
49
  guard (~> 2.1)
36
50
  guard-compat (~> 1.1)
37
51
  rspec (>= 2.99.0, < 4.0)
38
- highline (1.7.10)
39
- listen (3.1.5)
40
- rb-fsevent (~> 0.9, >= 0.9.4)
41
- rb-inotify (~> 0.9, >= 0.9.7)
42
- ruby_dep (~> 1.2)
43
- lumberjack (1.0.10)
44
- method_source (0.8.2)
52
+ highline (2.0.3)
53
+ json (2.8.2)
54
+ language_server-protocol (3.17.0.3)
55
+ listen (3.9.0)
56
+ rb-fsevent (~> 0.10, >= 0.10.3)
57
+ rb-inotify (~> 0.9, >= 0.9.10)
58
+ lumberjack (1.2.10)
59
+ method_source (1.1.0)
45
60
  nenv (0.3.0)
46
- net-scp (1.2.1)
47
- net-ssh (>= 2.6.5)
48
- net-ssh (5.0.2)
49
- notiffany (0.1.1)
61
+ net-scp (4.0.0)
62
+ net-ssh (>= 2.6.5, < 8.0.0)
63
+ net-sftp (4.0.0)
64
+ net-ssh (>= 5.0.0, < 8.0.0)
65
+ net-ssh (7.3.0)
66
+ notiffany (0.1.3)
50
67
  nenv (~> 0.1)
51
68
  shellany (~> 0.0)
52
- pry (0.10.4)
53
- coderay (~> 1.1.0)
54
- method_source (~> 0.8.1)
55
- slop (~> 3.4)
56
- pry-byebug (3.4.0)
57
- byebug (~> 9.0)
58
- pry (~> 0.10)
69
+ ostruct (0.6.1)
70
+ parallel (1.26.3)
71
+ parser (3.3.6.0)
72
+ ast (~> 2.4.1)
73
+ racc
74
+ pry (0.14.2)
75
+ coderay (~> 1.1)
76
+ method_source (~> 1.0)
77
+ pry-byebug (3.10.1)
78
+ byebug (~> 11.0)
79
+ pry (>= 0.13, < 0.15)
80
+ racc (1.8.1)
81
+ rainbow (3.1.1)
59
82
  rake (11.3.0)
60
- rb-fsevent (0.9.8)
61
- rb-inotify (0.9.7)
62
- ffi (>= 0.5.0)
63
- rbnacl (5.0.0)
64
- ffi
65
- rbnacl-libsodium (1.0.10)
83
+ rb-fsevent (0.11.2)
84
+ rb-inotify (0.11.1)
85
+ ffi (~> 1.0)
86
+ rbnacl (7.1.2)
87
+ ffi (~> 1)
88
+ rbnacl-libsodium (1.0.16)
66
89
  rbnacl (>= 3.0.1)
67
- rspec (3.5.0)
68
- rspec-core (~> 3.5.0)
69
- rspec-expectations (~> 3.5.0)
70
- rspec-mocks (~> 3.5.0)
71
- rspec-core (3.5.4)
72
- rspec-support (~> 3.5.0)
73
- rspec-expectations (3.5.0)
90
+ regexp_parser (2.9.3)
91
+ rspec (3.13.0)
92
+ rspec-core (~> 3.13.0)
93
+ rspec-expectations (~> 3.13.0)
94
+ rspec-mocks (~> 3.13.0)
95
+ rspec-core (3.13.2)
96
+ rspec-support (~> 3.13.0)
97
+ rspec-expectations (3.13.3)
74
98
  diff-lcs (>= 1.2.0, < 2.0)
75
- rspec-support (~> 3.5.0)
76
- rspec-mocks (3.5.0)
99
+ rspec-support (~> 3.13.0)
100
+ rspec-mocks (3.13.2)
77
101
  diff-lcs (>= 1.2.0, < 2.0)
78
- rspec-support (~> 3.5.0)
79
- rspec-support (3.5.0)
80
- ruby_dep (1.5.0)
102
+ rspec-support (~> 3.13.0)
103
+ rspec-support (3.13.1)
104
+ rubocop (1.69.0)
105
+ json (~> 2.3)
106
+ language_server-protocol (>= 3.17.0)
107
+ parallel (~> 1.10)
108
+ parser (>= 3.3.0.2)
109
+ rainbow (>= 2.2.2, < 4.0)
110
+ regexp_parser (>= 2.4, < 3.0)
111
+ rubocop-ast (>= 1.36.1, < 2.0)
112
+ ruby-progressbar (~> 1.7)
113
+ unicode-display_width (>= 2.4.0, < 4.0)
114
+ rubocop-ast (1.36.2)
115
+ parser (>= 3.3.1.0)
116
+ ruby-progressbar (1.13.0)
81
117
  shellany (0.0.1)
82
- slop (3.6.0)
83
- sshkit (1.17.0)
118
+ sshkit (1.23.2)
119
+ base64
84
120
  net-scp (>= 1.1.2)
121
+ net-sftp (>= 2.1.2)
85
122
  net-ssh (>= 2.8.0)
86
- thor (0.19.1)
123
+ ostruct
124
+ thor (1.3.2)
125
+ unicode-display_width (3.1.2)
126
+ unicode-emoji (~> 4.0, >= 4.0.4)
127
+ unicode-emoji (4.0.4)
87
128
 
88
129
  PLATFORMS
130
+ aarch64-linux-gnu
131
+ aarch64-linux-musl
132
+ arm-linux-gnu
133
+ arm-linux-musl
134
+ arm64-darwin
89
135
  ruby
136
+ x86-linux-gnu
137
+ x86-linux-musl
138
+ x86_64-darwin
139
+ x86_64-linux-gnu
140
+ x86_64-linux-musl
90
141
 
91
142
  DEPENDENCIES
92
- bundler (~> 1.13)
143
+ bundler
93
144
  guard-rspec (~> 4.7)
94
145
  loom-core!
95
146
  pry (~> 0.10)
96
147
  pry-byebug
97
148
  rake (~> 11.3)
98
149
  rspec (~> 3.5)
150
+ rubocop
99
151
 
100
152
  BUNDLED WITH
101
- 1.16.2
153
+ 2.5.23
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # TODO: I can replace this with Loom now.
2
+ # TODO: Make a Loom mod that converts Rake Tasks into Loom Patterns.
1
3
  require "bundler/gem_tasks"
2
4
  require "rspec/core/rake_task"
3
5
 
data/bin/loom CHANGED
@@ -158,6 +158,9 @@ EOS
158
158
  end
159
159
  end
160
160
  end
161
+ # TODO: p and patterns produce different output on failure, p is a
162
+ # truncated stack. Figure out why, and fix that. This is going to be
163
+ # somewhere in Commander.
161
164
  alias_command :"p", :"patterns"
162
165
 
163
166
  command :"config" do |c|
Binary file
data/gentags.sh ADDED
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ find lib -name \*.rb | etags -l ruby --output=loom.TAGS -
data/lib/loom/all.rb CHANGED
@@ -9,12 +9,12 @@ require_relative "config"
9
9
 
10
10
  require_relative "shell"
11
11
  require_relative "host_spec"
12
- require_relative "dsl"
13
12
 
14
13
  require_relative "inventory"
15
14
  require_relative "facts"
16
15
  require_relative "pattern"
17
16
  require_relative "mods"
17
+ require_relative "runner/all"
18
18
  require_relative "runner"
19
19
 
20
20
  require_relative "version"
data/lib/loom/config.rb CHANGED
@@ -69,7 +69,7 @@ module Loom
69
69
  map = config ? config.config_map : CONFIG_VARS.dup
70
70
  config_struct = OpenStruct.new **map
71
71
  yield config_struct if block_given?
72
- Config.new config_struct.to_h
72
+ Config.new **config_struct.to_h
73
73
  end
74
74
  end
75
75
 
@@ -77,7 +77,7 @@ module Loom
77
77
  class FileManager
78
78
 
79
79
  def initialize(config)
80
- @loom_search_paths = config.loom_search_paths
80
+ @loom_search_paths = [config.loom_search_paths].flatten
81
81
  @loom_files = config.loom_files
82
82
  @loom_file_patterns = config.loom_file_patterns
83
83
  end
@@ -64,7 +64,7 @@ module Loom
64
64
  end
65
65
 
66
66
  def build
67
- MatchSpec.new(@map || {})
67
+ MatchSpec.new(**(@map || {}))
68
68
  end
69
69
  end
70
70
 
@@ -40,7 +40,7 @@ module Loom::Mods
40
40
  # idiomatic.
41
41
  bound_action_name = tuple[1]
42
42
 
43
- define_method public_action_name do |*args, &block|
43
+ define_method public_action_name do |*args, **kwargs, &block|
44
44
  # TODO[P0]: Effectively this is the API for all mods, but it's
45
45
  # burried here in the middle of nowhere. Add documentation - or make
46
46
  # it easier to read.
@@ -48,7 +48,7 @@ module Loom::Mods
48
48
  "proxy to mod action: #{public_action_name} => #{bound_action_name}, #{@mod}"
49
49
  end
50
50
 
51
- @mod.send bound_action_name, *args, &block
51
+ @mod.send bound_action_name, *args, **kwargs, &block
52
52
  end
53
53
  Loom.log.debug2 self do
54
54
  "defined action proxy action: #{public_action_name} => #{bound_action_name}"
@@ -10,7 +10,12 @@ module Loom::Mods
10
10
  @loom_config = loom_config
11
11
  end
12
12
 
13
- def verify_shell_cmds(shell, mod_klass)
13
+ def load_mod_klass(mod_klass, shell)
14
+ verify_shell_cmds mod_klass, shell
15
+ end
16
+
17
+ private
18
+ def verify_shell_cmds(mod_klass, shell)
14
19
  Loom.log.debug2(self) { "verifying cmds for mod => #{mod_klass}" }
15
20
  mod_klass.required_commands.each do |cmd|
16
21
  begin
@@ -49,14 +54,14 @@ module Loom::Mods
49
54
  raise ModDefinedError, name if instance_methods.include? name
50
55
  registered_mods[mod_klass.name] = [name]
51
56
 
52
- define_method name do |shell, *args, &pattern_block|
57
+ define_method name do |shell, *args, **kwargs, &pattern_block|
53
58
  Loom.log.debug3(self) do
54
- "handling mod call => #{mod_klass}##{name} #{args} #{pattern_block}"
59
+ "handling mod call => #{mod_klass}##{name} #{args} #{kwargs} #{pattern_block}"
55
60
  end
56
- verify_shell_cmds shell, mod_klass
61
+ load_mod_klass mod_klass, shell
57
62
 
58
63
  mod = mod_klass.new shell, @loom_config
59
- mod.execute *args, &pattern_block
64
+ mod.execute *args, **kwargs, &pattern_block
60
65
  end
61
66
  end
62
67
 
@@ -32,13 +32,13 @@ module Loom::Mods
32
32
  @action_block = pattern_block
33
33
  end
34
34
 
35
- def execute(*args, &pattern_block)
35
+ def execute(*args, **kwargs, &pattern_block)
36
36
  if respond_to? :mod_block
37
37
  Loom.log.debug3(self) { "executing mod block => #{args} #{pattern_block}" }
38
- mod_block *args, &pattern_block
38
+ mod_block *args, **kwargs, &pattern_block
39
39
  else
40
40
  Loom.log.debug3(self) { "initing action => #{args}" }
41
- init_action *args, &pattern_block
41
+ init_action *args, **kwargs, &pattern_block
42
42
 
43
43
  # TODO: ooohhh... the action_proxy code path is fucking
44
44
  # crazy. ActionProxy needs some documentation.
@@ -99,11 +99,12 @@ module Loom::Mods
99
99
  # (e.g.) to each instance of Module. (actually I think it's because this
100
100
  # is executing from the subclass (via import_actions), so it's only that
101
101
  # class). in any case, add more docs and code pointers.
102
- define_method bound_method_name do |*args, &block|
102
+ define_method bound_method_name do |*args, **kwargs, &block|
103
103
  Loom.log.debug1(self) { "exec mod action #{self.class}##{bound_method_name}" }
104
104
 
105
105
  bound_method = unbound_method.bind self
106
- bound_method.call *args, &block
106
+
107
+ bound_method.call *args, **kwargs, &block
107
108
  end
108
109
  Loom.log.debug2(self) { "bound mod action => #{self.class.name}##{action_name}" }
109
110
 
@@ -1,6 +1,7 @@
1
1
  require_relative "dsl"
2
2
  require_relative "hook"
3
3
  require_relative "definition_context"
4
+ require_relative "pattern"
4
5
  require_relative "reference"
5
6
  require_relative "expanding_reference"
6
7
  require_relative "reference_set"
@@ -8,11 +8,11 @@ module Loom::Pattern
8
8
 
9
9
  NilLetValueError = Class.new Loom::LoomError
10
10
 
11
- def initialize(pattern_module, parent_context=nil)
12
- @fact_map = pattern_module.facts.dup
13
- @let_map = pattern_module.let_map.dup
11
+ def initialize(dsl_builder, parent_context=nil)
12
+ @fact_map = dsl_builder.facts.dup
13
+ @let_map = dsl_builder.let_map.dup
14
14
 
15
- @hooks = pattern_module.hooks.dup
15
+ @hooks = dsl_builder.hooks.dup
16
16
  @parent_context = parent_context
17
17
 
18
18
  @merged_fact_map = merged_fact_map
@@ -46,7 +46,9 @@ module Loom::Pattern
46
46
 
47
47
  if value.nil? || value.equal?(Loom::Facts::EMPTY)
48
48
  Loom.log.error "value of let expression[:#{let_key}] is nil"
49
- raise NilLetValueError, let_key
49
+ # TODO: I'm not sure what to do here, but raising an error isn't
50
+ # very user friendly.... as I just learned.
51
+ # raise NilLetValueError, "empty value for let[#{let_key}]"
50
52
  end
51
53
  scope_object.define_singleton_method(let_key) { value }
52
54
  end