prop_initializer 0.1.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 29c51456a07fe5ba7a95870bb2cb7e1a1b586b845c0a74878d3b273bee8dbaae
4
- data.tar.gz: a670f466ba0374a53a2f642de194317713a92ea1b081e777f509f354d56a5a67
3
+ metadata.gz: 682108ddd70bd9c7712bd7b98f8513298df74fe581a7a0eaf4a91f759f9de454
4
+ data.tar.gz: ac9e3004d3839dc9d3ec288a6de3e351b5b91e25cda394c024da8f1be4ba446a
5
5
  SHA512:
6
- metadata.gz: d99b4d83625d31aa5c900fc54f3f9251cc7ec389ee11d16bc9d770e736816fc1f549876727500f1a68a53a1e12346ca6637db592457dbd8857ea126f9a45da77
7
- data.tar.gz: f68cf05fcc1701e3ca85088b9e41f88622eaf071b20f93d949027899e768aeba05151a364d5e9455472c5e1410c2e93d2429c7060792f5147f424d2b3b213357
6
+ metadata.gz: 7d6ee37c5de04e5a6d6f8b7f24f081ed4da85d0aa0dca4879060c3bf9eb17d5b595a59cddb1dbf0497a1ecb99bce51c0bc59861259490bd0c43c2c45a49352c4
7
+ data.tar.gz: 54bd0d336769d14a2876914e0feb9d362ed4fa14e1202264b769aebaaf10ccb98f86176ff7c59127f81dd8015dcf7d21e1ec9198afcb741bddb13f51f7de01d6
data/README.md CHANGED
@@ -1,28 +1,137 @@
1
- # PropInitializer
2
- Short description and motivation.
1
+ <a href="https://badge.fury.io/rb/prop_initializer"><img src="https://badge.fury.io/rb/prop_initializer.svg" alt="Gem Version" height="18"></a>
3
2
 
4
- ## Usage
5
- How to use my plugin.
3
+ # Prop Initializer
4
+
5
+ ## Overview
6
+
7
+ The `prop_initializer` gem is a flexible tool for defining properties on Ruby classes.
8
+
9
+ ![](./logo.png)
10
+
11
+ 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.
12
+
13
+ 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.
6
14
 
7
15
  ## Installation
8
- Add this line to your application's Gemfile:
16
+
17
+ To use `prop_initializer ` in your Ruby project, add the following to your Gemfile:
9
18
 
10
19
  ```ruby
11
20
  gem "prop_initializer"
12
21
  ```
13
22
 
14
- And then execute:
23
+ Then, run the bundle command to install it:
24
+
15
25
  ```bash
16
- $ bundle
26
+ bundle install
17
27
  ```
18
28
 
19
- Or install it yourself as:
20
- ```bash
21
- $ gem install prop_initializer
29
+ ## Usage
30
+
31
+ To start using `prop_initializer `, you need to include the module in the class where you want to define properties.
32
+
33
+ ### Step 1: Extend the Properties Module
34
+
35
+ In any class, extend `PropInitializer::Properties` to enable the ability to define properties:
36
+
37
+ ```ruby
38
+ class MyClass
39
+ extend PropInitializer::Properties
40
+ end
22
41
  ```
23
42
 
24
- ## Contributing
25
- Contribution directions go here.
43
+ ### Step 2: Define Properties
44
+
45
+ Properties can be declared using the `prop` method, which generates writers and makes them available as instance variables (e.g., `@name`, `@size`, etc.).
46
+
47
+ #### Basic Syntax:
48
+
49
+ ```ruby
50
+ prop :name # A simple property, accessible via @name
51
+ prop :size, default: :md # A property with a default value of :md
52
+ prop :args, kind: :* # A property for handling splat arguments
53
+ prop :kwargs, kind: :** # A property for handling keyword arguments
54
+ ```
55
+
56
+ #### Custom Property with Block:
57
+
58
+ You can define a custom processing block when declaring a property, for example:
59
+
60
+ ```ruby
61
+ prop :icon do |value|
62
+ value&.to_sym # Converts the property value to a symbol
63
+ end
64
+ ```
65
+
66
+ ### Step 3: Accessing Properties
67
+
68
+ By default, `PropInitializer` generates a writer for each declared property. The properties are stored as instance variables, which can be accessed within the class:
69
+
70
+ ```ruby
71
+ @name # Accesses the value of the 'name' property
72
+ @size # Accesses the value of the 'size' property
73
+ ```
74
+
75
+ #### Public Reader:
76
+
77
+ If you want to generate a public reader (getter) for a property, use the `reader: :public` option when defining the property:
78
+
79
+ ```ruby
80
+ prop :title, reader: :public
81
+ ```
82
+
83
+ This will automatically generate a public getter method, allowing you to retrieve the property like so:
84
+
85
+ ```ruby
86
+ my_class_instance.title # Public getter for the 'title' property
87
+ ```
88
+
89
+ ### Example:
90
+
91
+ ```ruby
92
+ class MyComponent
93
+ extend PropInitializer::Properties
94
+
95
+ prop :name, reader: :public
96
+ prop :size, default: :md, reader: :public
97
+ prop :args, kind: :*
98
+ prop :kwargs, kind: :**
99
+ prop :icon do |value|
100
+ value&.to_sym
101
+ end
102
+ end
103
+
104
+ component = MyComponent.new(name: "Button", size: :lg)
105
+ component.name # => "Button"
106
+ component.size # => :lg
107
+ ```
108
+
109
+ ## Key Differences from [Literal](https://github.com/joeldrapper/literal)
110
+
111
+ While `prop_initializer` is based on the [Literal Gem](https://github.com/joeldrapper/literal), there are some important differences:
112
+
113
+ - **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.
114
+
115
+ - **Simplified Initializer:** The initialization process has been modified to avoid requiring types at the time of property definition.
116
+
117
+ ## Acknowledgements
118
+
119
+ 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.
120
+
121
+ 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).
122
+
123
+ Thank you for using `prop_initializer`! We hope this tool helps make your property management more efficient and adaptable in your Ruby projects.
124
+
125
+ ## Open Source
126
+
127
+ - [`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
128
+ - [`avo`](https://github.com/avo-hq/avo) - Build Content management systems with Ruby on Rails
129
+ - [`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.
130
+ - [`stimulus-confetti`](https://github.com/avo-hq/stimulus-confetti) - The easiest way to add confetti to your StimulusJS app
131
+
132
+ ## Try Avo ⭐️
133
+
134
+ 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.
26
135
 
27
136
  ## License
28
137
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -44,7 +44,7 @@ module PropInitializer::Properties
44
44
  def prop_initializer_properties
45
45
  return @prop_initializer_properties if defined?(@prop_initializer_properties)
46
46
 
47
- if superclass.is_a?(PropInitializer)
47
+ if superclass.is_a?(PropInitializer::Properties)
48
48
  @prop_initializer_properties = superclass.prop_initializer_properties.dup
49
49
  else
50
50
  @prop_initializer_properties = PropInitializer::Properties::Schema.new
@@ -1,3 +1,5 @@
1
+ require "rails/railtie"
2
+
1
3
  module PropInitializer
2
4
  class Railtie < ::Rails::Railtie
3
5
  end
@@ -1,3 +1,3 @@
1
1
  module PropInitializer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prop_initializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Bob
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: zeitwerk
@@ -49,7 +48,6 @@ licenses:
49
48
  - MIT
50
49
  metadata:
51
50
  homepage_uri: https://github.com/avo-hq/prop_initializer
52
- post_install_message:
53
51
  rdoc_options: []
54
52
  require_paths:
55
53
  - lib
@@ -64,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
62
  - !ruby/object:Gem::Version
65
63
  version: '0'
66
64
  requirements: []
67
- rubygems_version: 3.5.5
68
- signing_key:
65
+ rubygems_version: 3.6.9
69
66
  specification_version: 4
70
67
  summary: A flexible property initializer for Ruby classes inspired by the Literal
71
68
  gem.