You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 908317d
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
3
3
### 2.3.0 (Next)
4
4
5
+
*[#186](https://github.com/slack-ruby/slack-ruby-bot-server/pull/186): Document persisted custom Team attributes for both adapters and Rails concern loading/reloading - [@dblock](https://github.com/dblock), [@Copilot](https://github.com/apps/copilot-swe-agent).
5
6
*[#183](https://github.com/slack-ruby/slack-ruby-bot-server/pull/183): Add a `config.server_pages` block to configure page middleware options centrally without changing the installed library's defaults - [@dblock](https://github.com/dblock), [@Copilot](https://github.com/apps/copilot-swe-agent).
The installation model is the top-level `::Team` class for both adapters, not `SlackRubyBotServer::Models::Team`. Load `slack-ruby-bot-server` before extending it. The model already includes its database adapter and timestamps; do not include them again or declare a different superclass.
118
+
119
+
##### Mongoid Attributes
120
+
121
+
Add fields by reopening the existing class in an application file, for example `lib/team_extensions.rb`:
122
+
123
+
```ruby
124
+
require'slack-ruby-bot-server'
125
+
126
+
classTeam
127
+
field :subscription_plan, type:String, default:'free'
128
+
129
+
defpaid_plan?
130
+
subscription_plan =='paid'
131
+
end
132
+
end
133
+
```
134
+
135
+
Require that file from your startup code after loading the framework and before serving requests or starting the service. Mongoid does not require a schema migration for the new field.
136
+
137
+
##### Active Record Attributes
138
+
139
+
Add a column to the existing `teams` table with an application migration. Use your application's migration version; this example is also compatible with older supported Active Record versions:
Run the migration before code uses the attribute. Active Record provides its reader and writer from the column; do not use `attr_accessor`, which would bypass persistence. Add methods by reopening `class Team` after loading the framework, as above, but omit the Mongoid-only `field` declaration.
150
+
151
+
##### Rails Loading and Reloading
152
+
153
+
Putting another `app/models/team.rb` in a Rails app is not a reliable way to extend a class already loaded by a gem. Put reloadable behavior in a concern instead:
154
+
155
+
```ruby
156
+
# app/models/concerns/team_extensions.rb
157
+
moduleTeamExtensions
158
+
extendActiveSupport::Concern
159
+
160
+
defpaid_plan?
161
+
subscription_plan =='paid'
162
+
end
163
+
end
164
+
```
165
+
166
+
Include it in `::Team` from a reloader callback, rather than autoloading the concern directly during initializer execution:
With Active Record, use the migration above instead of declaring a field in the initializer. The callback runs at boot and after development reloads; including the same concern more than once is safe. Keep one-time field declarations outside the callback. Do not query the database or swallow database errors just to attach methods: the extension can be loaded before the `teams` table exists.
182
+
183
+
The framework currently owns the global `Team` constant. An unrelated application model with the same name is a separate [name-collision limitation](https://github.com/slack-ruby/slack-ruby-bot-server/pull/83), not an extension mechanism.
184
+
111
185
### OAuth Version and Scopes
112
186
113
187
Configure your app's [OAuth version](https://api.slack.com/authentication/oauth-v2) and [scopes](https://api.slack.com/legacy/oauth-scopes) as needed by your application.
0 commit comments