foobara 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 -0
 - data/projects/command/src/concerns/domain_mappers.rb +23 -10
 - data/projects/command_connectors_http/src/http/commands/help/templates/entity.html.erb +11 -1
 - data/projects/command_connectors_http/src/http/commands/help/templates/model.html.erb +8 -1
 - data/projects/domain/src/domain_mapper/registry.rb +31 -0
 - data/projects/domain/src/domain_module_extension.rb +1 -14
 - data/projects/foobara/lib/foobara/all.rb +0 -3
 - data/projects/manifest/src/foobara/manifest/entity.rb +4 -0
 - data/projects/manifest/src/foobara/manifest/model.rb +4 -0
 - metadata +5 -8
 - data/projects/version/lib/foobara/version.rb +0 -4
 - data/projects/version/src/version.rb +0 -5
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 0c67b545a741174d59b5a74553449d32169d2745b33824ad14ee21e4dac7085b
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1e54750375fe79b83ee0bbf08e460021193124e5f7f661c4eef39afd53c3573b
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 18d0063f27c3c708b30603091ddaaba2bb11ad864d6902b705f0b120ba64ed32f33f64023561a11086e3cf266cf426b927deefc44e173d625156e6aa4d2c9a19
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 84f34116a5033ae5c2f34c6e408520cb61a2b0efbedbb59b1b07792c35992c1622153a4b254c8c5c4bd3782b6a22c0a04ec828160f3a0c11e0729871a160ccc7
         
     | 
    
        data/CHANGELOG.md
    CHANGED
    
    | 
         @@ -1,3 +1,8 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ## [0.0.3] - 2024-08-15
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            - Do not automatically try to map subcommand types to calling command result type
         
     | 
| 
      
 4 
     | 
    
         
            +
            - Add some crude help info for models in http connector
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
       1 
6 
     | 
    
         
             
            ## [0.0.2] - 2024-06-20
         
     | 
| 
       2 
7 
     | 
    
         | 
| 
       3 
8 
     | 
    
         
             
            - Make sure content-type is json if we are json serializing an HTTP response
         
     | 
| 
         @@ -4,22 +4,35 @@ module Foobara 
     | 
|
| 
       4 
4 
     | 
    
         
             
                  module DomainMappers
         
     | 
| 
       5 
5 
     | 
    
         
             
                    include Concern
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                    def run_mapped_subcommand!(subcommand_class,  
     | 
| 
      
 7 
     | 
    
         
            +
                    def run_mapped_subcommand!(subcommand_class, *args)
         
     | 
| 
      
 8 
     | 
    
         
            +
                      unmapped_inputs, has_result_type, result_type =
         
     | 
| 
      
 9 
     | 
    
         
            +
                        case args.size
         
     | 
| 
      
 10 
     | 
    
         
            +
                        when 1
         
     | 
| 
      
 11 
     | 
    
         
            +
                          [args.first]
         
     | 
| 
      
 12 
     | 
    
         
            +
                        when 2
         
     | 
| 
      
 13 
     | 
    
         
            +
                          [args[1], true, args[0]]
         
     | 
| 
      
 14 
     | 
    
         
            +
                        else
         
     | 
| 
      
 15 
     | 
    
         
            +
                          # :nocov:
         
     | 
| 
      
 16 
     | 
    
         
            +
                          raise ArgumentError,
         
     | 
| 
      
 17 
     | 
    
         
            +
                                "Wrong number of arguments: (#{args.size}. Expected 2 or 3 argument."
         
     | 
| 
      
 18 
     | 
    
         
            +
                          # :nocov:
         
     | 
| 
      
 19 
     | 
    
         
            +
                        end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
       8 
21 
     | 
    
         
             
                      inputs = domain_map!(unmapped_inputs, to: subcommand_class, strict: true)
         
     | 
| 
       9 
22 
     | 
    
         | 
| 
       10 
23 
     | 
    
         
             
                      result = run_subcommand!(subcommand_class, inputs)
         
     | 
| 
       11 
24 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
                       
     | 
| 
       13 
     | 
    
         
            -
                         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
      
 25 
     | 
    
         
            +
                      if has_result_type
         
     | 
| 
      
 26 
     | 
    
         
            +
                        result_mapper = self.class.domain.foobara_domain_mapper_registry.lookup!(
         
     | 
| 
      
 27 
     | 
    
         
            +
                          from: result,
         
     | 
| 
      
 28 
     | 
    
         
            +
                          to: result_type,
         
     | 
| 
      
 29 
     | 
    
         
            +
                          strict: true
         
     | 
| 
      
 30 
     | 
    
         
            +
                        )
         
     | 
| 
       17 
31 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
                        result_mapper.map(result)
         
     | 
| 
       20 
     | 
    
         
            -
                      else
         
     | 
| 
       21 
     | 
    
         
            -
                        result
         
     | 
| 
      
 32 
     | 
    
         
            +
                        result = result_mapper.map(result)
         
     | 
| 
       22 
33 
     | 
    
         
             
                      end
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
                      result
         
     | 
| 
       23 
36 
     | 
    
         
             
                    end
         
     | 
| 
       24 
37 
     | 
    
         | 
| 
       25 
38 
     | 
    
         
             
                    def domain_map(...)
         
     | 
| 
         @@ -1 +1,11 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
             
     | 
| 
      
 1 
     | 
    
         
            +
            <h1><%= full_entity_name %></h1>
         
     | 
| 
      
 2 
     | 
    
         
            +
            <p><%= description %></p>
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            <h2>Attributes</h2>
         
     | 
| 
      
 5 
     | 
    
         
            +
            <%= render_html_list(attributes_type) %>
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            <h2>Primary Key</h2>
         
     | 
| 
      
 8 
     | 
    
         
            +
            <%= primary_key_attribute %>
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
            <h2>Possible Errors</h2>
         
     | 
| 
      
 11 
     | 
    
         
            +
            <%= render_html_list(possible_errors) %>
         
     | 
| 
         @@ -1,5 +1,30 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            module Foobara
         
     | 
| 
       2 
2 
     | 
    
         
             
              class DomainMapper
         
     | 
| 
      
 3 
     | 
    
         
            +
                class NoDomainMapperFoundError < StandardError
         
     | 
| 
      
 4 
     | 
    
         
            +
                  attr_accessor :value, :from, :to, :has_value
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                  def initialize(from, to, **opts)
         
     | 
| 
      
 7 
     | 
    
         
            +
                    valid_keys = [:value]
         
     | 
| 
      
 8 
     | 
    
         
            +
                    invalid_keys = opts.keys - [:value]
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                    if invalid_keys.any?
         
     | 
| 
      
 11 
     | 
    
         
            +
                      # :nocov:
         
     | 
| 
      
 12 
     | 
    
         
            +
                      raise ArgumentError, "Invalid keys: #{invalid_keys.join(", ")}. expected one of: #{valid_keys.join(", ")}"
         
     | 
| 
      
 13 
     | 
    
         
            +
                      # :nocov:
         
     | 
| 
      
 14 
     | 
    
         
            +
                    end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    if opts.key?(:value)
         
     | 
| 
      
 17 
     | 
    
         
            +
                      self.has_value = true
         
     | 
| 
      
 18 
     | 
    
         
            +
                      self.value = opts[:value]
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    self.from = from
         
     | 
| 
      
 22 
     | 
    
         
            +
                    self.to = to
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                    super("No domain mapper found for #{value}. from: #{from}. to: #{to}.")
         
     | 
| 
      
 25 
     | 
    
         
            +
                  end
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
       3 
28 
     | 
    
         
             
                class Registry
         
     | 
| 
       4 
29 
     | 
    
         
             
                  class AmbiguousDomainMapperError < StandardError
         
     | 
| 
       5 
30 
     | 
    
         
             
                    attr_accessor :candidates, :from, :to
         
     | 
| 
         @@ -17,6 +42,12 @@ module Foobara 
     | 
|
| 
       17 
42 
     | 
    
         
             
                    mappers << mapper
         
     | 
| 
       18 
43 
     | 
    
         
             
                  end
         
     | 
| 
       19 
44 
     | 
    
         | 
| 
      
 45 
     | 
    
         
            +
                  def lookup!(from: nil, to: nil, strict: false)
         
     | 
| 
      
 46 
     | 
    
         
            +
                    result = lookup(from:, to:, strict:)
         
     | 
| 
      
 47 
     | 
    
         
            +
             
     | 
| 
      
 48 
     | 
    
         
            +
                    result || raise(NoDomainMapperFoundError.new(from, to))
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
       20 
51 
     | 
    
         
             
                  def lookup(from: nil, to: nil, strict: false)
         
     | 
| 
       21 
52 
     | 
    
         
             
                    candidates = mappers.select do |mapper|
         
     | 
| 
       22 
53 
     | 
    
         
             
                      mapper.applicable?(from, to)
         
     | 
| 
         @@ -4,18 +4,6 @@ module Foobara 
     | 
|
| 
       4 
4 
     | 
    
         
             
                class AlreadyRegisteredError < StandardError; end
         
     | 
| 
       5 
5 
     | 
    
         
             
                class CannotSetTypeConstantError < StandardError; end
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
       7 
     | 
    
         
            -
                class NoDomainMapperFoundError < StandardError
         
     | 
| 
       8 
     | 
    
         
            -
                  attr_accessor :value, :from, :to
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                  def initialize(value, from, to)
         
     | 
| 
       11 
     | 
    
         
            -
                    self.value = value
         
     | 
| 
       12 
     | 
    
         
            -
                    self.from = from
         
     | 
| 
       13 
     | 
    
         
            -
                    self.to = to
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                    super("No domain mapper found for #{value}. from: #{from}. to: #{to}.")
         
     | 
| 
       16 
     | 
    
         
            -
                  end
         
     | 
| 
       17 
     | 
    
         
            -
                end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
7 
     | 
    
         
             
                class << self
         
     | 
| 
       20 
8 
     | 
    
         
             
                  def global
         
     | 
| 
       21 
9 
     | 
    
         
             
                    GlobalDomain
         
     | 
| 
         @@ -165,9 +153,8 @@ module Foobara 
     | 
|
| 
       165 
153 
     | 
    
         | 
| 
       166 
154 
     | 
    
         
             
                    def foobara_domain_map!(value, from: value, to: nil, strict: false)
         
     | 
| 
       167 
155 
     | 
    
         
             
                      mapper = foobara_domain_mapper_registry.lookup(from:, to:, strict:)
         
     | 
| 
       168 
     | 
    
         
            -
             
     | 
| 
       169 
156 
     | 
    
         
             
                      unless mapper
         
     | 
| 
       170 
     | 
    
         
            -
                        raise NoDomainMapperFoundError.new( 
     | 
| 
      
 157 
     | 
    
         
            +
                        raise Foobara::DomainMapper::NoDomainMapperFoundError.new(from, to, value:)
         
     | 
| 
       171 
158 
     | 
    
         
             
                      end
         
     | 
| 
       172 
159 
     | 
    
         | 
| 
       173 
160 
     | 
    
         
             
                      mapper.call(value)
         
     | 
| 
         @@ -25,6 +25,10 @@ module Foobara 
     | 
|
| 
       25 
25 
     | 
    
         
             
                    super - [primary_key_name]
         
     | 
| 
       26 
26 
     | 
    
         
             
                  end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
      
 28 
     | 
    
         
            +
                  def full_entity_name
         
     | 
| 
      
 29 
     | 
    
         
            +
                    full_model_name
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
       28 
32 
     | 
    
         
             
                  def associations
         
     | 
| 
       29 
33 
     | 
    
         
             
                    @associations ||= self[:associations].to_h do |path_key, type_name|
         
     | 
| 
       30 
34 
     | 
    
         
             
                      [path_key.to_sym, Type.new(root_manifest, [:type, type_name])]
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,14 +1,14 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: foobara
         
     | 
| 
       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 
     | 
    
         
             
            - Miles Georgi
         
     | 
| 
       8 
     | 
    
         
            -
            autorequire: 
     | 
| 
      
 8 
     | 
    
         
            +
            autorequire:
         
     | 
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
     | 
    
         
            -
            date: 2024- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2024-08-17 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies:
         
     | 
| 
       13 
13 
     | 
    
         
             
            - !ruby/object:Gem::Dependency
         
     | 
| 
       14 
14 
     | 
    
         
             
              name: foobara-util
         
     | 
| 
         @@ -378,8 +378,6 @@ files: 
     | 
|
| 
       378 
378 
     | 
    
         
             
            - projects/value/src/processor/selection.rb
         
     | 
| 
       379 
379 
     | 
    
         
             
            - projects/value/src/transformer.rb
         
     | 
| 
       380 
380 
     | 
    
         
             
            - projects/value/src/validator.rb
         
     | 
| 
       381 
     | 
    
         
            -
            - projects/version/lib/foobara/version.rb
         
     | 
| 
       382 
     | 
    
         
            -
            - projects/version/src/version.rb
         
     | 
| 
       383 
381 
     | 
    
         
             
            - projects/weak_object_set/lib/foobara/weak_object_set.rb
         
     | 
| 
       384 
382 
     | 
    
         
             
            - projects/weak_object_set/src/weak_object_set.rb
         
     | 
| 
       385 
383 
     | 
    
         
             
            homepage: https://github.com/foobara/foobara
         
     | 
| 
         @@ -390,7 +388,7 @@ metadata: 
     | 
|
| 
       390 
388 
     | 
    
         
             
              source_code_uri: https://github.com/foobara/foobara
         
     | 
| 
       391 
389 
     | 
    
         
             
              changelog_uri: https://github.com/foobara/foobara/CHANGELOG.md
         
     | 
| 
       392 
390 
     | 
    
         
             
              rubygems_mfa_required: 'true'
         
     | 
| 
       393 
     | 
    
         
            -
            post_install_message: 
     | 
| 
      
 391 
     | 
    
         
            +
            post_install_message:
         
     | 
| 
       394 
392 
     | 
    
         
             
            rdoc_options: []
         
     | 
| 
       395 
393 
     | 
    
         
             
            require_paths:
         
     | 
| 
       396 
394 
     | 
    
         
             
            - "./projects/builtin_types/lib"
         
     | 
| 
         @@ -417,7 +415,6 @@ require_paths: 
     | 
|
| 
       417 
415 
     | 
    
         
             
            - "./projects/type_declarations/lib"
         
     | 
| 
       418 
416 
     | 
    
         
             
            - "./projects/types/lib"
         
     | 
| 
       419 
417 
     | 
    
         
             
            - "./projects/value/lib"
         
     | 
| 
       420 
     | 
    
         
            -
            - "./projects/version/lib"
         
     | 
| 
       421 
418 
     | 
    
         
             
            - "./projects/weak_object_set/lib"
         
     | 
| 
       422 
419 
     | 
    
         
             
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
       423 
420 
     | 
    
         
             
              requirements:
         
     | 
| 
         @@ -431,7 +428,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement 
     | 
|
| 
       431 
428 
     | 
    
         
             
                  version: '0'
         
     | 
| 
       432 
429 
     | 
    
         
             
            requirements: []
         
     | 
| 
       433 
430 
     | 
    
         
             
            rubygems_version: 3.4.10
         
     | 
| 
       434 
     | 
    
         
            -
            signing_key: 
     | 
| 
      
 431 
     | 
    
         
            +
            signing_key:
         
     | 
| 
       435 
432 
     | 
    
         
             
            specification_version: 4
         
     | 
| 
       436 
433 
     | 
    
         
             
            summary: Implements command pattern for encapsulating and managing domain complexity
         
     | 
| 
       437 
434 
     | 
    
         
             
              as well as many supporting libraries including entities.
         
     |