lightrails 0.1.0.1 → 0.2.4

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +1 -1
  3. data/README.md +63 -11
  4. data/RELEASE_DATE +1 -1
  5. data/VERSION +1 -1
  6. metadata +11 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c2d323b4c3519ff4287bfe1e70b284130a97a3674ff50e53b5ae3394f0b721e5
4
- data.tar.gz: 92c7130f73c22b76b4d1df1260b87f38879ce7255c0a8b8a0021a824d8e8f277
3
+ metadata.gz: 4a10f0d8a2eaa70e659e3be3ec804dd702c7326490e75b0a9d900328da3748da
4
+ data.tar.gz: 5a8137e45c785b8e951e5e6246a55174c01c78b57a83e51d8586300d208c25b6
5
5
  SHA512:
6
- metadata.gz: 8e02d5648ca064786bc029bc139f8216919b0500d984b3f211db1e4c4bdae90a2acf6addb30e2a50dfa99275b9655cb39dfef38cf9a10824801388d2cfdf00c7
7
- data.tar.gz: 3c369315c4f528930b058d64029d7f9b59625c5be9737eaaa220051507e5e5c84771bbcbab800c41d6e3c2be6a039a06ec3151f30d3a8a668168f547757947a5
6
+ metadata.gz: a4af89866cb3d7c7fe2aaefde579e86b58d1ef15a44d205c82d166412cc220ba98f83a52c53aacb558a1d60ac414e7f982db36505814cd332b75c6d5c43c005e
7
+ data.tar.gz: 376127380a11e80046e5bfcc313a6ca3e510ea09fbc805206553d86e2e118bb49c49a587b7e3e7eba93d1ee8e83b824ca400b35edea2e4295e4aa2da802d6923
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2018-2019 Ryo Hashimoto
3
+ Copyright (c) 2018-2020 Ryo Hashimoto
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -24,6 +24,10 @@ $ bin/rails generate lightrails:install
24
24
 
25
25
  Add a simple interface for obtaining multiple data used in a view.
26
26
 
27
+ It uses Facade design pattern and takes responsibility for preparing data outside of the controller.
28
+
29
+ In the example below, by using `MyPage::IndexFacade` and `MyPage::NotificationsFacade`, Active Record methods will be called outside of the `MyPageController`.
30
+
27
31
  ```ruby
28
32
  class Mypage::IndexFacade < ApplicationFacade
29
33
  attr_reader :current_user
@@ -41,6 +45,18 @@ class Mypage::IndexFacade < ApplicationFacade
41
45
  end
42
46
  end
43
47
 
48
+ class MyPage::NotificationsFacade < ApplicationFacade
49
+ attr_reader :current_user
50
+
51
+ def initialize(payload)
52
+ @current_user = payload[:current_user]
53
+ end
54
+
55
+ def messages
56
+ @messages ||= current_user.messages.order(created_at: :desc).limit(10)
57
+ end
58
+ end
59
+
44
60
  class MypageController < ApplicationController
45
61
  # for using #retrieve method
46
62
  include ActionFacade::Retrieval
@@ -50,16 +66,29 @@ class MypageController < ApplicationController
50
66
  # assign instance variables
51
67
  retrieve(facade, :active_users, :messages)
52
68
  end
69
+
70
+ def notifications
71
+ # You can retrieve data from the guessed facade
72
+ # MyPageController#notifications => MyPage::NotificationsFacade
73
+ payload = { current_user: current_user }
74
+ retrieve_from(payload, :messages)
75
+ end
53
76
  end
54
77
  ```
55
78
 
56
79
  ```erb
57
- <%# in View %>
80
+ <%# in View (index.html.erb) %>
58
81
 
59
82
  <% @active_users.each do |user| %>
60
83
  ...
61
84
  <% end %>
62
85
 
86
+ <% @messages.each do |user| %>
87
+ ...
88
+ <% end %>
89
+
90
+ <%# in View (messages.html.erb) %>
91
+
63
92
  <% @messages.each do |user| %>
64
93
  ...
65
94
  <% end %>
@@ -75,6 +104,10 @@ $ bin/rails generate facade mypage/index
75
104
 
76
105
  Add standarized data processing units to your Rails application.
77
106
 
107
+ It uses Command design pattern and will be usable for various business logic (ex: user registration) in Rails applications.
108
+
109
+ In the example, by using `RegistrationInteractor`, user registration process will be executed outside of model and controller.
110
+
78
111
  ```ruby
79
112
  class User
80
113
  attr_accessor :name
@@ -86,16 +119,15 @@ end
86
119
 
87
120
  class RegistrationInteractor < ApplicationInteractor
88
121
  def execute
89
- return fail! unless payload[:name]
122
+ return failure! unless payload[:name]
90
123
  # complicated business logic
91
124
  # set results
92
125
  results.add(:user, User.new(name: payload[:name]))
93
- success!
126
+ successful!
94
127
  end
95
128
  end
96
129
 
97
- interactor = RegistrationInteractor.execute(name: "John")
98
- interactor.success? # => true
130
+ interactor.successful? # => true
99
131
  interactor.finished? # => true
100
132
  user = interactor.results[:user]
101
133
  user.name # => 'John'
@@ -109,9 +141,29 @@ $ bin/rails generate interactor registration
109
141
 
110
142
  ## Active Representer
111
143
 
112
- Add 'represented' models to your Rails application.
113
- It can be used with API responses.
114
- You can wrap hash-like objects (OpenStruct, Hashie::Mash etc.) like below.
144
+ It provides a class for wrapping a object and used like Model.
145
+ You can add custom methods to the class (using the decorator pattern).
146
+ It can be used with API responses or simple decorators.
147
+
148
+ In addition, `attr_field` / `attr_one` / `attr_many` can be used for attributes.
149
+
150
+ ### `attr_field`
151
+
152
+ Declare additional field and type to the objects.
153
+ You can get / set field's value (converted to corresponding).
154
+ It uses `ActiveModel::Attributes` internally.
155
+
156
+ ### `attr_one`
157
+
158
+ Declare an associated object like has one association.
159
+ If a representer for the object is found, the object will be wrapped by the representer.
160
+
161
+ ### `attr_mamy`
162
+
163
+ Declare associated objects like has many association.
164
+ If a representer for the objects is found, the objects will be wrapped by the representer.
165
+
166
+ You can wrap hash-like objects (`OpenStruct`, `Hashie::Mash` etc.) like below.
115
167
 
116
168
  ```ruby
117
169
  class ActivityRepresenter < ApplicationRepresenter
@@ -123,7 +175,7 @@ end
123
175
  class UserRepresenter < ApplicationRepresenter
124
176
  attr_field :first_name, :string
125
177
  attr_field :last_name, :string
126
- attr_collection :activities
178
+ attr_many :activities
127
179
 
128
180
  def full_name
129
181
  "#{first_name} #{last_name}"
@@ -143,7 +195,7 @@ activity.class # => ActivityRepresenter
143
195
  activity.created_on # => returns current date
144
196
  ```
145
197
 
146
- To create a representer, you can use the generator.
198
+ To create a representer, you can use the Rails generator.
147
199
 
148
200
  ```
149
201
  $ bin/rails generate representer user
@@ -152,4 +204,4 @@ $ bin/rails g representer activity
152
204
 
153
205
  ## License
154
206
 
155
- MIT License. Copyright 2018-2019 Ryo Hashimoto.
207
+ MIT License. Copyright 2018-2020 Ryo Hashimoto.
data/RELEASE_DATE CHANGED
@@ -1 +1 @@
1
- 2020-03-02
1
+ 2021-04-11
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0.1
1
+ 0.2.4
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lightrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.1
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Hashimoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-02 00:00:00.000000000 Z
11
+ date: 2021-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '5.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '6.1'
22
+ version: '6.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,49 +29,49 @@ dependencies:
29
29
  version: '5.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '6.1'
32
+ version: '6.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: actionfacade
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - '='
38
38
  - !ruby/object:Gem::Version
39
- version: 0.1.0.1
39
+ version: 0.2.4
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - '='
45
45
  - !ruby/object:Gem::Version
46
- version: 0.1.0.1
46
+ version: 0.2.4
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: actioninteractor
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.1.0.1
53
+ version: 0.2.4
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - '='
59
59
  - !ruby/object:Gem::Version
60
- version: 0.1.0.1
60
+ version: 0.2.4
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: activerepresenter
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - '='
66
66
  - !ruby/object:Gem::Version
67
- version: 0.1.0.1
67
+ version: 0.2.4
68
68
  type: :runtime
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - '='
73
73
  - !ruby/object:Gem::Version
74
- version: 0.1.0.1
74
+ version: 0.2.4
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: bundler
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: 1.8.11
156
156
  requirements: []
157
- rubygems_version: 3.0.3
157
+ rubygems_version: 3.1.4
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Utility library including Action Facade, Action Interactor, Active Representer