reportable_rails 0.1.2 → 0.1.3
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/README.md +24 -0
- data/lib/reportable_rails/models/report_category.rb +22 -0
- data/lib/reportable_rails/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec42191250593fe984e7f62ffb0dfbb6367aaa63226267d687f285141a76a5bf
|
4
|
+
data.tar.gz: 65d2a6a9a3e1c6c7e57343586018daba7257e97cd565bfee87023d79fe48935c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5cdf9b9698e1f620d19cd18680cef743b6fca62b875cf0c55d313ea893e35e0157a6f013e4f789d12010dca93b26676ca7cf270dd07fb09800ed8d52dbe58a5
|
7
|
+
data.tar.gz: ba76a3b406fbe56b6032c4ed6ee313b445ef4bc6c8d4f9d8f26625201df3c61312d5fbe241e223d17d81f67fceb988e900083f1496d0f0ffd6200880ffa7456c
|
data/README.md
CHANGED
@@ -31,6 +31,9 @@ ReportableRails.configure do |config|
|
|
31
31
|
# Your custom logic here
|
32
32
|
# For example: NotificationMailer.report_submitted(report).deliver_later
|
33
33
|
}
|
34
|
+
|
35
|
+
# Customize the name of the default category
|
36
|
+
config.default_category_name = 'General' # Defaults to 'Uncategorized'
|
34
37
|
end
|
35
38
|
```
|
36
39
|
|
@@ -121,6 +124,27 @@ report = TimeReport.create!(
|
|
121
124
|
)
|
122
125
|
```
|
123
126
|
|
127
|
+
### Default Category
|
128
|
+
|
129
|
+
ReportableRails automatically manages a default "Uncategorized" category that cannot be deactivated or deleted. You can customize the name of this category in your configuration:
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
ReportableRails.configure do |config|
|
133
|
+
config.default_category_name = 'General' # Defaults to 'Uncategorized'
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
To access the default category:
|
138
|
+
|
139
|
+
```ruby
|
140
|
+
default_category = ReportCategory.default_category # Returns or creates the default category
|
141
|
+
```
|
142
|
+
|
143
|
+
Reports without a specific category will use this default category. The default category:
|
144
|
+
- Cannot be deactivated
|
145
|
+
- Cannot be deleted
|
146
|
+
- Is automatically created when first accessed
|
147
|
+
|
124
148
|
### Database Setup
|
125
149
|
|
126
150
|
You'll need to create the necessary database tables. Here are the recommended migrations:
|
@@ -9,18 +9,33 @@ module ReportableRails
|
|
9
9
|
validates :name, presence: true, uniqueness: { case_sensitive: false }
|
10
10
|
validates :description, length: { maximum: 1000 }
|
11
11
|
validates :active, inclusion: { in: [true, false] }
|
12
|
+
validate :prevent_deactivating_default_category
|
12
13
|
|
13
14
|
# Scopes
|
14
15
|
scope :active, -> { where(active: true) }
|
15
16
|
scope :ordered, -> { order(:name) }
|
16
17
|
|
17
18
|
before_validation :set_default_active
|
19
|
+
before_destroy :prevent_destroying_default_category
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
23
|
def set_default_active
|
22
24
|
self.active = true if active.nil?
|
23
25
|
end
|
26
|
+
|
27
|
+
def prevent_deactivating_default_category
|
28
|
+
if name == ReportableRails.configuration.default_category_name && !active
|
29
|
+
errors.add(:active, "cannot deactivate the default category")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def prevent_destroying_default_category
|
34
|
+
if name == ReportableRails.configuration.default_category_name
|
35
|
+
errors.add(:base, "cannot delete the default category")
|
36
|
+
throw :abort
|
37
|
+
end
|
38
|
+
end
|
24
39
|
end
|
25
40
|
|
26
41
|
module ClassMethods
|
@@ -31,8 +46,15 @@ module ReportableRails
|
|
31
46
|
end
|
32
47
|
end
|
33
48
|
|
49
|
+
# Get or create the default category
|
50
|
+
def default_category
|
51
|
+
find_or_create_by_name(ReportableRails.configuration.default_category_name,
|
52
|
+
description: 'Default category for uncategorized reports')
|
53
|
+
end
|
54
|
+
|
34
55
|
# Deactivate a category without deleting it
|
35
56
|
def deactivate(name)
|
57
|
+
return false if name == ReportableRails.configuration.default_category_name
|
36
58
|
category = find_by(name: name)
|
37
59
|
category&.update(active: false)
|
38
60
|
end
|