ivar 0.2.0 → 0.4.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.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/.augment-guidelines +5 -3
  3. data/.devcontainer/devcontainer.json +28 -20
  4. data/.devcontainer/post-create.sh +18 -0
  5. data/.editorconfig +35 -0
  6. data/.rubocop.yml +6 -0
  7. data/.standard.yml +1 -1
  8. data/.vscode/extensions.json +3 -1
  9. data/.vscode/launch.json +25 -0
  10. data/.vscode/settings.json +38 -2
  11. data/CHANGELOG.md +99 -1
  12. data/README.md +272 -207
  13. data/Rakefile +1 -1
  14. data/VERSION.md +46 -0
  15. data/examples/check_all_block_example.rb +84 -0
  16. data/examples/check_all_example.rb +42 -0
  17. data/examples/inheritance_with_kwarg_init.rb +156 -0
  18. data/examples/inheritance_with_positional_init.rb +142 -0
  19. data/examples/mixed_positional_and_kwarg_init.rb +125 -0
  20. data/examples/require_check_all_example.rb +23 -0
  21. data/examples/sandwich_inheritance.rb +1 -1
  22. data/examples/sandwich_with_accessors.rb +78 -0
  23. data/examples/sandwich_with_block_values.rb +54 -0
  24. data/examples/sandwich_with_checked.rb +0 -1
  25. data/examples/sandwich_with_checked_once.rb +0 -1
  26. data/examples/sandwich_with_initial_values.rb +52 -0
  27. data/examples/sandwich_with_ivar_block.rb +6 -9
  28. data/examples/sandwich_with_ivar_macro.rb +4 -4
  29. data/examples/sandwich_with_kwarg_init.rb +78 -0
  30. data/examples/sandwich_with_positional_init.rb +50 -0
  31. data/examples/sandwich_with_shared_values.rb +54 -0
  32. data/hooks/README.md +42 -0
  33. data/hooks/install.sh +12 -0
  34. data/hooks/pre-commit +54 -0
  35. data/lib/ivar/check_all.rb +7 -0
  36. data/lib/ivar/check_all_manager.rb +72 -0
  37. data/lib/ivar/check_policy.rb +29 -0
  38. data/lib/ivar/checked/class_methods.rb +19 -0
  39. data/lib/ivar/checked/instance_methods.rb +35 -0
  40. data/lib/ivar/checked.rb +17 -24
  41. data/lib/ivar/declaration.rb +30 -0
  42. data/lib/ivar/explicit_declaration.rb +56 -0
  43. data/lib/ivar/explicit_keyword_declaration.rb +24 -0
  44. data/lib/ivar/explicit_positional_declaration.rb +19 -0
  45. data/lib/ivar/macros.rb +48 -111
  46. data/lib/ivar/manifest.rb +124 -0
  47. data/lib/ivar/policies.rb +13 -1
  48. data/lib/ivar/project_root.rb +59 -0
  49. data/lib/ivar/targeted_prism_analysis.rb +144 -0
  50. data/lib/ivar/validation.rb +6 -29
  51. data/lib/ivar/version.rb +1 -1
  52. data/lib/ivar.rb +141 -9
  53. data/script/console +11 -0
  54. data/script/de-lint +2 -0
  55. data/script/de-lint-unsafe +2 -0
  56. data/script/lint +2 -0
  57. data/script/release +213 -0
  58. data/script/setup +8 -0
  59. data/script/test +2 -0
  60. metadata +46 -8
  61. data/examples/sandwich_with_kwarg.rb +0 -45
  62. data/ivar.gemspec +0 -49
  63. data/lib/ivar/auto_check.rb +0 -77
  64. data/lib/ivar/prism_analysis.rb +0 -102
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f9a15e9e7bb48429652a717400a82480167376802939f68873b575b3fca766f
4
- data.tar.gz: f57d59b780e126287966c116fd83be4848bbbb05268591a3938262fb25395a08
3
+ metadata.gz: 3116543b0e32b5de687f2d5cdc4503add2a87334a03ffc20445ad3aaeeff65f1
4
+ data.tar.gz: 5944d6a180892a4bc6ce19903ec8185a847e2b464aa1fa23b7eda03c7e6d9baa
5
5
  SHA512:
6
- metadata.gz: acc557b2df216279c16bfa299a13017eae33f52622a8f5ef75729b253f00a414f37b8a2e44ae935f3d761a1a02477b3978297751f1e94d39b90a2005fbe6d5fd
7
- data.tar.gz: 8acf31444752ee0ef75ac3a4d197448b37cac3f193e8844c57545d6d222e9899586129df849ea3a5e29628608d07a0390591455c82bdbfea60e5bf8826c347dc
6
+ metadata.gz: f90e50b2767f6f5932ff36c19beb464392beb82789eef3db02ddc52d057746892a6e1a52ebb2a72692e61958082715deaa490ea636fc4e1cd8d06284e25e2bbc
7
+ data.tar.gz: 9b53396cb198b0313d2f900162a8fb3f10821509bfc90434b9e78223ac3fc6105c5d4c3da59de7a56e90c6e0d9642d35ac1d82bff0b0f768133c4279ffdf7451
data/.augment-guidelines CHANGED
@@ -2,9 +2,11 @@
2
2
  - use modern Ruby 3.4 style and features, including pattern-matching, endless methods, etc., where appropriate.
3
3
  - avoid over-engineering. Prefer basic Ruby data types to building new abstractions. (But extract abstractions when I tell you to.)
4
4
  - avoid inline comments. Prefer "explaining variables", intention-revealing method names, and the "composed method" pattern where appropriate. Class, module, and method-documenting comments are fine.
5
- - De-lint (with standardrb) before committing. Use auto-fix and manually fix the rest.
6
- - Run all tests and fix failures before committing.
5
+ - Code style is managed with standardrb. Run it (with script/de-lint) before committing. Manually fix the rest. script/lint can be used to check for issues without updating the code.
6
+ - Run all tests and fix failures before committing.
7
7
  - Never "cheat" by making implementation code test-aware. But it is fine to make interactions with the world dependency-injectable for testing purposes.
8
8
  - Include a quote of my instruction that led to the commit in the commit message
9
9
  - Sign your commit messages with "-- Auggie".
10
- - Commit and push after making successful changes.
10
+ - Update the CHANGELOG.md unreleased section as appropriate
11
+ - Commit and push after making successful changes.
12
+ - In methods that get information and where mutation is not the goal, prefer a concise, functional-transformation style leveraging Enumerable methods over imperative approaches.
@@ -1,22 +1,30 @@
1
1
  // See https://containers.dev/implementors/json_reference/ for configuration reference
2
2
  {
3
- "name": "ivar",
4
- "build": {
5
- "dockerfile": "Dockerfile"
6
- },
7
- "remoteUser": "devcontainer",
8
- "features": {
9
- "ghcr.io/devcontainers/features/github-cli:1": {},
10
- "ghcr.io/jungaretti/features/ripgrep:1": {}
11
- },
12
- "customizations": {
13
- "vscode": {
14
- "extensions": [
15
- "connorshea.vscode-ruby-test-adapter",
16
- "stripe.endsmart",
17
- "testdouble.vscode-standard-ruby",
18
- "castwide.solargraph",
19
- ]
20
- }
21
- }
22
- }
3
+ "name": "ivar",
4
+ "build": {
5
+ "dockerfile": "Dockerfile"
6
+ },
7
+ "remoteUser": "devcontainer",
8
+ "features": {
9
+ "ghcr.io/devcontainers/features/github-cli:1": {},
10
+ "ghcr.io/jungaretti/features/ripgrep:1": {}
11
+ },
12
+ "customizations": {
13
+ "vscode": {
14
+ "extensions": [
15
+ "connorshea.vscode-ruby-test-adapter",
16
+ "stripe.endsmart",
17
+ "testdouble.vscode-standard-ruby",
18
+ "castwide.solargraph",
19
+ "github.vscode-github-actions",
20
+ "Shopify.ruby-lsp",
21
+ "EditorConfig.EditorConfig"
22
+ ],
23
+ "settings": {
24
+ "standardRuby.commandPath": "/usr/local/bundle/bin/standardrb",
25
+ "solargraph.bundlerPath": "/usr/local/bin/bundle"
26
+ }
27
+ }
28
+ },
29
+ "postCreateCommand": "bash .devcontainer/post-create.sh"
30
+ }
@@ -0,0 +1,18 @@
1
+ #!/bin/bash
2
+ set -e
3
+
4
+ echo "Running post-create setup script..."
5
+
6
+ # Install Ruby dependencies
7
+ echo "Installing Ruby dependencies with bundle install..."
8
+ bundle install
9
+
10
+ # Install Git hooks
11
+ echo "Installing Git hooks..."
12
+ if [ -f "hooks/install.sh" ]; then
13
+ ./hooks/install.sh
14
+ else
15
+ echo "Hooks installation script not found. Skipping."
16
+ fi
17
+
18
+ echo "Post-create setup completed successfully!"
data/.editorconfig ADDED
@@ -0,0 +1,35 @@
1
+ # EditorConfig is awesome: https://EditorConfig.org
2
+
3
+ # top-most EditorConfig file
4
+ root = true
5
+
6
+ # Unix-style newlines with a newline ending every file
7
+ [*]
8
+ end_of_line = lf
9
+ insert_final_newline = true
10
+ trim_trailing_whitespace = true
11
+ charset = utf-8
12
+
13
+ # 2 space indentation for Ruby files
14
+ [*.rb]
15
+ indent_style = space
16
+ indent_size = 2
17
+
18
+ # 2 space indentation for YAML files
19
+ [*.{yml,yaml}]
20
+ indent_style = space
21
+ indent_size = 2
22
+
23
+ # 2 space indentation for JSON files
24
+ [*.json]
25
+ indent_style = space
26
+ indent_size = 2
27
+
28
+ # 2 space indentation for Gemfile and Rakefile
29
+ [{Gemfile,Rakefile}]
30
+ indent_style = space
31
+ indent_size = 2
32
+
33
+ # Markdown files
34
+ [*.md]
35
+ trim_trailing_whitespace = false
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ inherit_gem:
2
+ standard: config/base.yml
3
+
4
+ AllCops:
5
+ NewCops: enable
6
+ SuggestExtensions: false
data/.standard.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  # For available configuration options, see:
2
2
  # https://github.com/testdouble/standard
3
- ruby_version: 3.4
3
+ ruby_version: 3.3
@@ -3,6 +3,8 @@
3
3
  "connorshea.vscode-ruby-test-adapter",
4
4
  "stripe.endsmart",
5
5
  "testdouble.vscode-standard-ruby",
6
- "castwide.solargraph"
6
+ "castwide.solargraph",
7
+ "github.vscode-github-actions",
8
+ "qwtel.sqlite-viewer"
7
9
  ]
8
10
  }
@@ -0,0 +1,25 @@
1
+ {
2
+ // Use IntelliSense to learn about possible attributes.
3
+ // Hover to view descriptions of existing attributes.
4
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "type": "ruby_lsp",
9
+ "name": "Debug script",
10
+ "request": "launch",
11
+ "program": "ruby ${file}"
12
+ },
13
+ {
14
+ "type": "ruby_lsp",
15
+ "name": "Debug test",
16
+ "request": "launch",
17
+ "program": "ruby -Itest ${relativeFile}"
18
+ },
19
+ {
20
+ "type": "ruby_lsp",
21
+ "name": "Attach debugger",
22
+ "request": "attach"
23
+ }
24
+ ]
25
+ }
@@ -2,13 +2,49 @@
2
2
  "rubyTestExplorer.testFramework": "minitest",
3
3
  "[ruby]": {
4
4
  "editor.formatOnType": true,
5
+ "editor.defaultFormatter": "Shopify.ruby-lsp",
6
+ "editor.formatOnSave": true
5
7
  },
6
8
  "editor.formatOnSave": true,
7
9
  "standardRuby.mode": "enableUnconditionally",
8
10
  "solargraph.diagnostics": true,
9
11
  "solargraph.formatting": true,
10
12
  "solargraph.useBundler": true,
11
- "standardRuby.commandPath": "/usr/local/bundle/bin/standardrb",
12
13
  "rubyLsp.formatter": "standard",
13
14
  "standardRuby.autofix": true,
14
- }
15
+ "rubyLsp.enabledFeatures": {
16
+ "diagnostics": true,
17
+ "documentHighlights": true,
18
+ "documentLink": true,
19
+ "documentSymbols": true,
20
+ "foldingRanges": true,
21
+ "formatting": true,
22
+ "hover": true,
23
+ "inlayHint": true,
24
+ "onTypeFormatting": true,
25
+ "selectionRanges": true,
26
+ "semanticHighlighting": true,
27
+ "completion": true,
28
+ "codeLens": true,
29
+ "definition": true,
30
+ "workspaceSymbol": true,
31
+ },
32
+ "rubyLsp.rubyVersionManager": {
33
+ "identifier": "auto"
34
+ },
35
+ "rubyLsp.addonSettings": {
36
+ "rubocop": {
37
+ "command": "standardrb",
38
+ "except": []
39
+ }
40
+ },
41
+ "editor.detectIndentation": true,
42
+ "editor.insertFinalNewline": true,
43
+ "files.insertFinalNewline": true,
44
+ "files.trimTrailingWhitespace": true,
45
+ "editor.trimAutoWhitespace": true,
46
+ "files.eol": "\n",
47
+ "editor.codeActionsOnSave": {
48
+ "source.fixAll": "explicit"
49
+ }
50
+ }
data/CHANGELOG.md CHANGED
@@ -1,9 +1,107 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
1
8
  ## [Unreleased]
2
9
 
10
+ ## [0.4.6] - 2025-05-07
11
+
12
+ ## [0.4.5] - 2025-05-07
13
+
14
+ ## [0.4.4] - 2025-05-07
15
+
16
+ ### Changed
17
+ - Enhanced release script to detect and handle uncommitted changes after the release process
18
+ - Improved release script to update Gemfile.lock before committing version changes
19
+
20
+ ## [0.4.2] - 2025-05-07
21
+
22
+ ### Added
23
+ - Enhanced release script to automatically push changes and tags to the remote repository
24
+
25
+ ### Fixed
26
+ - Fixed release script to include Gemfile.lock changes in version bump commit
27
+ - Fixed GitHub Actions workflow to prevent "frozen Gemfile.lock" errors during gem publishing
28
+
29
+ ## [0.4.0] - 2025-05-07
30
+
31
+ ### Added
32
+ - Support for initializing instance variables from keyword arguments using `ivar :@foo, init: :kwarg` or `ivar :@foo, init: :keyword`
33
+ - Proper inheritance handling for keyword argument initialization, with child class declarations taking precedence over parent class declarations
34
+ - Added Ivar::Manifest class to formalize tracking of instance variables
35
+ - Added ExplicitDeclaration and ImplicitDeclaration classes to represent different types of variable declarations
36
+ - Added callbacks for declarations: on_declare and before_init
37
+ - Added CheckPolicy module to handle class-level check policy configuration
38
+ - Added support for policy inheritance in subclasses
39
+ - Added method stash abstraction with `stash_method`, `get_method_stash`, and `get_stashed_method` on the Ivar module
40
+ - Added `get_or_create_manifest` method to make it clearer when a manifest may be created
41
+
42
+ ### Changed
43
+ - Split declaration classes into separate files for better organization:
44
+ - `Declaration` → `lib/ivar/declaration.rb`
45
+ - `ExplicitDeclaration` → `lib/ivar/explicit_declaration.rb`
46
+ - `ExplicitKeywordDeclaration` → `lib/ivar/explicit_keyword_declaration.rb`
47
+ - `ExplicitPositionalDeclaration` → `lib/ivar/explicit_positional_declaration.rb`
48
+ - Centralized handling of internal variables (those starting with `@__ivar_`) to avoid explicit declarations
49
+ - Improved filtering of internal variables during analysis phase rather than validation phase
50
+ - Refactored internal variable tracking to use the Manifest system
51
+ - Removed backwards compatibility variables (@__ivar_declared_ivars, @__ivar_initial_values, @__ivar_init_methods)
52
+ - Improved manifest ancestry handling to walk the entire ancestor chain instead of just the direct parent
53
+ - Enhanced declaration inheritance to properly handle overrides from modules and included mixins
54
+ - Optimized manifest ancestry to avoid creating unnecessary manifests for classes/modules that don't declare anything
55
+ - Simplified Manifest class to use a single declarations hash instead of separate explicit and implicit declarations
56
+ - Improved Manifest API with clearer separation between declarations (array of values) and declarations_by_name (hash)
57
+ - Simplified initialization process by combining keyword argument handling into the before_init callback
58
+ - Refactored Checked module to use the CheckPolicy module for policy configuration
59
+ - Changed default policy for Checked module from :warn_once to :warn
60
+ - Enhanced initialization process in Checked module to properly handle manifest processing
61
+ - Simplified external-process tests to directly check for warnings in stderr instead of using custom capture logic
62
+ - Updated TargetedPrismAnalysis and Checked::InstanceMethods to use the new method stash abstraction
63
+ - Extracted modules from auto_check.rb into their own files and removed auto_check.rb
64
+ - Removed PrismAnalysis class as it has been superseded by TargetedPrismAnalysis
65
+
66
+ ### Documentation
67
+ - Improved documentation for the CheckPolicy module explaining its purpose and inheritance behavior
68
+ - Enhanced documentation for the Checked module detailing its functionality and initialization process
69
+ - Added comprehensive documentation for the Manifest#add_implicits method explaining its role in tracking instance variables
70
+ - Added documentation for the new method stash abstraction methods
71
+
72
+ ## [0.3.2] - 2025-05-05
73
+
74
+ ## [0.3.1] - 2025-05-05
75
+
76
+ ## [0.3.0] - 2025-05-05
77
+
78
+ ### Added
79
+ - Support for initializing multiple instance variables to the same value using `ivar :@foo, :@bar, value: 123`
80
+ - Support for ivar declarations with a block that generates default values based on the variable name
81
+ - Support for reader, writer, and accessor keyword arguments to automatically generate attr methods
82
+
83
+ ### Changed
84
+ - Extracted check_all functionality to its own class (CheckAllManager) for better organization
85
+ - Converted module instance variables to constants where appropriate
86
+ - Moved scripts from bin/ to script/ directory for better organization
87
+ - Improved development environment with consistent line endings and editor configuration
88
+
89
+ ### Fixed
90
+ - Fixed missing trailing newlines in files
91
+ - Fixed Gemfile.lock version synchronization
92
+ - Fixed release script to use $stdin.gets instead of gets
93
+
94
+ ## [0.2.1] - 2025-05-05
95
+
96
+ ### Added
97
+ - Release automation via GitHub Actions
98
+
3
99
  ## [0.2.0] - 2025-05-01
4
100
 
5
- - Added CheckDynamic module that overrides instance_variable_get/set to check against a list of allowed variables saved at the end of initialization
101
+ ### Added
102
+ - CheckDynamic module that overrides instance_variable_get/set to check against a list of allowed variables saved at the end of initialization
6
103
 
7
104
  ## [0.1.0] - 2025-04-29
8
105
 
106
+ ### Added
9
107
  - Initial release