calendar_sniper 1.1.3 → 1.1.5
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/.rubocop.yml +27 -0
- data/lib/calendar_sniper/version.rb +1 -1
- data/lib/calendar_sniper.rb +21 -8
- metadata +16 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0fb8a0724727a39f5eb81e8f032387369655446d
|
4
|
+
data.tar.gz: 7b4cbe5a588b28781b1c824088e84fb20587ec12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73d80d092a4794adf7b819f14fb69da71e0f3e9d4c4c298c855ff05e5bd843036d8f2dec51640d90684a06af9e8f37c48d85d6da61367c5e873eec3cb6f6c618
|
7
|
+
data.tar.gz: 7cd9ef2435ede7d8954f01126d4f9686ef6eb32227bcb1d1a1766da302a260b84f828d4ad0b7b6a8cd99ffe3b14f8f8117c4831e7709adbc9727957ebc20696d
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
AllCops:
|
2
|
+
Include:
|
3
|
+
- Rakefile
|
4
|
+
Exclude:
|
5
|
+
- db/**/*
|
6
|
+
- config/**/*
|
7
|
+
- script/**/*
|
8
|
+
- bin/**/*
|
9
|
+
LineLength:
|
10
|
+
Enabled: true
|
11
|
+
Max: 150
|
12
|
+
Documentation:
|
13
|
+
Enabled: false
|
14
|
+
AlignParameters:
|
15
|
+
Enabled: false
|
16
|
+
MethodLength:
|
17
|
+
Max: 30
|
18
|
+
AndOr:
|
19
|
+
Enabled: false
|
20
|
+
ClassLength:
|
21
|
+
Max: 200
|
22
|
+
ClassAndModuleChildren:
|
23
|
+
Enabled: false
|
24
|
+
MultilineOperationIndentation:
|
25
|
+
Enabled: false
|
26
|
+
Metrics/AbcSize:
|
27
|
+
Max: 20
|
data/lib/calendar_sniper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'calendar_sniper/version'
|
2
2
|
require 'active_support'
|
3
3
|
require 'active_support/core_ext/date'
|
4
4
|
require 'active_support/core_ext/date_time'
|
@@ -8,10 +8,23 @@ module CalendarSniper
|
|
8
8
|
extend ActiveSupport::Concern
|
9
9
|
|
10
10
|
included do
|
11
|
-
scope
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
scope(:with_date_range, lambda do |num_days|
|
12
|
+
case num_days
|
13
|
+
when /\A\d+(?:\.\d+)?\z/
|
14
|
+
with_from_date(num_days.to_f.days.ago)
|
15
|
+
when 'today'
|
16
|
+
where(started: Date.today.beginning_of_day..Time.now)
|
17
|
+
when 'yesterday'
|
18
|
+
where(started: Date.yesterday.beginning_of_day..Date.yesterday.end_of_day)
|
19
|
+
when 'last_month'
|
20
|
+
where(started: 1.month.ago.beginning_of_month..1.month.ago.end_of_month)
|
21
|
+
else
|
22
|
+
fail "Unknown date range for filtering: #{num_days}"
|
23
|
+
end
|
24
|
+
end)
|
25
|
+
scope :with_to_date, ->(date) { search_in_date_range :<, date }
|
26
|
+
scope :with_from_date, ->(date) { search_in_date_range :>, date }
|
27
|
+
scope :in_date_range, ->(from, to) { with_from_date(from).with_to_date(to) }
|
15
28
|
end
|
16
29
|
|
17
30
|
module ClassMethods
|
@@ -23,14 +36,14 @@ module CalendarSniper
|
|
23
36
|
#
|
24
37
|
# filterable_by_date_range :internal_lead_received_at
|
25
38
|
#
|
26
|
-
def filterable_by_date_range
|
39
|
+
def filterable_by_date_range(with_name = :created_at)
|
27
40
|
@_filterable_by_date_range_field = with_name.to_s
|
28
41
|
end
|
29
42
|
|
30
43
|
# Search through the date range in a given direction. Uses the
|
31
44
|
# field given in the +filterable_by_date_range+ macro that you
|
32
45
|
# can add to ActiveRecord, otherwise it defaults to 'created_at'.
|
33
|
-
def search_in_date_range
|
46
|
+
def search_in_date_range(by_direction, with_date)
|
34
47
|
logger.debug "Searched #{date_field} on #{self.class.name} with a scope"
|
35
48
|
where("#{table_name}.#{date_field} #{by_direction}= ?", coalesce_date(with_date, by_direction))
|
36
49
|
end
|
@@ -71,7 +84,7 @@ module CalendarSniper
|
|
71
84
|
'%Y-%m-%d'
|
72
85
|
end
|
73
86
|
else
|
74
|
-
|
87
|
+
fail "Date string in unknown format: #{str}"
|
75
88
|
end
|
76
89
|
end
|
77
90
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: calendar_sniper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris MacNaughton
|
@@ -9,62 +9,62 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 3.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 3.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - ~>
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '1.3'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.3'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rspec
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- -
|
60
|
+
- - ">="
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- -
|
67
|
+
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '0'
|
70
70
|
description: Gem that adds date related scopes to ActiveRecord models
|
@@ -75,8 +75,9 @@ executables: []
|
|
75
75
|
extensions: []
|
76
76
|
extra_rdoc_files: []
|
77
77
|
files:
|
78
|
-
- .gitignore
|
79
|
-
- .rspec
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- ".rubocop.yml"
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
82
83
|
- README.md
|
@@ -96,17 +97,17 @@ require_paths:
|
|
96
97
|
- lib
|
97
98
|
required_ruby_version: !ruby/object:Gem::Requirement
|
98
99
|
requirements:
|
99
|
-
- -
|
100
|
+
- - ">="
|
100
101
|
- !ruby/object:Gem::Version
|
101
102
|
version: '0'
|
102
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
104
|
requirements:
|
104
|
-
- -
|
105
|
+
- - ">="
|
105
106
|
- !ruby/object:Gem::Version
|
106
107
|
version: '0'
|
107
108
|
requirements: []
|
108
109
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.5.2
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
113
|
summary: CalendarSniper adds with_date_range, with_to_date, with_from_date, and in_date_range
|