digicus_web_backend 0.1.2
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 +7 -0
- data/lib/digicus_web_backend/compiler.rb +67 -0
- data/lib/digicus_web_backend.rb +44 -0
- metadata +46 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: c36306a10b9e5793ca5cae1e7dd61e6bbe92da01b3a1796730083d1f43283203
         | 
| 4 | 
            +
              data.tar.gz: 7b7cb4e821b4bcf16a88d236deeb1e3e70e660b3ecf1ab96add756fede81ada3
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 30404944e87af48ba958e630c00ccc53c982d0e203c5137b85be52b38ca45ad8522fdf797f5f2c9c8d602cf4736dd8261c56ce61b2b050ed4a68f036c477dfcd
         | 
| 7 | 
            +
              data.tar.gz: c0722c6b768d85114997a506be7aec483cc2af48f9f58b9a67b65553bb4f7a2cb55305f2bbb0126167f8e59159dd152aef0207930e40bf690e17ffff2fc8485a
         | 
| @@ -0,0 +1,67 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'dtr_core'
         | 
| 4 | 
            +
            require 'json'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            module DigicusWebBackend
         | 
| 7 | 
            +
              # This is a simple compiler class that takes a DTR code and transpiles it to JSON.
         | 
| 8 | 
            +
              class Compiler
         | 
| 9 | 
            +
                attr_reader :contract
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def initialize(dtr_code)
         | 
| 12 | 
            +
                  @contract = DTRCore::Contract.from_dtr_raw(dtr_code)
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def self.from_dtr(dtr_code)
         | 
| 16 | 
            +
                  new(dtr_code).from_dtr
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def from_dtr
         | 
| 20 | 
            +
                  result = {
         | 
| 21 | 
            +
                    contract_name:,
         | 
| 22 | 
            +
                    contract_state:,
         | 
| 23 | 
            +
                    contract_interface:,
         | 
| 24 | 
            +
                    contract_user_defined_types:
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                  }
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  result.to_json
         | 
| 29 | 
            +
                end
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                private
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def contract_name
         | 
| 34 | 
            +
                  contract.name
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                def contract_state
         | 
| 38 | 
            +
                  contract.state&.map do |s|
         | 
| 39 | 
            +
                    {
         | 
| 40 | 
            +
                      name: s.name,
         | 
| 41 | 
            +
                      type: s.type,
         | 
| 42 | 
            +
                      initial_value: s.initial_value
         | 
| 43 | 
            +
                    }.to_json
         | 
| 44 | 
            +
                  end
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                def contract_interface
         | 
| 48 | 
            +
                  contract.interface&.map do |f|
         | 
| 49 | 
            +
                    {
         | 
| 50 | 
            +
                      name: f.name,
         | 
| 51 | 
            +
                      instructions: f.instructions.map(&:to_json),
         | 
| 52 | 
            +
                      inputs: f&.inputs,
         | 
| 53 | 
            +
                      output: f&.output
         | 
| 54 | 
            +
                    }.to_json
         | 
| 55 | 
            +
                  end
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                def contract_user_defined_types
         | 
| 59 | 
            +
                  contract.user_defined_types&.map do |t|
         | 
| 60 | 
            +
                    {
         | 
| 61 | 
            +
                      name: t.name,
         | 
| 62 | 
            +
                      attributes: t.attributes
         | 
| 63 | 
            +
                    }.to_json
         | 
| 64 | 
            +
                  end
         | 
| 65 | 
            +
                end
         | 
| 66 | 
            +
              end
         | 
| 67 | 
            +
            end
         | 
| @@ -0,0 +1,44 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # Core logic for consuming Digicus Textual Representation (DTR) files.
         | 
| 4 | 
            +
            module DigicusWebBackend
         | 
| 5 | 
            +
              autoload :Compiler, './lib/digicus_web_backend/compiler'
         | 
| 6 | 
            +
            end
         | 
| 7 | 
            +
             | 
| 8 | 
            +
            def silence_streams
         | 
| 9 | 
            +
              original_stdout = $stdout
         | 
| 10 | 
            +
              original_stderr = $stderr
         | 
| 11 | 
            +
              $stdout = File.new('/dev/null', 'w')
         | 
| 12 | 
            +
              $stderr = File.new('/dev/null', 'w')
         | 
| 13 | 
            +
              yield
         | 
| 14 | 
            +
            ensure
         | 
| 15 | 
            +
              $stdout = original_stdout
         | 
| 16 | 
            +
              $stderr = original_stderr
         | 
| 17 | 
            +
            end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            if __FILE__ == $PROGRAM_NAME
         | 
| 20 | 
            +
              input = ARGV[0]
         | 
| 21 | 
            +
             | 
| 22 | 
            +
              if input == 'version'
         | 
| 23 | 
            +
                gemspec_path = 'digicus_web_backend.gemspec'
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                # Extract version from gemspec
         | 
| 26 | 
            +
                gemspec = File.read(gemspec_path)
         | 
| 27 | 
            +
                version_match = gemspec.match(/\.version\s*=\s*["']([^"']+)["']/)
         | 
| 28 | 
            +
                version = version_match[1] if version_match
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                puts version
         | 
| 31 | 
            +
              else
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                if input.nil?
         | 
| 34 | 
            +
                  puts 'Usage: ./digicus_web_backend <file_path>'
         | 
| 35 | 
            +
                  exit(1)
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                json_for_web = silence_streams do
         | 
| 39 | 
            +
                  DigicusWebBackend::Compiler.from_dtr(File.read(input))
         | 
| 40 | 
            +
                end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                puts json_for_web
         | 
| 43 | 
            +
              end
         | 
| 44 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,46 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: digicus_web_backend
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.1.2
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Rob Durst
         | 
| 8 | 
            +
            autorequire:
         | 
| 9 | 
            +
            bindir: bin
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2024-07-17 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies: []
         | 
| 13 | 
            +
            description: DTR to JSON compiler.
         | 
| 14 | 
            +
            email:
         | 
| 15 | 
            +
            - me@robdurst.com
         | 
| 16 | 
            +
            executables: []
         | 
| 17 | 
            +
            extensions: []
         | 
| 18 | 
            +
            extra_rdoc_files: []
         | 
| 19 | 
            +
            files:
         | 
| 20 | 
            +
            - lib/digicus_web_backend.rb
         | 
| 21 | 
            +
            - lib/digicus_web_backend/compiler.rb
         | 
| 22 | 
            +
            homepage: https://spaced-out-thoughts-dev-foundation.github.io/digicus/
         | 
| 23 | 
            +
            licenses:
         | 
| 24 | 
            +
            - MIT
         | 
| 25 | 
            +
            metadata:
         | 
| 26 | 
            +
              rubygems_mfa_required: 'true'
         | 
| 27 | 
            +
            post_install_message:
         | 
| 28 | 
            +
            rdoc_options: []
         | 
| 29 | 
            +
            require_paths:
         | 
| 30 | 
            +
            - lib
         | 
| 31 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 32 | 
            +
              requirements:
         | 
| 33 | 
            +
              - - ">="
         | 
| 34 | 
            +
                - !ruby/object:Gem::Version
         | 
| 35 | 
            +
                  version: 3.2.0
         | 
| 36 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 37 | 
            +
              requirements:
         | 
| 38 | 
            +
              - - ">="
         | 
| 39 | 
            +
                - !ruby/object:Gem::Version
         | 
| 40 | 
            +
                  version: '0'
         | 
| 41 | 
            +
            requirements: []
         | 
| 42 | 
            +
            rubygems_version: 3.5.13
         | 
| 43 | 
            +
            signing_key:
         | 
| 44 | 
            +
            specification_version: 4
         | 
| 45 | 
            +
            summary: DTR to JSON compiler.
         | 
| 46 | 
            +
            test_files: []
         |