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