mainapp 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7d4ade99eef2b4f21fb37866fa721ed31e9d83d77e35a43f7ef0d5ff130373d
4
- data.tar.gz: 82e3cf7736253777e35aa454dfe4aebbf70c4c3ba51f127cd987cf9cbca77bf7
3
+ metadata.gz: 5803520b0069145d56aa91989ec4813168317aea43e5b528e31854e4736559c6
4
+ data.tar.gz: 5e27b4f2d5a5d3ce924d8428c0c4d29b67167eb79cbde42aa66b7123090393c5
5
5
  SHA512:
6
- metadata.gz: 8909c01b5a818f9fddab1976dce8da2a3eb1b2df9929db1c02274703dc2761dba62012f31be386cce16025fa52bc7ff0dfda73b4ae4fb7ea213eb58c300a29e7
7
- data.tar.gz: 3dde28c0b02188c044d3a7d4f33f080d219e84a40a4366220b00b5f7d78f7beb6f656546068ac6b0a9e73604ab00b08d76fe0696f928d71b3889a55715cf1e1f
6
+ metadata.gz: 13875ebf27df4a38737bea6dcbbf1e67abe3b9026cde923582f843747fcd0366cbf5d01bc22ff65290d38d48f452c9488f476fce829152594d4342ddaafd878b
7
+ data.tar.gz: 6dd68bfd702f0abf0a4f72d4572478447256928aabc250b14c2111f8b4add58db75d9d8af2383a78d29391444f29c18c6ac02168dd858b0079dc8d80a49a1c37
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # development
2
2
 
3
+ # 1.1.1 (2022.11.17)
4
+
5
+ * add components module
6
+
3
7
  # 1.0.3 (2022.06.24)
4
8
 
5
9
  * update makefile
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/mainapp.svg)](http://badge.fury.io/rb/mainapp)
4
4
 
5
- `.set` method extracted from the Sinatra::Base
5
+ `.set` method extracted from the Sinatra::Base, and helper for the components
6
+ convention
6
7
 
7
8
  ## Installation
8
9
 
@@ -20,6 +21,8 @@ Or install it yourself as:
20
21
 
21
22
  ## Usage
22
23
 
24
+ ### Creating structure with components
25
+
23
26
  ```ruby
24
27
  class My
25
28
  extend ::Mainapp::Base
@@ -27,7 +30,23 @@ end
27
30
 
28
31
  My.set foo: 1
29
32
 
30
- My.foo => 1
33
+ My.foo #=> 1
34
+ ```
35
+
36
+ ### Working with components
37
+
38
+ ```ruby
39
+ class TestComponent
40
+ include ::Mainapp::Component
41
+ attr_struct :foo, :bar
42
+
43
+ def some_method
44
+ pp foo
45
+ end
46
+ end
47
+
48
+ components = {foo: 1, bar: 2, baz: 3}
49
+ handler = TestComponent.new components
31
50
  ```
32
51
 
33
52
  ## Versioning
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "ostruct"
4
+
5
+ module Mainapp
6
+ module Component
7
+ def self.included(base)
8
+ base.extend ClassMethods
9
+ base.prepend PrepMethods
10
+ end
11
+
12
+ module PrepMethods
13
+ def initialize(config = {})
14
+ @config = OpenStruct.new(config.to_h).to_h
15
+ super if initialize_in_ancestor?
16
+ end
17
+
18
+ protected
19
+
20
+ def initialize_in_ancestor?
21
+ self.class.ancestors[1].private_instance_methods(false).include?(:initialize)
22
+ end
23
+ end
24
+
25
+ module ClassMethods
26
+ def attr_struct(*components)
27
+ components.each do |name|
28
+ next if method_defined?(name)
29
+ define_method name do
30
+ @config[name.to_sym]
31
+ end
32
+ private name
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mainapp
4
- VERSION = "1.0.3"
4
+ VERSION = "1.1.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mainapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Szymon Kopciewski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-24 00:00:00.000000000 Z
11
+ date: 2022-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -106,6 +106,7 @@ files:
106
106
  - LICENSE
107
107
  - README.md
108
108
  - lib/mainapp/base.rb
109
+ - lib/mainapp/component.rb
109
110
  - lib/mainapp/version.rb
110
111
  homepage: https://github.com/skopciewski/mainapp
111
112
  licenses: