foobara 0.2.4 → 0.2.6
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 +10 -0
- data/README.md +94 -1
- data/projects/command_connectors/lib/foobara/command_connectors.rb +1 -0
- data/projects/command_connectors/src/command_connector.rb +16 -1
- data/projects/command_connectors/src/desugarizers/set_inputs.rb +48 -0
- data/projects/command_connectors/src/serializers/atomic_serializer.rb +5 -0
- data/projects/namespace/src/ambiguous_registry.rb +6 -0
- data/projects/type_declarations/src/attributes_transformers/set.rb +77 -0
- data/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a3b6525afdbf01d8f0d56dce1f067430111781670ebac06dc4a90297e5fb1188
|
|
4
|
+
data.tar.gz: fc79448ff4613758061b9c6336855fed97b6328356d510b77eb438097d55c99d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 46d2df3884c269014f64a0b040d867e63bf65bd4c0822a4d810e07a506f296a2c6a967be2437542e7d6b56af8080094f1510da9d8143e94880428bd816bf32ad
|
|
7
|
+
data.tar.gz: 878e815dad1a261fa6bf9fc64525d06ea6cef4c499770fa6f621487a1fce011a2781750e53b75c40f8f8d1d3db57ef4cd17e4c542fba899c2474ca3576e239ab
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
# [0.2.6] - 2025-10-30
|
|
2
|
+
|
|
3
|
+
- Add a set inputs transformer
|
|
4
|
+
|
|
5
|
+
# [0.2.5] - 2025-10-27
|
|
6
|
+
|
|
7
|
+
- Do not allow commands to be connected multiple times via symbol/string
|
|
8
|
+
- Add CommandConnector#all_exposed_command_names
|
|
9
|
+
- pry is again required by default in development/test mode but can be skipped with SKIP_PRY env var
|
|
10
|
+
|
|
1
11
|
# [0.2.4] -2025-10-26
|
|
2
12
|
|
|
3
13
|
- Remove all uses of .require_project_file and deprecate it
|
data/README.md
CHANGED
|
@@ -2124,10 +2124,103 @@ the build will fail if test coverage is below 100%.
|
|
|
2124
2124
|
|
|
2125
2125
|
You should be able to do the typical stuff:
|
|
2126
2126
|
|
|
2127
|
+
### 1. Cloning repository:
|
|
2128
|
+
Fork the repository and run this(Only for SSH):
|
|
2129
|
+
|
|
2130
|
+
```
|
|
2131
|
+
git clone git@github.com:${your_github_username}/foobara.git
|
|
2132
|
+
```
|
|
2133
|
+
|
|
2134
|
+
Create a new branch for you to push into
|
|
2135
|
+
|
|
2136
|
+
```
|
|
2137
|
+
git checkout -b <branch-name>
|
|
2138
|
+
```
|
|
2139
|
+
|
|
2140
|
+
Now navigate to project directory
|
|
2141
|
+
|
|
2127
2142
|
```
|
|
2128
|
-
git clone git@github.com:foobara/foobara
|
|
2129
2143
|
cd foobara
|
|
2144
|
+
```
|
|
2145
|
+
|
|
2146
|
+
### 2. Installing mise (LINUX/WSL)
|
|
2147
|
+
Mise is a package manager and helps with managing different versions of ruby. It allows you to switch different versions of ruby.
|
|
2148
|
+
|
|
2149
|
+
The installation docs might be updated by mise so here's the reference to that: [Installation Docs](https://mise.jdx.dev/installing-mise.html)
|
|
2150
|
+
|
|
2151
|
+
***If you already installed by following mise's docs then, you can skip this section***
|
|
2152
|
+
|
|
2153
|
+
Else to setup mise follow the script given below:
|
|
2154
|
+
|
|
2155
|
+
```
|
|
2156
|
+
sudo apt update -y && sudo apt install -y gpg wget \
|
|
2157
|
+
build-essential \
|
|
2158
|
+
libssl-dev zlib1g-dev libreadline-dev libyaml-dev libxml2-dev \
|
|
2159
|
+
libxslt1-dev libffi-dev libgdbm-dev autoconf bison
|
|
2160
|
+
wget -qO - https://mise.jdx.dev/gpg-key.pub | gpg --dearmor | sudo tee /etc/apt/keyrings/mise-archive-keyring.gpg 1> /dev/null
|
|
2161
|
+
echo "deb [signed-by=/etc/apt/keyrings/mise-archive-keyring.gpg arch=amd64] https://mise.jdx.dev/deb stable main" | sudo tee /etc/apt/sources.list.d/mise.list
|
|
2162
|
+
sudo apt update
|
|
2163
|
+
sudo apt install -y mise
|
|
2164
|
+
```
|
|
2165
|
+
|
|
2166
|
+
Verify if it's installed or not by running:
|
|
2167
|
+
|
|
2168
|
+
```
|
|
2169
|
+
mise -v
|
|
2170
|
+
```
|
|
2171
|
+
|
|
2172
|
+
It should print out an ascii-art saying "mise-en-place"
|
|
2173
|
+
|
|
2174
|
+
### 3. Install required ruby version
|
|
2175
|
+
In this project, currently we require ruby version >=3.4 so we can install it manually using the command below
|
|
2176
|
+
|
|
2177
|
+
```
|
|
2178
|
+
mise use -g ruby@3.4
|
|
2179
|
+
```
|
|
2180
|
+
|
|
2181
|
+
In case, you want to automatically activate the ruby version whenever you navigate to the directory containing .ruby-version file
|
|
2182
|
+
|
|
2183
|
+
This helps a lot when you have lot of ruby projects with different versions and don't want to switch ruby versions each time manually
|
|
2184
|
+
|
|
2185
|
+
```
|
|
2186
|
+
mise settings add idiomatic_version_file_enable_tools ruby
|
|
2187
|
+
```
|
|
2188
|
+
|
|
2189
|
+
### 4. Activating mise
|
|
2190
|
+
We can activate mise so that it will update the environment variables such that we will use the correct version of ruby.
|
|
2191
|
+
|
|
2192
|
+
```
|
|
2193
|
+
echo 'eval "$(mise activate bash)"' >> ~/.bashrc
|
|
2194
|
+
```
|
|
2195
|
+
|
|
2196
|
+
Restart the terminal
|
|
2197
|
+
|
|
2198
|
+
Now environment variables are updated and you can verify it by running:
|
|
2199
|
+
|
|
2200
|
+
```
|
|
2201
|
+
ruby -v
|
|
2202
|
+
```
|
|
2203
|
+
|
|
2204
|
+
It will print out the ruby version, which is mentioned in .ruby-version file
|
|
2205
|
+
|
|
2206
|
+
You can list out your mise tools and its versions by running:
|
|
2207
|
+
|
|
2208
|
+
```
|
|
2209
|
+
mise list
|
|
2210
|
+
```
|
|
2211
|
+
|
|
2212
|
+
### 5. Running tests
|
|
2213
|
+
Before running test-suite, we need to install all the dependencies
|
|
2214
|
+
|
|
2215
|
+
Run this to install all the dependencies:
|
|
2216
|
+
|
|
2217
|
+
```
|
|
2130
2218
|
bundle
|
|
2219
|
+
```
|
|
2220
|
+
|
|
2221
|
+
Run the tests now:
|
|
2222
|
+
|
|
2223
|
+
```
|
|
2131
2224
|
rake
|
|
2132
2225
|
```
|
|
2133
2226
|
|
|
@@ -17,6 +17,7 @@ module Foobara
|
|
|
17
17
|
CommandConnector.add_desugarizer Desugarizers.rename :response, :response_mutators
|
|
18
18
|
CommandConnector.add_desugarizer Desugarizers::Attributes::OnlyInputs
|
|
19
19
|
CommandConnector.add_desugarizer Desugarizers::Attributes::RejectInputs
|
|
20
|
+
CommandConnector.add_desugarizer Desugarizers::SetInputs
|
|
20
21
|
CommandConnector.add_desugarizer Desugarizers::Attributes::OnlyResult
|
|
21
22
|
CommandConnector.add_desugarizer Desugarizers::Attributes::RejectResult
|
|
22
23
|
CommandConnector.add_desugarizer Desugarizers::Attributes::InputsFromYaml
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
module Foobara
|
|
2
2
|
class CommandConnector
|
|
3
3
|
class UnexpectedSensitiveTypeInManifestError < StandardError; end
|
|
4
|
+
class AlreadyConnectedError < StandardError; end
|
|
4
5
|
|
|
5
6
|
include Concerns::Desugarizers
|
|
6
7
|
|
|
@@ -305,7 +306,15 @@ module Foobara
|
|
|
305
306
|
end
|
|
306
307
|
|
|
307
308
|
def connect_delayed(registerable_name, *args, **opts)
|
|
308
|
-
|
|
309
|
+
key = registerable_name.to_s
|
|
310
|
+
|
|
311
|
+
if delayed_connections.key?(key)
|
|
312
|
+
# :nocov:
|
|
313
|
+
raise AlreadyConnectedError, "Already connected #{key}"
|
|
314
|
+
# :nocov:
|
|
315
|
+
else
|
|
316
|
+
delayed_connections[key] = { args:, opts: }
|
|
317
|
+
end
|
|
309
318
|
end
|
|
310
319
|
|
|
311
320
|
def delayed_connections
|
|
@@ -313,6 +322,8 @@ module Foobara
|
|
|
313
322
|
end
|
|
314
323
|
|
|
315
324
|
def process_delayed_connections
|
|
325
|
+
return if delayed_connections.empty?
|
|
326
|
+
|
|
316
327
|
delayed_connections.each_pair do |registerable_name, arg_hash|
|
|
317
328
|
args = arg_hash[:args]
|
|
318
329
|
opts = arg_hash[:opts]
|
|
@@ -665,6 +676,10 @@ module Foobara
|
|
|
665
676
|
command_registry.foobara_all_command(mode: Namespace::LookupMode::ABSOLUTE_SINGLE_NAMESPACE)
|
|
666
677
|
end
|
|
667
678
|
|
|
679
|
+
def all_exposed_command_names
|
|
680
|
+
all_exposed_commands.map(&:full_command_name)
|
|
681
|
+
end
|
|
682
|
+
|
|
668
683
|
def all_exposed_type_names
|
|
669
684
|
# TODO: cache this or better yet cache #foobara_manifest
|
|
670
685
|
foobara_manifest[:type].keys.sort.map(&:to_s)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require_relative "../desugarizer"
|
|
2
|
+
|
|
3
|
+
module Foobara
|
|
4
|
+
module CommandConnectors
|
|
5
|
+
module Desugarizers
|
|
6
|
+
class SetInputs < Desugarizer
|
|
7
|
+
def applicable?(args_and_opts)
|
|
8
|
+
_args, opts = args_and_opts
|
|
9
|
+
|
|
10
|
+
return false unless opts.key?(:inputs_transformers)
|
|
11
|
+
|
|
12
|
+
transformers = opts[:inputs_transformers]
|
|
13
|
+
transformers = Util.array(transformers)
|
|
14
|
+
|
|
15
|
+
transformers.any? do |transformer|
|
|
16
|
+
transformer.is_a?(::Hash) && transformer.key?(:set)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def desugarize(args_and_opts)
|
|
21
|
+
args, opts = args_and_opts
|
|
22
|
+
|
|
23
|
+
transformers = opts[:inputs_transformers]
|
|
24
|
+
is_array = transformers.is_a?(::Array)
|
|
25
|
+
|
|
26
|
+
transformers = Util.array(transformers)
|
|
27
|
+
|
|
28
|
+
transformers = transformers.map do |transformer|
|
|
29
|
+
if transformer.is_a?(::Hash) && transformer.key?(:set)
|
|
30
|
+
AttributesTransformers.set(transformer[:set])
|
|
31
|
+
else
|
|
32
|
+
# TODO: add a test for this
|
|
33
|
+
# :nocov:
|
|
34
|
+
transformer
|
|
35
|
+
# :nocov:
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
transformers = transformers.first unless is_array
|
|
40
|
+
|
|
41
|
+
opts = opts.merge(inputs_transformers: transformers)
|
|
42
|
+
|
|
43
|
+
[args, opts]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
module Foobara
|
|
2
2
|
module CommandConnectors
|
|
3
3
|
module Serializers
|
|
4
|
+
# This seems to interpret "Atomic" as load the first entity you hit but not deeper entities.
|
|
5
|
+
# Other interpretations it could have been:
|
|
6
|
+
# 1) If top-level is an entity, load it and convert all nested entities to primary keys,
|
|
7
|
+
# otherwise, convert all entities to primary keys
|
|
8
|
+
# 2) Once past the first model, all entities are cast to primary keys
|
|
4
9
|
class AtomicSerializer < SuccessSerializer
|
|
5
10
|
def serialize(object)
|
|
6
11
|
case object
|
|
@@ -8,6 +8,12 @@ module Foobara
|
|
|
8
8
|
def register(scoped)
|
|
9
9
|
short_name = scoped.scoped_short_name
|
|
10
10
|
registry[short_name] ||= []
|
|
11
|
+
# This kind of error should only happen in test suites that need to unregister/reregister things
|
|
12
|
+
# with different object_ids but the same scoped full name. So will check it in commented out.
|
|
13
|
+
# if registry[short_name].map(&:scoped_full_name).include?(scoped.scoped_full_name)
|
|
14
|
+
# raise "Already registered: #{scoped.scoped_full_name}"
|
|
15
|
+
# end
|
|
16
|
+
|
|
11
17
|
registry[short_name] |= [scoped]
|
|
12
18
|
end
|
|
13
19
|
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
module Foobara
|
|
2
|
+
class AttributesTransformers < TypeDeclarations::TypedTransformer
|
|
3
|
+
class << self
|
|
4
|
+
def next_index
|
|
5
|
+
@index ||= 0
|
|
6
|
+
@index += 1
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def set(attribute_names_to_values)
|
|
10
|
+
if attribute_names_to_values.empty?
|
|
11
|
+
# :nocov:
|
|
12
|
+
raise ArgumentError, "You must specify at least one attribute name/value pair"
|
|
13
|
+
# :nocov:
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
symbol = symbol_for_attribute_names([*attribute_names_to_values.keys, next_index.to_s.to_sym])
|
|
17
|
+
existing = Set.foobara_lookup(symbol, mode: Namespace::LookupMode::DIRECT)
|
|
18
|
+
|
|
19
|
+
return existing if existing
|
|
20
|
+
|
|
21
|
+
transformer_class = Class.new(Set)
|
|
22
|
+
transformer_class.attribute_names_to_values = attribute_names_to_values
|
|
23
|
+
|
|
24
|
+
Namespace::NamespaceHelpers.foobara_autoset_scoped_path(transformer_class, set_namespace: true)
|
|
25
|
+
transformer_class.scoped_namespace.foobara_register(transformer_class)
|
|
26
|
+
|
|
27
|
+
transformer_class
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class Set < AttributesTransformers
|
|
32
|
+
class << self
|
|
33
|
+
attr_accessor :attribute_names_to_values
|
|
34
|
+
|
|
35
|
+
def symbol
|
|
36
|
+
if attribute_names_to_values
|
|
37
|
+
symbol_for_attribute_names(attribute_names_to_values.keys)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def will_set_scoped_path?
|
|
42
|
+
true
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def to_type_declaration
|
|
47
|
+
# TODO: test this
|
|
48
|
+
# :nocov:
|
|
49
|
+
if from_type
|
|
50
|
+
from_declaration = from_type.declaration_data
|
|
51
|
+
TypeDeclarations::Attributes.reject(from_declaration, *self.class.attribute_names_to_values.keys)
|
|
52
|
+
end
|
|
53
|
+
# :nocov:
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def from_type_declaration
|
|
57
|
+
if to_type
|
|
58
|
+
to_declaration = to_type.declaration_data
|
|
59
|
+
TypeDeclarations::Attributes.reject(to_declaration, *self.class.attribute_names_to_values.keys)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def transform(inputs)
|
|
64
|
+
to_merge = {}
|
|
65
|
+
|
|
66
|
+
self.class.attribute_names_to_values.each_pair do |input_name, value|
|
|
67
|
+
if value.is_a?(::Proc)
|
|
68
|
+
value = value.call
|
|
69
|
+
end
|
|
70
|
+
to_merge[input_name] = value
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
inputs.merge(to_merge)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
data/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foobara
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Miles Georgi
|
|
@@ -214,6 +214,7 @@ files:
|
|
|
214
214
|
- projects/command_connectors/src/desugarizers/attributes/reject_result.rb
|
|
215
215
|
- projects/command_connectors/src/desugarizers/auth.rb
|
|
216
216
|
- projects/command_connectors/src/desugarizers/rename_key.rb
|
|
217
|
+
- projects/command_connectors/src/desugarizers/set_inputs.rb
|
|
217
218
|
- projects/command_connectors/src/desugarizers/symbols_to_true.rb
|
|
218
219
|
- projects/command_connectors/src/request_mutator.rb
|
|
219
220
|
- projects/command_connectors/src/response_mutator.rb
|
|
@@ -422,6 +423,7 @@ files:
|
|
|
422
423
|
- projects/type_declarations/src/attributes_transformers/from_yaml.rb
|
|
423
424
|
- projects/type_declarations/src/attributes_transformers/only.rb
|
|
424
425
|
- projects/type_declarations/src/attributes_transformers/reject.rb
|
|
426
|
+
- projects/type_declarations/src/attributes_transformers/set.rb
|
|
425
427
|
- projects/type_declarations/src/caster.rb
|
|
426
428
|
- projects/type_declarations/src/desugarizer.rb
|
|
427
429
|
- projects/type_declarations/src/desugarizer_pipeline.rb
|