nocode 0.0.4 → 0.0.5

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: 884ab5737629463437ef0991555e1ea30faa8db0cd6d8c79da712942aa69011b
4
- data.tar.gz: d8562fdf11b2a204e9ced685b434d6959bafe2dca605dd3795355aeed1ed5238
3
+ metadata.gz: 8726547b06744c6a7870a8634901b344e41a65bb1ede23c7e68e99d2218d482f
4
+ data.tar.gz: 3462f703d7639662c0da4f96ec9913749698c7f7a08a58387671db909a88785f
5
5
  SHA512:
6
- metadata.gz: 677aa00aba3a998a4cc616002420c9366ac945fabdfc336d948b5158c24eae6c9bfc1b8a7ee658718c5c55af4148c4f83656fddf8b45995002471ef7224870da
7
- data.tar.gz: e4de53676eaebb1d9bd3738dbbbb6df777ce0fdf1674e9aa370176c2eca9d42d4672d6edd682a313b943f24d149566491d1d7322d9c30ed0cc352db7730e0f3f
6
+ metadata.gz: f7bcfd37d152798a753801944a6a4787e3ad83a08fcfca0b40d9a0957cd7c5142a298adbb64215ed2e161c9e7f842b89ab460f6374fb8ec552a3482aa0b712eb
7
+ data.tar.gz: 6e024f679e2973888d5bb67c20988c8e93b296a6b6c4dbc66f7cb1f55d8638db48842834fd00c2a6d24050d9aa61950666107ff285a469e3f63835f74e7a5e7d
data/CHANGELOG.md CHANGED
@@ -1,7 +1,11 @@
1
+ #### 0.0.5 - February 13th, 2022
2
+
3
+ * Added initial Dataset steps.
4
+
1
5
  #### 0.0.4 - February 13th, 2022
2
6
 
3
7
  * Increase class documentation
4
- * Add YAML serialization/deserializationß
8
+ * Add YAML serialization/deserialization
5
9
 
6
10
  #### 0.0.3 - February 12th, 2022
7
11
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  #### Execute Ruby code through YAML
4
4
 
5
- [![Gem Version](https://badge.fury.io/rb/nocode.svg)](https://badge.fury.io/rb/nocode) [![Ruby Gem CI](https://github.com/mattruggio/nocode/actions/workflows/rubygem.yml/badge.svg)](https://github.com/mattruggio/nocode/actions/workflows/rubygem.yml)
5
+ [![Gem Version](https://badge.fury.io/rb/nocode.svg)](https://badge.fury.io/rb/nocode) [![Ruby Gem CI](https://github.com/mattruggio/nocode/actions/workflows/rubygem.yml/badge.svg)](https://github.com/mattruggio/nocode/actions/workflows/rubygem.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/66479dae44129c87dc88/maintainability)](https://codeclimate.com/github/mattruggio/nocode/maintainability) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
 
7
7
  This is a proof of concept showing how a YAML interface could be draped over arbitrary Ruby code. The YAML contains a series of steps with each step mapping to a specific Ruby class. The Ruby classes just have one responsibility: to implement #perform.
8
8
 
@@ -6,6 +6,12 @@ require_relative 'step_registry'
6
6
  module Nocode
7
7
  # Manages the lifecycle and executes a job.
8
8
  class Executor
9
+ NAME_KEY = 'name'
10
+ OPTIONS_KEY = 'options'
11
+ PARAMETERS_KEY = 'parameters'
12
+ STEPS_KEY = 'steps'
13
+ TYPE_KEY = 'type'
14
+
9
15
  attr_reader :yaml, :io
10
16
 
11
17
  def initialize(yaml, io: $stdout)
@@ -17,8 +23,8 @@ module Nocode
17
23
  end
18
24
 
19
25
  def execute
20
- steps = yaml['steps'] || []
21
- parameters = yaml['parameters'] || {}
26
+ steps = yaml[STEPS_KEY] || []
27
+ parameters = yaml[PARAMETERS_KEY] || {}
22
28
  context = Context.new(io: io, parameters: parameters)
23
29
 
24
30
  log_title
@@ -39,9 +45,9 @@ module Nocode
39
45
 
40
46
  def make_step(step, context)
41
47
  step = Util::ObjectTemplate.new(step).evaluate(context.to_h)
42
- type = step['type'].to_s
43
- name = step['name'].to_s
44
- options = step['options'] || {}
48
+ type = step[TYPE_KEY].to_s
49
+ name = step[NAME_KEY].to_s
50
+ options = step[OPTIONS_KEY] || {}
45
51
  step_class = StepRegistry.constant!(type)
46
52
 
47
53
  step_class.new(
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nocode
4
+ module Steps
5
+ module Dataset
6
+ # Add entries specified in the options to the end of the specified register's
7
+ # existing entries.
8
+ class Append < Step
9
+ option :entries, :register
10
+
11
+ def perform
12
+ registers[register_option] = array(registers[register_option])
13
+
14
+ array(entries_option).each do |entry|
15
+ registers[register_option].append(entry)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nocode
4
+ module Steps
5
+ module Dataset
6
+ # Combine all specified from_registers into one dataset and place in the specified
7
+ # to_register. If anything currently exists in the to_register then it will be coerced
8
+ # to an array and prepended to the beginning.
9
+ class Coalesce < Step
10
+ option :from_registers, :to_register
11
+
12
+ def perform
13
+ registers[to_register_option] = array(registers[to_register_option])
14
+
15
+ array(from_registers_option).each do |from_register|
16
+ registers[to_register_option] += array(registers[from_register])
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nocode
4
+ module Steps
5
+ module Dataset
6
+ # Insert the entries to the at_index of the specified register.
7
+ # If at_index is nil then they will appended to the end.
8
+ class Insert < Step
9
+ option :at_index, :entries, :register
10
+
11
+ def perform
12
+ registers[register_option] = array(registers[register_option])
13
+
14
+ registers[register_option].insert(at_index, *entries)
15
+ end
16
+
17
+ private
18
+
19
+ def entries
20
+ array(entries_option)
21
+ end
22
+
23
+ def at_index
24
+ at_index_option.nil? ? -1 : at_index_option.to_i
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nocode
4
+ module Steps
5
+ module Dataset
6
+ # Add entries specified in the options to the beginning of the specified register's
7
+ # existing entries.
8
+ class Prepend < Step
9
+ option :entries, :register
10
+
11
+ def perform
12
+ registers[register_option] = array(registers[register_option])
13
+
14
+ array(entries_option).reverse_each do |entry|
15
+ registers[register_option].prepend(entry)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nocode
4
+ module Steps
5
+ module Dataset
6
+ # Slice a dataset and keep on the entries between start_index and end_index, inclusively.
7
+ # If start_index is not provided then it defaults to 0.
8
+ # If end_index is not provided then it defaults to the end of the dataset.
9
+ class Range < Step
10
+ option :end_index,
11
+ :register,
12
+ :start_index
13
+
14
+ def perform
15
+ registers[register_option] = array(registers[register_option])
16
+
17
+ registers[register_option] = registers[register_option][start_index..end_index]
18
+ end
19
+
20
+ private
21
+
22
+ def start_index
23
+ start_index_option.nil? ? 0 : start_index_option.to_i
24
+ end
25
+
26
+ def end_index
27
+ end_index_option.nil? ? -1 : end_index_option.to_i
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -27,14 +27,8 @@ module Nocode
27
27
 
28
28
  if object.is_a?(Array)
29
29
  csv << object
30
-
31
- true
32
30
  elsif object.respond_to?(:values)
33
31
  csv << object.values
34
-
35
- true
36
- else
37
- false
38
32
  end
39
33
  end
40
34
  end
@@ -3,6 +3,8 @@
3
3
  module Nocode
4
4
  module Steps
5
5
  # Sleep for an arbitrary number of seconds.
6
+ #
7
+ # Mechanic: https://apidock.com/ruby/Kernel/sleep
6
8
  class Sleep < Step
7
9
  option :seconds
8
10
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nocode
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.5'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nocode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Ruggio
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-13 00:00:00.000000000 Z
11
+ date: 2022-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-audit
@@ -179,6 +179,11 @@ files:
179
179
  - lib/nocode/step.rb
180
180
  - lib/nocode/step_registry.rb
181
181
  - lib/nocode/steps/copy.rb
182
+ - lib/nocode/steps/dataset/append.rb
183
+ - lib/nocode/steps/dataset/coalesce.rb
184
+ - lib/nocode/steps/dataset/insert.rb
185
+ - lib/nocode/steps/dataset/prepend.rb
186
+ - lib/nocode/steps/dataset/range.rb
182
187
  - lib/nocode/steps/delete.rb
183
188
  - lib/nocode/steps/deserialize/csv.rb
184
189
  - lib/nocode/steps/deserialize/json.rb