nocode 0.0.2 → 0.0.3

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: ab995350f47e22230654ff1abd4ad9113039c93599528139081d5ee17da6b2f0
4
- data.tar.gz: 88e1927602ea3739d3444641fe0ca5145a6ac8f9df3040b5e47db76a842d8b0b
3
+ metadata.gz: 4609bf6b3f082509087ab07dfbe8b96f55df01788baac74c0d7c4500f1a48f35
4
+ data.tar.gz: 1acd73ef5df505964078a840362f271a8196b7f099e5f18e9f5d7f4692152e5c
5
5
  SHA512:
6
- metadata.gz: 9e234599b96b1a306dbd52e3726179f132121ae8509f23bc1d8f2043a79215bab6d4455580e50502c828c7d004b7e7e40a12b1121036483a5e376414b7b44cbc
7
- data.tar.gz: 34becb5eb86e23eed92783856f2c154ce10c6d87a64e9e0f75030b04c4b8d6285f2dbf7b87310df656c91f5d43fe7603cf26b4537ffc3e46cb982cd2e728034f
6
+ metadata.gz: ce4af8b6a125a1cd178d0436e32918ed246053ac8f214b7adc98f4051ab34916c60794bb915f978aa0101adca7f4d9ccd332b04f0f27efaba8dc9fb17035e310
7
+ data.tar.gz: 4e2e951062a9085a6bba5d146c5672f0862e6dc92eeedcc5d08cc5e7fdcdad86c08395240034a13441b6770c3bf0d31b1383446bf9f27ed4f18ceb0cd4cda9ac
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
- #### February 9th, 2022
1
+ #### 0.0.3 - February 12th, 2022
2
+
3
+ * Add initial implementation.
4
+
5
+ #### 0.0.0 - February 9th, 2022
2
6
 
3
7
  * Establish initial repository and gem infrastructure.
data/README.md CHANGED
@@ -24,13 +24,56 @@ bundle add nocode
24
24
 
25
25
  ## Examples
26
26
 
27
- ### A Simple File Copier
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
- TODO
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
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'context'
4
- require_relative 'options_template'
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
- type = step['type'].to_s
42
- name = step['name'].to_s
43
- options = step['options'] || {}
44
- compiled_options = OptionsTemplate.new(options).evaluate(context.to_h)
45
- step_class = StepRegistry.constant!(type)
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(compiled_options),
48
+ options: Util::Dictionary.new(options),
49
49
  context: context,
50
50
  name: name,
51
51
  type: type
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nocode
4
- class OptionsTemplate
4
+ class ObjectTemplate
5
5
  attr_reader :object
6
6
 
7
7
  def initialize(object)
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nocode
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
data/lib/nocode.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'benchmark'
4
+ require 'csv'
4
5
  require 'fileutils'
6
+ require 'json'
5
7
  require 'singleton'
6
8
  require 'time'
7
9
  require 'yaml'
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.2
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/options_template.rb
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