From ea596519f99e159f1c3105ee90e892078b3a6a8a Mon Sep 17 00:00:00 2001 From: Paul Bob Date: Thu, 10 Oct 2024 16:26:05 +0300 Subject: [PATCH 1/5] update readme --- README.md | 124 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 112 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 06c0474..e087eae 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,128 @@ -# PropInitializer -Short description and motivation. +# PropInitializer Gem Documentation -## Usage -How to use my plugin. +## Overview + +The `PropInitializer` gem is a flexible tool for defining properties on Ruby classes. This gem is an adaptation of the [Literal Gem](https://github.com/joeldrapper/literal), with custom modifications tailored to the needs of [Avo](https://avohq.io). We sincerely thank [Joel Drapper](https://github.com/joeldrapper) for the inspiration and base code that made this possible. + +With `PropInitializer`, you can easily declare properties for any class, giving you flexible options for default values and more. However, unlike [Literal](https://github.com/joeldrapper/literal), `PropInitializer` simplifies by removing strict typing requirements, providing a more lightweight and adaptable interface. + +--- ## Installation -Add this line to your application's Gemfile: + +To use `PropInitializer` in your Ruby project, add the following to your Gemfile: ```ruby gem "prop_initializer" ``` -And then execute: +Then, run the bundle command to install it: + ```bash -$ bundle +bundle install ``` -Or install it yourself as: -```bash -$ gem install prop_initializer +## Usage + +To start using `PropInitializer`, you need to include the module in the class where you want to define properties. + +### Step 1: Extend the Properties Module + +In any class, extend `PropInitializer::Properties` to enable the ability to define properties: + +```ruby +class MyClass + extend PropInitializer::Properties +end ``` -## Contributing -Contribution directions go here. +### Step 2: Define Properties + +Properties can be declared using the `prop` method, which generates writers and makes them available as instance variables (e.g., `@name`, `@size`, etc.). + +#### Basic Syntax: + +```ruby +prop :name # A simple property, accessible via @name +prop :size, default: :md # A property with a default value of :md +prop :args, kind: :* # A property for handling splat arguments +prop :kwargs, kind: :** # A property for handling keyword arguments +``` + +#### Custom Property with Block: + +You can define a custom processing block when declaring a property, for example: + +```ruby +prop :icon do |value| + value&.to_sym # Converts the property value to a symbol +end +``` + +### Step 3: Accessing Properties + +By default, `PropInitializer` generates a writer for each declared property. The properties are stored as instance variables, which can be accessed within the class: + +```ruby +@name # Accesses the value of the 'name' property +@size # Accesses the value of the 'size' property +``` + +#### Public Reader: + +If you want to generate a public reader (getter) for a property, use the `reader: :public` option when defining the property: + +```ruby +prop :title, reader: :public +``` + +This will automatically generate a public getter method, allowing you to retrieve the property like so: + +```ruby +my_class_instance.title # Public getter for the 'title' property +``` + +### Example: + +```ruby +class MyComponent + extend PropInitializer::Properties + + prop :name, reader: :public + prop :size, default: :md, reader: :public + prop :args, kind: :* + prop :kwargs, kind: :** + prop :icon do |value| + value&.to_sym + end +end + +component = MyComponent.new(name: "Button", size: :lg) +component.name # => "Button" +component.size # => :lg +``` + +--- + +## Key Differences from [Literal](https://github.com/joeldrapper/literal) + +While `PropInitializer` is based on the [Literal Gem](https://github.com/joeldrapper/literal), there are some important differences: + +- **No Type Requirement:** [Literal](https://github.com/joeldrapper/literal)'s properties system enforces types, but `PropInitializer` omits this for flexibility. You can define properties without needing to specify a type. + +- **Simplified Initializer:** The initialization process has been modified to avoid requiring types at the time of property definition. + +--- + +## Acknowledgements + +Special thanks to the team at [Literal](https://github.com/joeldrapper/literal) for their pioneering work on property-based object initialization. This gem builds upon the foundation laid by their work. + +If you're looking for a more type-strict approach to property initialization, we encourage you to check out the original [Literal Gem](https://github.com/joeldrapper/literal). + +--- + +Thank you for using `PropInitializer`! We hope this tool helps make your property management more efficient and adaptable in your Ruby projects. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). From be705b7e615977706b96eacbe14064010923c4ea Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Fri, 11 Oct 2024 08:48:57 +0300 Subject: [PATCH 2/5] Apply suggestions from code review --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index e087eae..694e45b 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,17 @@ ## Overview -The `PropInitializer` gem is a flexible tool for defining properties on Ruby classes. This gem is an adaptation of the [Literal Gem](https://github.com/joeldrapper/literal), with custom modifications tailored to the needs of [Avo](https://avohq.io). We sincerely thank [Joel Drapper](https://github.com/joeldrapper) for the inspiration and base code that made this possible. +The `prop_initializer` gem is a flexible tool for defining properties on Ruby classes. -With `PropInitializer`, you can easily declare properties for any class, giving you flexible options for default values and more. However, unlike [Literal](https://github.com/joeldrapper/literal), `PropInitializer` simplifies by removing strict typing requirements, providing a more lightweight and adaptable interface. +It's a fork of the [Literal Gem](https://github.com/joeldrapper/literal), with a few tweaks. We sincerely thank [Joel Drapper](https://github.com/joeldrapper) for the inspiration and base code that made this possible. + +With `prop_initializer`, you can easily declare properties for any class, giving you flexible options for default values and more. However, the scope is narrowed down by removing strict typing requirements, providing a more lightweight and adaptable interface. --- ## Installation -To use `PropInitializer` in your Ruby project, add the following to your Gemfile: +To use `prop_initializer ` in your Ruby project, add the following to your Gemfile: ```ruby gem "prop_initializer" @@ -24,7 +26,7 @@ bundle install ## Usage -To start using `PropInitializer`, you need to include the module in the class where you want to define properties. +To start using `prop_initializer `, you need to include the module in the class where you want to define properties. ### Step 1: Extend the Properties Module @@ -106,9 +108,9 @@ component.size # => :lg ## Key Differences from [Literal](https://github.com/joeldrapper/literal) -While `PropInitializer` is based on the [Literal Gem](https://github.com/joeldrapper/literal), there are some important differences: +While `prop_initializer` is based on the [Literal Gem](https://github.com/joeldrapper/literal), there are some important differences: -- **No Type Requirement:** [Literal](https://github.com/joeldrapper/literal)'s properties system enforces types, but `PropInitializer` omits this for flexibility. You can define properties without needing to specify a type. +- **No Type Requirement:** [Literal](https://github.com/joeldrapper/literal)'s properties system enforces types, while `prop_initializer` omits them for flexibility. You can define properties without needing to specify a type. - **Simplified Initializer:** The initialization process has been modified to avoid requiring types at the time of property definition. @@ -122,7 +124,7 @@ If you're looking for a more type-strict approach to property initialization, we --- -Thank you for using `PropInitializer`! We hope this tool helps make your property management more efficient and adaptable in your Ruby projects. +Thank you for using `prop_initializer`! We hope this tool helps make your property management more efficient and adaptable in your Ruby projects. ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). From c55f259e844a7a4ed4c662b0e4bb94dbfca49d83 Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Fri, 11 Oct 2024 07:52:34 +0200 Subject: [PATCH 3/5] add other OSS repos --- Gemfile.lock | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 19 ++++++----- 2 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 Gemfile.lock diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..8d2fa79 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,90 @@ +PATH + remote: . + specs: + prop_initializer (0.1.0) + zeitwerk (>= 2.6.18) + +GEM + remote: https://rubygems.org/ + specs: + activesupport (7.2.1) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.3.1) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + logger (>= 1.4.2) + minitest (>= 5.1) + securerandom (>= 0.3) + tzinfo (~> 2.0, >= 2.0.5) + ast (2.4.2) + base64 (0.2.0) + bigdecimal (3.1.8) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + drb (2.2.1) + i18n (1.14.6) + concurrent-ruby (~> 1.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + logger (1.6.1) + minitest (5.25.1) + nio4r (2.7.3) + parallel (1.26.3) + parser (3.3.5.0) + ast (~> 2.4.1) + racc + puma (6.4.3) + nio4r (~> 2.0) + racc (1.8.1) + rack (3.1.7) + rainbow (3.1.1) + regexp_parser (2.9.2) + rubocop (1.66.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.4, < 3.0) + rubocop-ast (>= 1.32.2, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.32.3) + parser (>= 3.3.1.0) + rubocop-minitest (0.36.0) + rubocop (>= 1.61, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-performance (1.22.1) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.26.2) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.52.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails-omakase (1.0.0) + rubocop + rubocop-minitest + rubocop-performance + rubocop-rails + ruby-progressbar (1.13.0) + securerandom (0.3.1) + sqlite3 (2.1.0-arm64-darwin) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + unicode-display_width (2.6.0) + zeitwerk (2.6.18) + +PLATFORMS + arm64-darwin + +DEPENDENCIES + prop_initializer! + puma + rubocop-rails-omakase + sqlite3 + +BUNDLED WITH + 2.5.6 diff --git a/README.md b/README.md index 694e45b..7c87054 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,6 @@ It's a fork of the [Literal Gem](https://github.com/joeldrapper/literal), with a With `prop_initializer`, you can easily declare properties for any class, giving you flexible options for default values and more. However, the scope is narrowed down by removing strict typing requirements, providing a more lightweight and adaptable interface. ---- - ## Installation To use `prop_initializer ` in your Ruby project, add the following to your Gemfile: @@ -104,8 +102,6 @@ component.name # => "Button" component.size # => :lg ``` ---- - ## Key Differences from [Literal](https://github.com/joeldrapper/literal) While `prop_initializer` is based on the [Literal Gem](https://github.com/joeldrapper/literal), there are some important differences: @@ -114,17 +110,24 @@ While `prop_initializer` is based on the [Literal Gem](https://github.com/joeldr - **Simplified Initializer:** The initialization process has been modified to avoid requiring types at the time of property definition. ---- - ## Acknowledgements Special thanks to the team at [Literal](https://github.com/joeldrapper/literal) for their pioneering work on property-based object initialization. This gem builds upon the foundation laid by their work. If you're looking for a more type-strict approach to property initialization, we encourage you to check out the original [Literal Gem](https://github.com/joeldrapper/literal). ---- - Thank you for using `prop_initializer`! We hope this tool helps make your property management more efficient and adaptable in your Ruby projects. +## Open Source + + - [`active_storage-blurhash`](https://github.com/avo-hq/active_storage-blurhash) - A plug-n-play [blurhash](https://blurha.sh/) integration for images stored in ActiveStorage + - [`avo`](https://github.com/avo-hq/avo) - Build Content management systems with Ruby on Rails + - [`class_variants`](https://github.com/avo-hq/class_variants) - Easily configure styles and apply them as classes. Very useful when you're implementing Tailwind CSS components and call them with different states. + - [`stimulus-confetti`](https://github.com/avo-hq/stimulus-confetti) - The easiest way to add confetti to your StimulusJS app + +## Try Avo ⭐️ + +If you enjoyed this gem try out [Avo](https://github.com/avo-hq/avo). It helps developers build Internal Tools, Admin Panels, CMSes, CRMs, and any other type of Business Apps 10x faster on top of Ruby on Rails. + ## License The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). From d2d55006fd75c3173405c1d6b4e23b787ef2bb87 Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Fri, 11 Oct 2024 07:53:04 +0200 Subject: [PATCH 4/5] wip --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c87054..92618c7 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# PropInitializer Gem Documentation +# `prop_initializer` ## Overview From 2b5491aa5212196bc2dd2d2c517649c4fb0cd2d2 Mon Sep 17 00:00:00 2001 From: Adrian Marin Date: Fri, 11 Oct 2024 07:54:04 +0200 Subject: [PATCH 5/5] add editorconfig --- .editorconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5acb96c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 2 +trim_trailing_whitespace = true + +[*.key] +insert_final_newline = false