mainapp 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +21 -2
- data/lib/mainapp/component.rb +37 -0
- data/lib/mainapp/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5803520b0069145d56aa91989ec4813168317aea43e5b528e31854e4736559c6
|
4
|
+
data.tar.gz: 5e27b4f2d5a5d3ce924d8428c0c4d29b67167eb79cbde42aa66b7123090393c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13875ebf27df4a38737bea6dcbbf1e67abe3b9026cde923582f843747fcd0366cbf5d01bc22ff65290d38d48f452c9488f476fce829152594d4342ddaafd878b
|
7
|
+
data.tar.gz: 6dd68bfd702f0abf0a4f72d4572478447256928aabc250b14c2111f8b4add58db75d9d8af2383a78d29391444f29c18c6ac02168dd858b0079dc8d80a49a1c37
|
data/CHANGELOG.md
CHANGED
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
|
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
|
data/lib/mainapp/version.rb
CHANGED
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
|
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-
|
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:
|