eddy 0.3.0 → 0.4.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: 1741275af8926c329cfb842bbcd9e878850d21957d00cd93596d378a7b443a68
4
- data.tar.gz: 1c1d5492e1ac989708505890e9d3a2e4db8008b614b7e52bb7554ccbc99f3739
3
+ metadata.gz: f42340c2240a26ad129493767545915bfa8d6405d79691841fada80cac9ac7ee
4
+ data.tar.gz: d60b37dc82e5a008e616ee98c902201df6d97808d4e215769e208a0de404bffb
5
5
  SHA512:
6
- metadata.gz: 56a2d2235e1eb3759400567ee7765e0ad647fc579abde3cc6a7a6ef15c5a3c4e2e497796084e5bea4170c7fc0a1bda79f29ac21024ecc6c39960d9656a54c199
7
- data.tar.gz: 01274642ed73cd71bf525839f7521b93d848483935641b84e6165f05e6f64497fbef6fb414b19641cbf075d08be6f8c0a96828c34606b1e43ecb455d2c692cca
6
+ metadata.gz: 5c6ac232571b5cd098770a25c20416cfa7ce4a65be98bf5b001666185010b0d84dbf9af160406bcd1e313c35eda2a463da92b413cceee1a9458f728ab0894e3d
7
+ data.tar.gz: f41c5e4c6bc496f0354e6046c1d9bec085037f529647d9ea04c4c81706c4bcd3412528413afb5166866894c19484279d098f9b35ebc6de13129a31217c7977f5
data/CHANGELOG.md CHANGED
@@ -7,12 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## master (unreleased)
9
9
 
10
- Versions 0.x.x (0.2.0, 0.3.0) exist to make it easier for me to test Eddy in other projects and figure out how best to move forward with development.
10
+ Versions 0.x (0.2, 0.3, 0.4, ...) exist to make it easier for me to test Eddy in other projects and figure out how best to move forward with development.
11
11
 
12
12
  All code should be considered Work In Progress.
13
13
 
14
14
  While the API is still changing, enough code exists that EDI documents can currently be written with Eddy (though I wouldn't recommend use in production environments yet).
15
15
 
16
+ ## 0.4.0 (2020-01-05)
17
+
18
+ ### Added
19
+
20
+ - Support `Eddy::Data::Persistence::ActiveRecord`.
21
+
22
+ ### Changed
23
+
24
+ - Move generators to separate repo, [tcd/eddy-rails](https://github.com/tcd/eddy-rails).
25
+ - Update `Eddy.data` when `Eddy.config.persistence_method` is changed.
26
+
16
27
  ## 0.3.0 (2020-01-04)
17
28
 
18
29
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- eddy (0.3.0)
4
+ eddy (0.4.0)
5
5
  ginny (~> 0.6.3)
6
6
  json_schemer (~> 0.2.8)
7
7
  thor (~> 1.0.1)
data/README.md CHANGED
@@ -10,10 +10,12 @@
10
10
  [travis-ci]: https://travis-ci.org/tcd/eddy
11
11
  [coveralls]: https://coveralls.io/github/tcd/eddy?branch=master
12
12
  [license]: https://github.com/tcd/eddy/blob/master/LICENSE.txt
13
- [docs]: https://www.rubydoc.info/gems/eddy/0.3.0
13
+ [docs]: https://www.rubydoc.info/gems/eddy/0.4.0
14
14
 
15
15
  ## Installation
16
16
 
17
+ ### Without Rails
18
+
17
19
  Add this line to your application's Gemfile:
18
20
 
19
21
  ```ruby
@@ -28,12 +30,7 @@ bundle
28
30
 
29
31
  ### With Rails
30
32
 
31
- Once installed, run
32
-
33
- ```sh
34
- rails g eddy:install eddy:migration
35
- rails db:migrate
36
- ```
33
+ Use [eddy-rails](https://github.com/tcd/eddy-rails).
37
34
 
38
35
  ## Validation
39
36
 
data/eddy.gemspec CHANGED
@@ -6,13 +6,14 @@ Gem::Specification.new do |spec|
6
6
  spec.name = "eddy"
7
7
  spec.version = Eddy::VERSION
8
8
  spec.authors = ["Clay Dunston"]
9
- spec.required_ruby_version = ">= 2.5.0"
10
9
  spec.email = ["dunstontc@gmail.com"]
11
10
  spec.summary = "EDI toolkit"
12
11
  spec.description = spec.summary
13
12
  spec.homepage = "https://github.com/tcd/eddy"
14
13
  spec.license = "MIT"
15
14
 
15
+ spec.required_ruby_version = ">= 2.5.0"
16
+
16
17
  spec.metadata = {
17
18
  "homepage_uri" => spec.homepage,
18
19
  "source_code_uri" => spec.homepage,
File without changes
File without changes
data/lib/eddy/config.rb CHANGED
@@ -1,12 +1,9 @@
1
1
  module Eddy
2
- # Configuration for Eddy
2
+ # Configuration for Eddy.
3
3
  class Config
4
4
 
5
5
  # @return [String<"test", "development", "production">] ("development")
6
6
  attr_accessor :env
7
- # Method used by Eddy to persist data about EDI control numbers.
8
- # @return [Symbol<:memory, :file>] (:memory)
9
- attr_accessor :persistence_method
10
7
  # @return [String]
11
8
  attr_accessor :tmp_dir
12
9
  # @return [String]
@@ -26,6 +23,23 @@ module Eddy
26
23
  self.validate = true
27
24
  end
28
25
 
26
+ # Method used by Eddy to persist data about EDI control numbers.
27
+ # @return [Symbol<:memory, :file>] (:memory)
28
+ #
29
+ # @return [void]
30
+ def persistence_method()
31
+ return @persistence_method
32
+ end
33
+
34
+ # Method used by Eddy to persist data about EDI control numbers.
35
+ #
36
+ # @param method [Symbol]
37
+ # @return [void]
38
+ def persistence_method=(method)
39
+ Eddy.clear_data()
40
+ @persistence_method = method
41
+ end
42
+
29
43
  end
30
44
 
31
45
  # Configuration for Eddy
data/lib/eddy/data.rb CHANGED
@@ -7,16 +7,29 @@ module Eddy
7
7
  # Persistent data used by Eddy.
8
8
  # @return [Eddy::Data::Persistence::Base]
9
9
  def self.data
10
- return @data if defined? @data
10
+ return @data if defined?(@data) && !@data.nil?
11
11
  case Eddy.config.persistence_method
12
12
  when :memory then @data = Eddy::Data::Persistence::Memory.new()
13
13
  when :file then raise NotImplementedError
14
- when :db then raise NotImplementedError
14
+ when :active_record
15
+ if defined?(Rails) && defined?(Eddy::Rails)
16
+ @data = Eddy::Data::Persistence::ActiveRecord.new()
17
+ else
18
+ raise Eddy::Errors::Error, "ActiveRecord persistence method can currently only be used with Ruby on Rails"
19
+ end
15
20
  else raise Eddy::Errors::Error, "Unsupported persistence method: #{Eddy.config.persistence_method}"
16
21
  end
17
22
  return @data
18
23
  end
19
24
 
25
+ # Set `@data` to `nil` so that a new persistence_method can be set up.
26
+ #
27
+ # @return [void]
28
+ def self.clear_data()
29
+ @data = nil
30
+ end
31
+
32
+ # Code for storing & generating data used by Eddy when generating EDI documents.
20
33
  module Data
21
34
 
22
35
  # @return [Integer]
File without changes
File without changes
File without changes
@@ -0,0 +1,42 @@
1
+ module Eddy
2
+ module Loop
3
+ # Data form a single loop iteration.
4
+ class Repeat
5
+
6
+ # An array of Segments and/or other Loops.
7
+ # This is used as a template to populate `content`.
8
+ # @return [Array<Eddy::Segment, Eddy::Loop::Base>]
9
+ attr_reader :components
10
+ # @return [Eddy::Data::Store] Data passed down from a Transaction Set.
11
+ attr_reader :store
12
+
13
+ # All of a Loop's elements need to be declared in its constructor.
14
+ #
15
+ # @param store [Eddy::Data::Store]
16
+ # @param components [Array<Eddy::Loop, Eddy::Segment>]
17
+ # @return [void]
18
+ def initialize(store, *components)
19
+ @store = store
20
+ components.flatten!
21
+ @components = components || []
22
+ end
23
+
24
+ # Return all contained Segments in a single, flattened array.
25
+ #
26
+ # @return [Array<Eddy::Segment>]
27
+ def all_contents()
28
+ contents = self.content.flatten.map do |c|
29
+ if c.is_a?(Eddy::Loop::Base)
30
+ c.all_contents()
31
+ elsif c.is_a?(Eddy::Segment)
32
+ c
33
+ else
34
+ raise Eddy::Errors::RenderError
35
+ end
36
+ end
37
+ return contents.flatten
38
+ end
39
+
40
+ end
41
+ end
42
+ end
File without changes
@@ -0,0 +1,13 @@
1
+ require "eddy/models/element"
2
+ require "eddy/models/segment"
3
+ require "eddy/models/loop/base"
4
+ # require "eddy/models/loop/repeat"
5
+ require "eddy/models/transaction_set"
6
+ require "eddy/models/functional_group"
7
+ require "eddy/models/interchange"
8
+ require "eddy/models/simple_interchange"
9
+
10
+ module Eddy
11
+ # Classes modeling EDI components.
12
+ module Models; end
13
+ end
data/lib/eddy/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eddy
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
data/lib/eddy.rb CHANGED
@@ -9,18 +9,9 @@ require "eddy/data"
9
9
 
10
10
  Dir.glob(File.join(__dir__, "eddy", "schema", "*.rb")).sort.each { |file| require file }
11
11
 
12
- require "eddy/models/element"
13
- require "eddy/models/segment"
14
- require "eddy/models/loop"
15
- require "eddy/models/transaction_set"
16
-
17
- require "eddy/write/interchange"
18
- require "eddy/write/simple_interchange"
19
- require "eddy/write/functional_group"
20
-
12
+ require "eddy/models"
21
13
  require "eddy/parse"
22
-
23
- require "eddy/build/build"
14
+ require "eddy/build"
24
15
 
25
16
  # Dir.glob(File.join(__dir__, "definitions", "elements", "manual", "**", "*.rb")).sort.each { |file| require file }
26
17
  # Dir.glob(File.join(__dir__, "definitions", "segments", "manual", "**", "*.rb")).sort.each { |file| require file }
@@ -30,4 +21,4 @@ Dir.glob(File.join(__dir__, "definitions", "elements", "**", "*.rb")).sort.each
30
21
  Dir.glob(File.join(__dir__, "definitions", "segments", "**", "*.rb")).sort.each { |file| require file }
31
22
  Dir.glob(File.join(__dir__, "definitions", "transaction_sets", "**", "*.rb")).sort.each { |file| require file }
32
23
 
33
- require "eddy/cli/cli"
24
+ require "eddy/cli"
data/todo.txt CHANGED
@@ -3,10 +3,10 @@ x 2019-12-20 2019-12-20 Write code to check what element files already exist.
3
3
  x 2019-12-20 Write code to build all segments.
4
4
  x 2020-01-02 2019-12-20 Figure out how to deal with loops.
5
5
  x 2020-01-03 2019-12-20 Finish TransactionSetBuilder.
6
+ x 2020-01-05 2019-12-20 Reset `Eddy.data` when `Eddy.config.persistence_method` changes.
6
7
 
7
8
  2019-12-28 If a loop can only repeat once, dont treat it as a loop.
8
9
  2019-12-20 Add a DB persistence_method.
9
- 2019-12-20 Reset `Eddy.data` when `Eddy.config.persistence_method` changes.
10
10
  2019-12-20 Check for conflicts in Rails generators.
11
11
  2019-12-20 Write a Rails model generator.
12
12
  2019-12-27 Generate "ref map" files.
@@ -14,3 +14,4 @@ x 2020-01-03 2019-12-20 Finish TransactionSetBuilder.
14
14
  2019-12-30 JSON schema validation errors.
15
15
  2020-01-02 Ensure loops dont go over repeat limit.
16
16
  2020-01-02 Implement `Segment.max_use` & `Segment.min_use`.
17
+ 2020-01-05 Move `Build` to `eddy-build`
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eddy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clay Dunston
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-04 00:00:00.000000000 Z
11
+ date: 2020-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -1491,7 +1491,7 @@ files:
1491
1491
  - lib/definitions/transaction_sets/manual/856/856.rb
1492
1492
  - lib/definitions/transaction_sets/manual/856/loops.rb
1493
1493
  - lib/eddy.rb
1494
- - lib/eddy/build/build.rb
1494
+ - lib/eddy/build.rb
1495
1495
  - lib/eddy/build/elements/element.rb
1496
1496
  - lib/eddy/build/elements/elements.rb
1497
1497
  - lib/eddy/build/elements/id.rb
@@ -1499,15 +1499,15 @@ files:
1499
1499
  - lib/eddy/build/loop_builder.rb
1500
1500
  - lib/eddy/build/segment_builder.rb
1501
1501
  - lib/eddy/build/transaction_set_builder.rb
1502
- - lib/eddy/cli/cli.rb
1502
+ - lib/eddy/cli.rb
1503
1503
  - lib/eddy/config.rb
1504
1504
  - lib/eddy/data.rb
1505
- - lib/eddy/data/persistence/active_record.rb
1506
1505
  - lib/eddy/data/persistence/base.rb
1507
1506
  - lib/eddy/data/persistence/file.rb
1508
1507
  - lib/eddy/data/persistence/memory.rb
1509
1508
  - lib/eddy/data/store.rb
1510
1509
  - lib/eddy/errors.rb
1510
+ - lib/eddy/models.rb
1511
1511
  - lib/eddy/models/element.rb
1512
1512
  - lib/eddy/models/element/an.rb
1513
1513
  - lib/eddy/models/element/b.rb
@@ -1518,8 +1518,12 @@ files:
1518
1518
  - lib/eddy/models/element/n.rb
1519
1519
  - lib/eddy/models/element/r.rb
1520
1520
  - lib/eddy/models/element/tm.rb
1521
- - lib/eddy/models/loop.rb
1521
+ - lib/eddy/models/functional_group.rb
1522
+ - lib/eddy/models/interchange.rb
1523
+ - lib/eddy/models/loop/base.rb
1524
+ - lib/eddy/models/loop/repeat.rb
1522
1525
  - lib/eddy/models/segment.rb
1526
+ - lib/eddy/models/simple_interchange.rb
1523
1527
  - lib/eddy/models/transaction_set.rb
1524
1528
  - lib/eddy/parse.rb
1525
1529
  - lib/eddy/schema/element_summary.rb
@@ -1538,13 +1542,6 @@ files:
1538
1542
  - lib/eddy/util/timestamp.rb
1539
1543
  - lib/eddy/util/trim.rb
1540
1544
  - lib/eddy/version.rb
1541
- - lib/eddy/write/functional_group.rb
1542
- - lib/eddy/write/interchange.rb
1543
- - lib/eddy/write/simple_interchange.rb
1544
- - lib/generators/eddy/initializer/initializer_generator.rb
1545
- - lib/generators/eddy/initializer/templates/eddy.rb.erb
1546
- - lib/generators/eddy/migration/migration_generator.rb
1547
- - lib/generators/eddy/migration/templates/migration.rb.erb
1548
1545
  - tasks/build.rake
1549
1546
  - tasks/misc/gemspec.rake
1550
1547
  - tasks/misc/missing_lists.rake
@@ -1557,7 +1554,7 @@ metadata:
1557
1554
  homepage_uri: https://github.com/tcd/eddy
1558
1555
  source_code_uri: https://github.com/tcd/eddy
1559
1556
  changelog_uri: https://github.com/tcd/eddy/blob/master/CHANGELOG.md
1560
- documentation_uri: https://www.rubydoc.info/gems/eddy/0.3.0
1557
+ documentation_uri: https://www.rubydoc.info/gems/eddy/0.4.0
1561
1558
  yard.run: yri
1562
1559
  post_install_message:
1563
1560
  rdoc_options: []
@@ -1,10 +0,0 @@
1
- module Eddy
2
- module Data
3
- module Persistence
4
- # Persist data to a database using Active Record.
5
- class ActiveRecord
6
-
7
- end
8
- end
9
- end
10
- end
@@ -1,17 +0,0 @@
1
- require "rails/generators"
2
-
3
- module Eddy
4
- module Generators
5
- # Generate an initializer file for Eddy.
6
- class InitializersGenerator < Rails::Generators::Base
7
- desc "This generator creates an initializer file at config/initializers/eddy.rb for Eddy"
8
- source_root File.expand_path("templates", __dir__)
9
-
10
- # @return [void]
11
- def copy_initializer
12
- template "eddy.rb.erb", "config/initializers/eddy.rb"
13
- end
14
-
15
- end
16
- end
17
- end
@@ -1,6 +0,0 @@
1
- Eddy.configure do |config|
2
- config.env = Rails.env
3
- config.persistence_method = :memory
4
- config.tmp_dir = Rails.root.join('tmp')
5
- config.tmp_dir = Rails.root.join('tmp', 'build')
6
- end
@@ -1,53 +0,0 @@
1
- require "rails/generators"
2
- require "rails/generators/active_record"
3
-
4
- module Eddy
5
- module Generators
6
- # Generate migrations to set up database tables for use by Eddy.
7
- #
8
- # See:
9
- #
10
- # - [Rails Guides - Generators](https://edgeguides.rubyonrails.org/generators.html)
11
- # - [`Rails::Generators::Migration`](https://api.rubyonrails.org/classes/Rails/Generators/Migration.html)
12
- # - [StackOverflow Question](https://stackoverflow.com/questions/53212961/how-to-make-a-custom-generator-which-also-generates-a-migration-in-rails)
13
- # - ["index: true" in Rails migrations does not work as you'd expect](https://makandracards.com/makandra/32353-psa-index-true-in-rails-migrations-does-not-work-as-you-d-expect)
14
- class MigrationGenerator < Rails::Generators::Base
15
-
16
- include Rails::Generators::Migration
17
- desc "This generator creates a migration file in db/migrate that will set up database tables for use by Eddy"
18
- source_root File.expand_path("templates", __dir__)
19
-
20
- # @return [void]
21
- def generate_migration
22
- migration_template(
23
- "migration.rb.erb",
24
- "db/migrate/#{self.migration_file_name()}",
25
- migration_version: self.migration_version(),
26
- )
27
- end
28
-
29
- # @return [String]
30
- def migration_file_name()
31
- return "create_eddy_tables.rb"
32
- # return "#{self.timestamp()}_create_eddy_tables.rb"
33
- end
34
-
35
- # @return [String]
36
- def timestamp()
37
- return Time.now.utc.strftime("%Y%m%d%H%M%S")
38
- end
39
-
40
- # @return [String]
41
- def migration_version()
42
- return "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
43
- end
44
-
45
- # for generating a timestamp when using `create_migration`
46
- # Sole from - https://github.com/thoughtbot/clearance/blob/master/lib/generators/clearance/install/install_generator.rb#L116
47
- def self.next_migration_number(dir)
48
- ActiveRecord::Generators::Base.next_migration_number(dir)
49
- end
50
-
51
- end
52
- end
53
- end
@@ -1,35 +0,0 @@
1
- class EddyCreateTables < ActiveRecord::Migration<%= migration_version %>
2
-
3
- def self.up
4
- create_table :eddy_interchange_control_numbers do |t|
5
- t.integer :control_number, null: false
6
- t.boolean :received
7
- t.boolean :sent
8
- t.timestamps null: false
9
- end
10
- create_table :eddy_functional_group_control_numbers do |t|
11
- t.integer :control_number, null: false
12
- t.string :functional_group, null: false
13
- t.boolean :received
14
- t.boolean :sent
15
- t.timestamps null: false
16
- end
17
- create_table :eddy_transaction_set_control_numbers do |t|
18
- t.integer :control_number, null: false
19
- t.string :transaction_set, null: false
20
- t.boolean :received
21
- t.boolean :sent
22
- t.timestamps null: false
23
- end
24
- add_index :eddy_interchange_control_numbers, :control_number, unique: true
25
- add_index :eddy_functional_group_control_numbers, :control_number, unique: true
26
- add_index :eddy_transaction_set_control_numbers, :control_number, unique: true
27
- end
28
-
29
- def self.down
30
- drop_table :eddy_interchange_control_numbers
31
- drop_table :eddy_functional_group_control_numbers
32
- drop_table :eddy_transaction_set_control_numbers
33
- end
34
-
35
- end