cal-invite 0.1.2 → 0.1.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.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.rdoc_options +85 -0
- data/CACHING.md +148 -0
- data/CHANGELOG.md +16 -0
- data/README.md +154 -17
- data/Rakefile +26 -0
- data/lib/.DS_Store +0 -0
- data/lib/cal_invite/.DS_Store +0 -0
- data/lib/cal_invite/caching.rb +74 -0
- data/lib/cal_invite/configuration.rb +67 -3
- data/lib/cal_invite/event.rb +144 -53
- data/lib/cal_invite/providers/base_provider.rb +73 -56
- data/lib/cal_invite/providers/google.rb +60 -4
- data/lib/cal_invite/providers/ical.rb +107 -16
- data/lib/cal_invite/providers/ics.rb +107 -18
- data/lib/cal_invite/providers/ics_content.rb +184 -0
- data/lib/cal_invite/providers/office365.rb +64 -10
- data/lib/cal_invite/providers/outlook.rb +70 -6
- data/lib/cal_invite/providers/yahoo.rb +64 -4
- data/lib/cal_invite/providers.rb +9 -2
- data/lib/cal_invite/version.rb +1 -1
- data/lib/cal_invite.rb +39 -0
- data/lib/tasks/rdoc.rake +13 -0
- metadata +54 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3f79844d8b3618ca4539da1033070e310d84d8d6a004d921ce28b7230fda371
|
4
|
+
data.tar.gz: c7f43118837065df3744b139fc5e0abcbedbb4e9a6490f660c0d79b0bff85d6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 884ac33c88abc0b496496ba495e6bc4381c617df1c327cfd52e8995121f3a607c576724f3c7095b8186a3ffc10c5020ddd7643c4d79ad7746e7419b4da4277f0
|
7
|
+
data.tar.gz: b026672548b98ad349ab094a5def2d1f3c7b7904592ed1528caec8978c9d6c0c4f584e68706d307d31fdcfe769ca119d71df516f535bbc5ccc50a03768fefeac
|
data/.DS_Store
ADDED
Binary file
|
data/.rdoc_options
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
---
|
2
|
+
encoding: UTF-8
|
3
|
+
static_path: ["./doc/images"]
|
4
|
+
charset: UTF-8
|
5
|
+
exclude: ["vendor/*", "tmp/*", ".*/*"]
|
6
|
+
hyperlink_all: true
|
7
|
+
line_numbers: true
|
8
|
+
locale: en
|
9
|
+
main: README.md
|
10
|
+
markup: markdown
|
11
|
+
output_decoration: true
|
12
|
+
show_hash: false
|
13
|
+
tab_width: 2
|
14
|
+
template_stylesheets: []
|
15
|
+
title: "CalInvite - Calendar Invite Generator by DashAPI"
|
16
|
+
visibility: :public
|
17
|
+
webcvs: https://github.com/the-pew-inc/cal-invite
|
18
|
+
|
19
|
+
# Custom sections for better organization
|
20
|
+
sections:
|
21
|
+
- title: Calendar Providers
|
22
|
+
dir: lib/cal_invite/providers
|
23
|
+
include: ["**/*.rb"]
|
24
|
+
- title: Core
|
25
|
+
dir: lib/cal_invite
|
26
|
+
include: ["*.rb"]
|
27
|
+
|
28
|
+
extra_docs:
|
29
|
+
- README.md
|
30
|
+
- CHANGELOG.md
|
31
|
+
- LICENSE.txt
|
32
|
+
|
33
|
+
# Options for better documentation organization
|
34
|
+
options:
|
35
|
+
all:
|
36
|
+
- "--title=CalInvite - Calendar Invite Generator by DashAPI"
|
37
|
+
- "--line-numbers"
|
38
|
+
- "--diagram" # Include diagrams if you have any
|
39
|
+
- "--main=README.md"
|
40
|
+
SystemExtension:
|
41
|
+
- "--title=CalInvite System Extensions"
|
42
|
+
|
43
|
+
# Documentation sections
|
44
|
+
doc_sections:
|
45
|
+
- "Calendar Provider Implementation"
|
46
|
+
- "Configuration"
|
47
|
+
- "Event Management"
|
48
|
+
- "Utility Functions"
|
49
|
+
|
50
|
+
# Additional documentation metadata
|
51
|
+
metadata:
|
52
|
+
copyright: "© 2024 ThePew Inc. All rights reserved."
|
53
|
+
authors:
|
54
|
+
- "Stephane Paquet"
|
55
|
+
website: "https://github.com/the-pew-inc/cal-invite"
|
56
|
+
license: "MIT"
|
57
|
+
|
58
|
+
# Documentation themes and styles
|
59
|
+
template:
|
60
|
+
css: [] # You can add custom CSS files if needed
|
61
|
+
javascript: [] # You can add custom JS files if needed
|
62
|
+
|
63
|
+
# Search engine optimization
|
64
|
+
search_index:
|
65
|
+
include:
|
66
|
+
- "**/*.rb"
|
67
|
+
exclude:
|
68
|
+
- "test/**/*"
|
69
|
+
- "spec/**/*"
|
70
|
+
- "vendor/**/*"
|
71
|
+
|
72
|
+
# Documentation organization
|
73
|
+
groups:
|
74
|
+
Core:
|
75
|
+
- CalInvite
|
76
|
+
- CalInvite::Configuration
|
77
|
+
- CalInvite::Event
|
78
|
+
Providers:
|
79
|
+
- CalInvite::Providers::BaseProvider
|
80
|
+
- CalInvite::Providers::Google
|
81
|
+
- CalInvite::Providers::Outlook
|
82
|
+
- CalInvite::Providers::Office365
|
83
|
+
- CalInvite::Providers::Yahoo
|
84
|
+
- CalInvite::Providers::Ics
|
85
|
+
- CalInvite::Providers::Ical
|
data/CACHING.md
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
## Caching
|
2
|
+
|
3
|
+
CalInvite supports flexible caching options when used within a Rails application. You can configure the cache store to use any of Rails' supported cache stores including memory store, Redis, or a custom cache store implementation.
|
4
|
+
|
5
|
+
### Basic Configuration
|
6
|
+
|
7
|
+
Configure caching in your Rails application's initializer:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# config/initializers/cal_invite.rb
|
11
|
+
CalInvite.configure do |config|
|
12
|
+
# Use Rails.cache by default
|
13
|
+
config.cache_store = Rails.cache
|
14
|
+
|
15
|
+
# Optional: Set a custom prefix for cache keys
|
16
|
+
config.cache_prefix = 'my_app_cal_invite'
|
17
|
+
|
18
|
+
# Optional: Set cache expiration (in seconds)
|
19
|
+
config.cache_expires_in = 3600 # 1 hour
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
### Available Cache Stores
|
24
|
+
|
25
|
+
CalInvite supports the following cache stores:
|
26
|
+
|
27
|
+
1. Memory Store (default)
|
28
|
+
```ruby
|
29
|
+
config.cache_store = :memory_store
|
30
|
+
```
|
31
|
+
|
32
|
+
2. Null Store (for disabling caching)
|
33
|
+
```ruby
|
34
|
+
config.cache_store = :null_store
|
35
|
+
```
|
36
|
+
|
37
|
+
3. Custom Cache Store
|
38
|
+
```ruby
|
39
|
+
# Any object that implements read/write/delete methods
|
40
|
+
config.cache_store = MyCacheStore.new
|
41
|
+
```
|
42
|
+
|
43
|
+
4. Rails Cache
|
44
|
+
```ruby
|
45
|
+
# Use your Rails application's configured cache
|
46
|
+
config.cache_store = Rails.cache
|
47
|
+
```
|
48
|
+
|
49
|
+
### Cache Configuration Options
|
50
|
+
|
51
|
+
- `cache_store`: The storage mechanism for cached data
|
52
|
+
- `cache_prefix`: Prefix for all cache keys (default: 'cal_invite')
|
53
|
+
- `cache_expires_in`: Default cache expiration time in seconds
|
54
|
+
- `timezone`: Default timezone for cache keys (default: 'UTC')
|
55
|
+
|
56
|
+
### Custom Cache Adapters
|
57
|
+
|
58
|
+
You can implement custom cache adapters by creating a class that responds to the following methods:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
class CustomCacheStore
|
62
|
+
def read(key)
|
63
|
+
# Implementation for retrieving cached value
|
64
|
+
end
|
65
|
+
|
66
|
+
def write(key, value, options = {})
|
67
|
+
# Implementation for storing value in cache
|
68
|
+
# options may include :expires_in
|
69
|
+
end
|
70
|
+
|
71
|
+
def delete(key)
|
72
|
+
# Implementation for removing cached value
|
73
|
+
end
|
74
|
+
|
75
|
+
def clear
|
76
|
+
# Implementation for clearing all cached values
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# Configure CalInvite to use your custom cache store
|
81
|
+
CalInvite.configure do |config|
|
82
|
+
config.cache_store = CustomCacheStore.new
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
### Automatic Cache Invalidation
|
87
|
+
|
88
|
+
The cache is automatically invalidated in the following scenarios:
|
89
|
+
|
90
|
+
1. When event attributes are updated via `update_attributes`
|
91
|
+
2. When a new calendar URL is generated
|
92
|
+
3. When the configuration changes
|
93
|
+
|
94
|
+
### Best Practices
|
95
|
+
|
96
|
+
1. **Cache Store Selection**: Choose an appropriate cache store based on your needs:
|
97
|
+
- Use `:memory_store` for development and small applications
|
98
|
+
- Use Rails.cache for production applications
|
99
|
+
- Implement a custom cache store for specific requirements
|
100
|
+
|
101
|
+
2. **Cache Key Management**:
|
102
|
+
- The gem automatically generates unique cache keys based on event attributes
|
103
|
+
- Keys include a prefix for namespace isolation
|
104
|
+
- Consider your timezone settings when debugging cache issues
|
105
|
+
|
106
|
+
3. **Expiration Strategy**:
|
107
|
+
- Set appropriate expiration times based on your use case
|
108
|
+
- Consider using shorter expiration times for frequently changing data
|
109
|
+
- Use `nil` expiration for permanent caching (until manual invalidation)
|
110
|
+
|
111
|
+
### Example Rails Integration
|
112
|
+
|
113
|
+
Here's a complete example of setting up caching in a Rails application:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
# config/initializers/cal_invite.rb
|
117
|
+
CalInvite.configure do |config|
|
118
|
+
if Rails.env.production?
|
119
|
+
# Use Rails cache in production
|
120
|
+
config.cache_store = Rails.cache
|
121
|
+
config.cache_expires_in = 1.hour
|
122
|
+
else
|
123
|
+
# Use memory store in development
|
124
|
+
config.cache_store = :memory_store
|
125
|
+
config.cache_expires_in = 5.minutes
|
126
|
+
end
|
127
|
+
|
128
|
+
config.cache_prefix = "cal_invite:#{Rails.env}"
|
129
|
+
config.timezone = 'UTC'
|
130
|
+
end
|
131
|
+
```
|
132
|
+
|
133
|
+
### Testing with Caching
|
134
|
+
|
135
|
+
When writing tests that involve caching:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
# In your test setup
|
139
|
+
CalInvite.configure do |config|
|
140
|
+
config.cache_store = :memory_store
|
141
|
+
config.cache_expires_in = 3600 # 1 hour in seconds
|
142
|
+
end
|
143
|
+
|
144
|
+
# Clear cache between tests
|
145
|
+
def setup
|
146
|
+
CalInvite.configuration.cache_store.clear
|
147
|
+
end
|
148
|
+
```
|
data/CHANGELOG.md
CHANGED
@@ -2,8 +2,22 @@
|
|
2
2
|
|
3
3
|
## [Released]
|
4
4
|
|
5
|
+
## [v0.1.3] - 2024-12-19
|
6
|
+
|
7
|
+
- Add support to RDoc
|
8
|
+
|
9
|
+
## [v0.1.3] - 2024-12-19
|
10
|
+
|
11
|
+
- Apple iCal and ics file can now be either generated or wrap to be downloaded
|
12
|
+
- Add Caching management support
|
13
|
+
- Add CACHING.md for more details about how to use caching in a Rails app
|
14
|
+
- Updating the README file to reflect latest usage changes
|
15
|
+
- Minor bug fixes and improvments.
|
16
|
+
|
5
17
|
## [v0.1.2] - 2024-12-17
|
6
18
|
|
19
|
+
⚠️ This version should not be used
|
20
|
+
|
7
21
|
- Add support to Microsoft office 365 calendar invite URL
|
8
22
|
- Update the README
|
9
23
|
- Add an example
|
@@ -11,6 +25,8 @@
|
|
11
25
|
|
12
26
|
## [v0.1.1] - 2024-12-17
|
13
27
|
|
28
|
+
⚠️ This version should not be used
|
29
|
+
|
14
30
|
Fixing a bug in the gemspec file
|
15
31
|
|
16
32
|
## [Unreleased]
|
data/README.md
CHANGED
@@ -4,7 +4,6 @@ A Ruby gem for generating calendar invitations across multiple calendar platform
|
|
4
4
|
|
5
5
|
[](https://badge.fury.io/rb/cal-invite)
|
6
6
|

|
7
|
-
|
8
7
|
[]
|
9
8
|
|
10
9
|
## Compatibility
|
@@ -15,7 +14,7 @@ A Ruby gem for generating calendar invitations across multiple calendar platform
|
|
15
14
|
## Supported Calendar Platforms
|
16
15
|
|
17
16
|
Direct Integration:
|
18
|
-
- Apple iCal
|
17
|
+
- Apple iCal (with proper timezone support)
|
19
18
|
- Microsoft Outlook
|
20
19
|
- Microsoft Outlook 365
|
21
20
|
- Google Calendar
|
@@ -52,21 +51,47 @@ $ gem install cal-invite
|
|
52
51
|
|
53
52
|
### Basic Event Creation
|
54
53
|
|
54
|
+
Important notes:
|
55
|
+
- Always provide times in UTC
|
56
|
+
- Use the timezone parameter to specify the display timezone
|
57
|
+
- Location and URL are handled separately for better calendar integration
|
58
|
+
|
55
59
|
```ruby
|
56
|
-
#
|
60
|
+
# Create an event with physical location
|
57
61
|
event = CalInvite::Event.new(
|
58
62
|
title: "Team Meeting",
|
59
|
-
start_time: Time.current,
|
60
|
-
end_time: Time.current + 2.hours,
|
63
|
+
start_time: Time.current.utc, # Always use UTC times
|
64
|
+
end_time: Time.current.utc + 2.hours,
|
61
65
|
description: "Weekly team sync",
|
62
|
-
location: "Conference Room A",
|
63
|
-
|
66
|
+
location: "Conference Room A", # Physical location
|
67
|
+
timezone: "America/New_York", # Display timezone
|
64
68
|
attendees: ["person@example.com"],
|
65
69
|
show_attendees: true,
|
66
|
-
timezone: "America/New_York",
|
67
70
|
notes: "Please bring your laptop"
|
68
71
|
)
|
69
72
|
|
73
|
+
# Create an event with both physical and virtual locations
|
74
|
+
event = CalInvite::Event.new(
|
75
|
+
title: "Hybrid Meeting",
|
76
|
+
start_time: Time.current.utc,
|
77
|
+
end_time: Time.current.utc + 2.hours,
|
78
|
+
description: "Weekly team sync",
|
79
|
+
location: "Conference Room A", # Physical location
|
80
|
+
url: "https://zoom.us/j/123456789", # Virtual meeting URL
|
81
|
+
timezone: "America/New_York",
|
82
|
+
attendees: ["person@example.com"],
|
83
|
+
show_attendees: true
|
84
|
+
)
|
85
|
+
|
86
|
+
# All-day event
|
87
|
+
event = CalInvite::Event.new(
|
88
|
+
title: "Company All-Day Event",
|
89
|
+
start_time: Date.today.beginning_of_day.utc,
|
90
|
+
end_time: Date.today.end_of_day.utc,
|
91
|
+
all_day: true,
|
92
|
+
timezone: "America/New_York"
|
93
|
+
)
|
94
|
+
|
70
95
|
# Multi-day event
|
71
96
|
event = CalInvite::Event.new(
|
72
97
|
title: "Training Workshop",
|
@@ -82,19 +107,125 @@ event = CalInvite::Event.new(
|
|
82
107
|
],
|
83
108
|
description: "Advanced Ruby Training",
|
84
109
|
location: "Training Center",
|
85
|
-
url: "https://zoom.us/j/123456789",
|
110
|
+
url: "https://zoom.us/j/123456789", # Virtual meeting URL kept separate
|
86
111
|
timezone: "America/New_York",
|
87
112
|
notes: "Bring your own laptop"
|
88
113
|
)
|
89
114
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
115
|
+
# Generate calendar URLs
|
116
|
+
ical_url = event.generate_calendar_url(:ical)
|
117
|
+
google_url = event.generate_calendar_url(:google)
|
118
|
+
outlook_url = event.generate_calendar_url(:outlook)
|
119
|
+
outlook365_url = event.generate_calendar_url(:office365)
|
120
|
+
yahoo_url = event.generate_calendar_url(:yahoo)
|
121
|
+
```
|
122
|
+
|
123
|
+
### Implementing ICS Downloads
|
124
|
+
|
125
|
+
To enable ICS file downloads in your application, you'll need to:
|
126
|
+
|
127
|
+
1. Create an endpoint that will handle the download request
|
128
|
+
2. Generate the ICS content
|
129
|
+
3. Send the file to the user
|
130
|
+
|
131
|
+
Here's a basic example of the controller logic:
|
132
|
+
|
133
|
+
```ruby
|
134
|
+
# In your controller action
|
135
|
+
def download_calendar
|
136
|
+
event = # ... your event creation logic ...
|
137
|
+
|
138
|
+
content = CalInvite::Providers::Ics.new(event).generate
|
139
|
+
filename = "#{event.title.downcase.gsub(/[^0-9A-Za-z.\-]/, '_')}_#{Time.now.strftime('%Y%m%d')}.ics"
|
140
|
+
|
141
|
+
send_data(
|
142
|
+
content,
|
143
|
+
filename: filename,
|
144
|
+
type: 'text/calendar; charset=UTF-8',
|
145
|
+
disposition: 'attachment'
|
146
|
+
)
|
147
|
+
end
|
148
|
+
```
|
149
|
+
|
150
|
+
You can implement this in any controller and route that makes sense for your application's architecture.
|
151
|
+
|
152
|
+
### ICS File Generation
|
153
|
+
|
154
|
+
The gem provides two ways to generate ICS files:
|
155
|
+
|
156
|
+
1. Direct content generation:
|
157
|
+
```ruby
|
158
|
+
event = CalInvite::Event.new(
|
159
|
+
title: "Meeting",
|
160
|
+
start_time: Time.current.utc,
|
161
|
+
end_time: Time.current.utc + 1.hour,
|
162
|
+
timezone: "America/New_York"
|
163
|
+
)
|
164
|
+
|
165
|
+
# Generate ICS content
|
166
|
+
content = CalInvite::Providers::Ics.new(event).generate
|
167
|
+
```
|
168
|
+
|
169
|
+
2. Rails controller integration:
|
170
|
+
```ruby
|
171
|
+
# In your controller
|
172
|
+
def download_ics
|
173
|
+
event = CalInvite::Event.new(
|
174
|
+
title: "Meeting",
|
175
|
+
start_time: Time.current.utc,
|
176
|
+
end_time: Time.current.utc + 1.hour,
|
177
|
+
timezone: "America/New_York"
|
178
|
+
)
|
179
|
+
|
180
|
+
content = CalInvite::Providers::Ics.new(event).generate
|
181
|
+
filename = "#{event.title.downcase.gsub(/[^0-9A-Za-z.\-]/, '_')}_#{Time.now.strftime('%Y%m%d')}.ics"
|
182
|
+
|
183
|
+
send_data(
|
184
|
+
content,
|
185
|
+
filename: filename,
|
186
|
+
type: 'text/calendar; charset=UTF-8',
|
187
|
+
disposition: 'attachment'
|
188
|
+
)
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
### Important Notes
|
193
|
+
|
194
|
+
1. Time Handling:
|
195
|
+
- Always provide times in UTC to the Event constructor
|
196
|
+
- Use the timezone parameter to specify the display timezone
|
197
|
+
- All-day events should use beginning_of_day.utc and end_of_day.utc
|
198
|
+
|
199
|
+
2. Location and URL:
|
200
|
+
- Physical location goes in the `location` parameter
|
201
|
+
- Virtual meeting URL goes in the `url` parameter
|
202
|
+
- They are handled separately for better calendar integration
|
203
|
+
|
204
|
+
3. ICS Files:
|
205
|
+
- Both Apple iCal and standard ICS files now properly handle timezones
|
206
|
+
- Attendees are properly formatted with RSVP options
|
207
|
+
- Virtual meeting URLs are properly separated from physical locations
|
208
|
+
|
209
|
+
## Caching Support
|
210
|
+
|
211
|
+
CalInvite includes built-in caching support to improve performance when generating calendar URLs. To enable caching in your Rails application:
|
212
|
+
|
213
|
+
```ruby
|
214
|
+
# config/initializers/cal_invite.rb
|
215
|
+
CalInvite.configure do |config|
|
216
|
+
# Use Rails cache by default
|
217
|
+
config.cache_store = Rails.cache
|
218
|
+
|
219
|
+
# Optional: Set cache prefix
|
220
|
+
config.cache_prefix = 'my_app_cal_invite'
|
221
|
+
|
222
|
+
# Optional: Set expiration time (in seconds)
|
223
|
+
config.cache_expires_in = 3600 # 1 hour
|
224
|
+
end
|
96
225
|
```
|
97
226
|
|
227
|
+
For detailed information about configuring caching in Rails applications and available options, see our [Caching Guide](https://github.com/the-pew-inc/cal-invite/blob/master/CACHING.md)
|
228
|
+
|
98
229
|
## Development
|
99
230
|
|
100
231
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -105,16 +236,22 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
105
236
|
|
106
237
|
Add test(s) as necessary.
|
107
238
|
|
108
|
-
Run all the tests before
|
239
|
+
Run all the tests before submitting: `bundle exec rake test`
|
109
240
|
|
110
241
|
## Contributing
|
111
242
|
|
112
243
|
Bug reports and pull requests are welcome on GitHub at https://github.com/the-pew-inc/cal-invite. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/the-pew-inc/cal-invite/blob/master/CODE_OF_CONDUCT.md).
|
113
244
|
|
245
|
+
## Documentation
|
246
|
+
|
247
|
+
The documentation is spread accross the README, CAHCING and the doc folder.
|
248
|
+
|
249
|
+
The documentation can be generated using `bundle exec rake rdoc`
|
250
|
+
|
114
251
|
## License
|
115
252
|
|
116
253
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
117
254
|
|
118
255
|
## Code of Conduct
|
119
256
|
|
120
|
-
Everyone interacting in the Cal::Invite project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/the-pew-inc/cal-invite/blob/master/CODE_OF_CONDUCT.md).
|
257
|
+
Everyone interacting in the Cal::Invite project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/the-pew-inc/cal-invite/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
@@ -2,11 +2,37 @@
|
|
2
2
|
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
require "rake/testtask"
|
5
|
+
require "rdoc/task"
|
5
6
|
|
7
|
+
# Test task configuration
|
6
8
|
Rake::TestTask.new(:test) do |t|
|
7
9
|
t.libs << "test"
|
8
10
|
t.libs << "lib"
|
9
11
|
t.test_files = FileList["test/**/*_test.rb"]
|
10
12
|
end
|
11
13
|
|
14
|
+
# RDoc task configuration
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'doc'
|
17
|
+
rdoc.title = 'CalInvite Documentation'
|
18
|
+
rdoc.main = 'README.md'
|
19
|
+
|
20
|
+
# Configure RDoc options
|
21
|
+
rdoc.options << '--line-numbers'
|
22
|
+
rdoc.options << '--charset' << 'UTF-8'
|
23
|
+
rdoc.options << '--markup' << 'markdown'
|
24
|
+
rdoc.options << '--all'
|
25
|
+
rdoc.options << '--exclude' << '^(test|spec|features)/'
|
26
|
+
|
27
|
+
# Include files to document
|
28
|
+
rdoc.rdoc_files.include('README.md', 'LICENSE.txt', 'lib/**/*.rb')
|
29
|
+
rdoc.rdoc_files.exclude('lib/cal_invite/version.rb')
|
30
|
+
end
|
31
|
+
|
32
|
+
# Define a task to clean documentation
|
33
|
+
task 'rdoc:clean' do
|
34
|
+
rm_rf 'doc'
|
35
|
+
end
|
36
|
+
|
37
|
+
# Keep test as the default task
|
12
38
|
task default: :test
|
data/lib/.DS_Store
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# lib/cal_invite/caching.rb
|
4
|
+
require 'active_support/concern'
|
5
|
+
|
6
|
+
module CalInvite
|
7
|
+
module Caching
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
class_methods do
|
11
|
+
def fetch_from_cache(key, options = {}, &block)
|
12
|
+
full_key = generate_cache_key(key)
|
13
|
+
store = CalInvite.configuration.cache_store
|
14
|
+
|
15
|
+
if store.respond_to?(:fetch)
|
16
|
+
store.fetch(full_key, options, &block)
|
17
|
+
else
|
18
|
+
cached = store.read(full_key)
|
19
|
+
return cached if cached
|
20
|
+
|
21
|
+
value = block.call
|
22
|
+
store.write(full_key, value, options)
|
23
|
+
value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def write_to_cache(key, value, options = {})
|
28
|
+
full_key = generate_cache_key(key)
|
29
|
+
options[:expires_in] ||= CalInvite.configuration.cache_expires_in
|
30
|
+
CalInvite.configuration.cache_store.write(full_key, value, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def read_from_cache(key)
|
34
|
+
full_key = generate_cache_key(key)
|
35
|
+
CalInvite.configuration.cache_store.read(full_key)
|
36
|
+
end
|
37
|
+
|
38
|
+
def clear_cache!
|
39
|
+
store = CalInvite.configuration.cache_store
|
40
|
+
if store.respond_to?(:delete_matched)
|
41
|
+
store.delete_matched("#{CalInvite.configuration.cache_prefix}:*")
|
42
|
+
else
|
43
|
+
store.clear
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def clear_event_cache!(event_id)
|
48
|
+
delete_cache_pattern("events:#{event_id}")
|
49
|
+
end
|
50
|
+
|
51
|
+
def clear_provider_cache!(provider)
|
52
|
+
delete_cache_pattern("providers:#{provider}")
|
53
|
+
end
|
54
|
+
|
55
|
+
def generate_cache_key(*parts)
|
56
|
+
([CalInvite.configuration.cache_prefix] + parts).join(':')
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def delete_cache_pattern(pattern)
|
62
|
+
store = CalInvite.configuration.cache_store
|
63
|
+
full_pattern = generate_cache_key(pattern)
|
64
|
+
|
65
|
+
if store.respond_to?(:delete_matched)
|
66
|
+
store.delete_matched("#{full_pattern}:*")
|
67
|
+
else
|
68
|
+
# Fallback for stores that don't support pattern deletion
|
69
|
+
store.delete(full_pattern)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|