nocode 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +47 -4
- data/lib/nocode/executor.rb +7 -7
- data/lib/nocode/{options_template.rb → object_template.rb} +1 -1
- data/lib/nocode/steps/deserialize/csv.rb +17 -0
- data/lib/nocode/steps/deserialize/json.rb +17 -0
- data/lib/nocode/steps/serialize/csv.rb +41 -0
- data/lib/nocode/steps/serialize/json.rb +17 -0
- data/lib/nocode/version.rb +1 -1
- data/lib/nocode.rb +2 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4609bf6b3f082509087ab07dfbe8b96f55df01788baac74c0d7c4500f1a48f35
|
4
|
+
data.tar.gz: 1acd73ef5df505964078a840362f271a8196b7f099e5f18e9f5d7f4692152e5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce4af8b6a125a1cd178d0436e32918ed246053ac8f214b7adc98f4051ab34916c60794bb915f978aa0101adca7f4d9ccd332b04f0f27efaba8dc9fb17035e310
|
7
|
+
data.tar.gz: 4e2e951062a9085a6bba5d146c5672f0862e6dc92eeedcc5d08cc5e7fdcdad86c08395240034a13441b6770c3bf0d31b1383446bf9f27ed4f18ceb0cd4cda9ac
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,13 +24,56 @@ bundle add nocode
|
|
24
24
|
|
25
25
|
## Examples
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
TODO
|
27
|
+
Create a file called `nocode-csv-to-json.yaml`:
|
30
28
|
|
31
29
|
### CSV-to-JSON File Converter
|
32
30
|
|
33
|
-
|
31
|
+
````yaml
|
32
|
+
parameters:
|
33
|
+
input_filename: input.csv
|
34
|
+
output_filename: output.json
|
35
|
+
|
36
|
+
steps:
|
37
|
+
- type: io/read
|
38
|
+
name: READ FILE
|
39
|
+
options:
|
40
|
+
path:
|
41
|
+
- files
|
42
|
+
- << parameters.input_filename >>
|
43
|
+
- type: deserialize/csv
|
44
|
+
- type: serialize/json
|
45
|
+
- type: io/write
|
46
|
+
options:
|
47
|
+
path:
|
48
|
+
- files
|
49
|
+
- << parameters.output_filename >>
|
50
|
+
````
|
51
|
+
|
52
|
+
Create csv file at: `files/input.csv`
|
53
|
+
|
54
|
+
Execute in Ruby:
|
55
|
+
|
56
|
+
````ruby
|
57
|
+
path = Pathname.new('nocode-csv-to-json.yaml')
|
58
|
+
|
59
|
+
Nocode.execute(path)
|
60
|
+
````
|
61
|
+
|
62
|
+
Or use bundler:
|
63
|
+
|
64
|
+
````zsh
|
65
|
+
bundle exec nocode `nocode-csv-to-json.yaml
|
66
|
+
````
|
67
|
+
|
68
|
+
A file should have been created at: `files/output.json`.
|
69
|
+
|
70
|
+
Notes:
|
71
|
+
|
72
|
+
* Path can be an array or a string. If its an array then the environment's path separator will be used.
|
73
|
+
* The `name` job key is optional. If present then it will print out on the log.
|
74
|
+
* Parameter values can be interpolated with keys and values using `<< parameters.key >>` syntax
|
75
|
+
|
76
|
+
|
34
77
|
|
35
78
|
## Contributing
|
36
79
|
|
data/lib/nocode/executor.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'context'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'object_template'
|
5
5
|
require_relative 'step_registry'
|
6
6
|
|
7
7
|
module Nocode
|
@@ -38,14 +38,14 @@ module Nocode
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def make_step(step, context)
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
step_class
|
41
|
+
step = ObjectTemplate.new(step).evaluate(context.to_h)
|
42
|
+
type = step['type'].to_s
|
43
|
+
name = step['name'].to_s
|
44
|
+
options = step['options'] || {}
|
45
|
+
step_class = StepRegistry.constant!(type)
|
46
46
|
|
47
47
|
step_class.new(
|
48
|
-
options: Util::Dictionary.new(
|
48
|
+
options: Util::Dictionary.new(options),
|
49
49
|
context: context,
|
50
50
|
name: name,
|
51
51
|
type: type
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nocode
|
4
|
+
module Steps
|
5
|
+
module Deserialize
|
6
|
+
class Csv < Step
|
7
|
+
option :register
|
8
|
+
|
9
|
+
def perform
|
10
|
+
input = registers[register_option].to_s
|
11
|
+
|
12
|
+
registers[register_option] = CSV.new(input, headers: true).map(&:to_h)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nocode
|
4
|
+
module Steps
|
5
|
+
module Deserialize
|
6
|
+
class Json < Step
|
7
|
+
option :register
|
8
|
+
|
9
|
+
def perform
|
10
|
+
input = registers[register_option]
|
11
|
+
|
12
|
+
registers[register_option] = JSON.parse(input)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nocode
|
4
|
+
module Steps
|
5
|
+
module Serialize
|
6
|
+
class Csv < Step
|
7
|
+
option :register
|
8
|
+
|
9
|
+
def perform
|
10
|
+
input = registers[register_option]
|
11
|
+
|
12
|
+
registers[register_option] = CSV.generate do |csv|
|
13
|
+
array(input).each_with_index do |object, index|
|
14
|
+
csv << object.keys if index.zero? && object.respond_to?(:keys)
|
15
|
+
|
16
|
+
add_object(object, csv)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def add_object(object, csv)
|
24
|
+
object ||= {}
|
25
|
+
|
26
|
+
if object.is_a?(Array)
|
27
|
+
csv << object
|
28
|
+
|
29
|
+
true
|
30
|
+
elsif object.respond_to?(:values)
|
31
|
+
csv << object.values
|
32
|
+
|
33
|
+
true
|
34
|
+
else
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Nocode
|
4
|
+
module Steps
|
5
|
+
module Serialize
|
6
|
+
class Json < Step
|
7
|
+
option :register
|
8
|
+
|
9
|
+
def perform
|
10
|
+
input = registers[register_option]
|
11
|
+
|
12
|
+
registers[register_option] = input.to_json
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/nocode/version.rb
CHANGED
data/lib/nocode.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nocode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ruggio
|
@@ -162,14 +162,18 @@ files:
|
|
162
162
|
- lib/nocode.rb
|
163
163
|
- lib/nocode/context.rb
|
164
164
|
- lib/nocode/executor.rb
|
165
|
-
- lib/nocode/
|
165
|
+
- lib/nocode/object_template.rb
|
166
166
|
- lib/nocode/step.rb
|
167
167
|
- lib/nocode/step_registry.rb
|
168
168
|
- lib/nocode/steps/copy.rb
|
169
169
|
- lib/nocode/steps/delete.rb
|
170
|
+
- lib/nocode/steps/deserialize/csv.rb
|
171
|
+
- lib/nocode/steps/deserialize/json.rb
|
170
172
|
- lib/nocode/steps/io/read.rb
|
171
173
|
- lib/nocode/steps/io/write.rb
|
172
174
|
- lib/nocode/steps/log.rb
|
175
|
+
- lib/nocode/steps/serialize/csv.rb
|
176
|
+
- lib/nocode/steps/serialize/json.rb
|
173
177
|
- lib/nocode/steps/set.rb
|
174
178
|
- lib/nocode/steps/sleep.rb
|
175
179
|
- lib/nocode/util.rb
|