Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update readme #1

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
90 changes: 90 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
129 changes: 117 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,133 @@
# PropInitializer
Short description and motivation.
# `prop_initializer`

## Usage
How to use my plugin.
## Overview

The `prop_initializer` gem is a flexible tool for defining properties on Ruby classes.

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
Add this line to your application's Gemfile:

To use `prop_initializer ` 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 `prop_initializer `, 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
```

### 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
```

## Contributing
Contribution directions go here.
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 `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, 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.

## 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).
Loading