reportable_rails 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7e5ec2f4a9c2f8a9cdcbfeb33e8644619d50ea228b41406b6f9722a696139969
4
- data.tar.gz: 607c06c8e2f02dcb465bbc3f22da9c0bbdf4516e67aed9191f437dc3eb38d901
3
+ metadata.gz: '0859e1f21d09920db40681907ff7678cffb1b5bda35a0a34e6b1a940de57055c'
4
+ data.tar.gz: 8bc039930b898a3b5ce8d051ca239f990df3146cdfc9f0c5cec58ba03fd4b174
5
5
  SHA512:
6
- metadata.gz: a26f5731f97be20f52a7e887a38dbe80037681e0c759fef6df9a5d79f3bdd31b0de1e7aa7f8b45d70e7039a8ba86b32d3843e7545112d44c8cc6f8a0a5ea3e09
7
- data.tar.gz: 951dd89ad30271c6c0a9ebaae267a9dd78017277f858b52d3795cae394cc52f067e2440189482c00e5e6b7dd66fbb8e78362074cc33c6c63f00ce4fb13070319
6
+ metadata.gz: 84f228e677dc9b530cb06c2e5a3e75412d46a6ab787def6bbd88f43655ffae28041686729e686faf453e763ea235792c3c32134006cbb31f0227c1cfa37f5117
7
+ data.tar.gz: 65832dbf3b45bda9bc8e11999378ad99ce810a5ae05e6398d6c840671fdaa0172895c679c1c15fcfe0c151e4c29708f6e75d941d7afa455d0bc4ca85b2a92ec4
@@ -0,0 +1,34 @@
1
+ module ReportableRails
2
+ module Models
3
+ module HoursLog
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ belongs_to :report, class_name: 'ReportableRails::Report'
8
+
9
+ validates :hours, presence: true, numericality: { greater_than: 0, less_than_or_equal_to: 24 }
10
+ validates :date, presence: true
11
+ validates :description, presence: true, length: { maximum: 1000 }
12
+
13
+ validate :date_within_period
14
+
15
+ # Check if the hours log belongs to the current reporting period
16
+ def current_period?
17
+ return false unless report && date
18
+
19
+ date >= report.current_period_start_date && date <= report.current_period_end_date
20
+ end
21
+
22
+ private
23
+
24
+ def date_within_period
25
+ return unless date && report
26
+
27
+ unless date >= report.current_period_start_date && date <= report.current_period_end_date
28
+ errors.add(:date, "must be within the current reporting period (#{report.current_period_start_date} to #{report.current_period_end_date})")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,42 @@
1
+ module ReportableRails
2
+ module Models
3
+ module ReportCategory
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ has_many :reports, class_name: 'ReportableRails::Report', dependent: :nullify
8
+
9
+ validates :name, presence: true, uniqueness: { case_sensitive: false }
10
+ validates :description, length: { maximum: 1000 }
11
+ validates :active, inclusion: { in: [true, false] }
12
+
13
+ # Scopes
14
+ scope :active, -> { where(active: true) }
15
+ scope :ordered, -> { order(:name) }
16
+
17
+ before_validation :set_default_active
18
+
19
+ private
20
+
21
+ def set_default_active
22
+ self.active = true if active.nil?
23
+ end
24
+ end
25
+
26
+ module ClassMethods
27
+ # Find or create a category by name
28
+ def find_or_create_by_name(name, description: nil)
29
+ find_or_create_by(name: name) do |category|
30
+ category.description = description if description.present?
31
+ end
32
+ end
33
+
34
+ # Deactivate a category without deleting it
35
+ def deactivate(name)
36
+ category = find_by(name: name)
37
+ category&.update(active: false)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module ReportableRails
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reportable_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicu Listana
@@ -103,7 +103,9 @@ extra_rdoc_files: []
103
103
  files:
104
104
  - README.md
105
105
  - lib/reportable_rails.rb
106
+ - lib/reportable_rails/models/hours_log.rb
106
107
  - lib/reportable_rails/models/report.rb
108
+ - lib/reportable_rails/models/report_category.rb
107
109
  - lib/reportable_rails/version.rb
108
110
  homepage: https://github.com/adobocorp/reportable_rails
109
111
  licenses: