microscope 0.5 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/data/irregular_verbs.yml +155 -0
- data/lib/microscope/instance_method/boolean_instance_method.rb +16 -0
- data/lib/microscope/instance_method/date_instance_method.rb +6 -0
- data/lib/microscope/instance_method/datetime_instance_method.rb +6 -0
- data/lib/microscope/instance_method.rb +11 -0
- data/lib/microscope/version.rb +1 -1
- data/lib/microscope.rb +9 -0
- data/microscope.gemspec +1 -0
- data/spec/microscope/instance_method/boolean_instance_method_spec.rb +18 -0
- data/spec/microscope/instance_method/date_instance_method_spec.rb +8 -0
- data/spec/microscope/instance_method/datetime_instance_method_spec.rb +8 -0
- data/spec/spec_helper.rb +3 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5895b7cb7f78b5949fbc6ed893ec2ce8572cc966
|
4
|
+
data.tar.gz: 26d3e1ec93726e9224d0ff99a4383318932606fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93107c9b07a8fd1c3f5191fe49a7cefc03db714131f003926bcdc09d944f3d5effaaf4e07b647ecd6b8f50fdb3e344f359901dadb6640b3f3e85008dde4f391c
|
7
|
+
data.tar.gz: e3444a475a126c37c4c5f4ffbdba31edadc18012aa39f696d1c6953f4d77fce431c799392e16d8e352dc6ba3669518ccfa2cbac4769d66ed0e3788592bdba19f
|
data/README.md
CHANGED
@@ -7,6 +7,8 @@
|
|
7
7
|
<br /><br />
|
8
8
|
<a href="https://rubygems.org/gems/microscope"><img src="https://badge.fury.io/rb/microscope.png" /></a>
|
9
9
|
<a href="https://codeclimate.com/github/mirego/microscope"><img src="https://codeclimate.com/github/mirego/microscope.png" /></a>
|
10
|
+
<a href='https://coveralls.io/r/mirego/microscope?branch=master'><img src='https://coveralls.io/repos/mirego/microscope/badge.png?branch=master' /></a>
|
11
|
+
<a href='https://gemnasium.com/mirego/microscope'><img src="https://gemnasium.com/mirego/microscope.png" /></a>
|
10
12
|
<a href="https://travis-ci.org/mirego/microscope"><img src="https://travis-ci.org/mirego/microscope.png?branch=master" /></a>
|
11
13
|
</p>
|
12
14
|
|
@@ -68,7 +70,7 @@ Event.not_started
|
|
68
70
|
# SELECT * FROM `events` where `events`.`started_at` IS NULL OR `events`.`started_at` > '2013-07-05 15:43:42'
|
69
71
|
```
|
70
72
|
|
71
|
-
Microscope also adds
|
73
|
+
Microscope also adds three instance methods to the model per scope.
|
72
74
|
|
73
75
|
```ruby
|
74
76
|
event = Event.started.first
|
@@ -76,6 +78,13 @@ event = Event.started.first
|
|
76
78
|
|
77
79
|
event.started? # => true
|
78
80
|
event.not_started? # => false
|
81
|
+
|
82
|
+
event = Event.unstarted.first
|
83
|
+
event.started? # => false
|
84
|
+
|
85
|
+
event.start!
|
86
|
+
event.started? # => true
|
87
|
+
event.started_at # => 2013-07-05 15:43:44 (Time.now)
|
79
88
|
```
|
80
89
|
|
81
90
|
### Options
|
@@ -0,0 +1,155 @@
|
|
1
|
+
arisen: arise
|
2
|
+
awoken: awake
|
3
|
+
been: be
|
4
|
+
borne: bear
|
5
|
+
beaten: beat
|
6
|
+
beat: beat
|
7
|
+
become: become
|
8
|
+
begun: begin
|
9
|
+
bent: bend
|
10
|
+
bet: bet
|
11
|
+
bitten: bite
|
12
|
+
bled: bleed
|
13
|
+
blown: blow
|
14
|
+
broken: break
|
15
|
+
brought: bring
|
16
|
+
built: build
|
17
|
+
burnt: burn
|
18
|
+
burst: burst
|
19
|
+
bought: buy
|
20
|
+
caught: catch
|
21
|
+
chosen: choose
|
22
|
+
clung: cling
|
23
|
+
come: come
|
24
|
+
cost: cost
|
25
|
+
crept: creep
|
26
|
+
cut: cut
|
27
|
+
dealt: deal
|
28
|
+
dug: dig
|
29
|
+
dived: dive
|
30
|
+
done: do
|
31
|
+
drawn: draw
|
32
|
+
dreamt: dream
|
33
|
+
dreamed: dream
|
34
|
+
drunk: drink
|
35
|
+
driven: drive
|
36
|
+
eaten: eat
|
37
|
+
fallen: fall
|
38
|
+
fed: feed
|
39
|
+
felt: feel
|
40
|
+
fought: fight
|
41
|
+
found: find
|
42
|
+
fit: fit
|
43
|
+
fled: flee
|
44
|
+
flung: fling
|
45
|
+
flown: fly
|
46
|
+
forbidden: forbid
|
47
|
+
forbade: forbid
|
48
|
+
forgotten: forget
|
49
|
+
forgiven: forgive
|
50
|
+
forgone: forgo
|
51
|
+
frozen: freeze
|
52
|
+
gotten: get
|
53
|
+
got: get
|
54
|
+
given: give
|
55
|
+
gone: go
|
56
|
+
ground: grind
|
57
|
+
grown: grow
|
58
|
+
hung: hang
|
59
|
+
had: have
|
60
|
+
heard: hear
|
61
|
+
hidden: hide
|
62
|
+
hit: hit
|
63
|
+
held: hold
|
64
|
+
hurt: hurt
|
65
|
+
kept: keep
|
66
|
+
knelt: kneel
|
67
|
+
knit: knit
|
68
|
+
known: know
|
69
|
+
laid: lay
|
70
|
+
led: lead
|
71
|
+
leapt: leap
|
72
|
+
left: leave
|
73
|
+
lent: lend
|
74
|
+
let: let
|
75
|
+
lain: lie
|
76
|
+
lit: light
|
77
|
+
lost: lose
|
78
|
+
made: make
|
79
|
+
meant: mean
|
80
|
+
met: meet
|
81
|
+
paid: pay
|
82
|
+
proven: prove
|
83
|
+
put: put
|
84
|
+
quit: quit
|
85
|
+
read: read
|
86
|
+
ridden: ride
|
87
|
+
rung: ring
|
88
|
+
risen: rise
|
89
|
+
run: run
|
90
|
+
sawn: saw
|
91
|
+
said: say
|
92
|
+
seen: see
|
93
|
+
sought: seek
|
94
|
+
sold: sell
|
95
|
+
sent: send
|
96
|
+
set: set
|
97
|
+
sewn: sew
|
98
|
+
shaken: shake
|
99
|
+
shaven: shave
|
100
|
+
shorn: shear
|
101
|
+
shone: shine
|
102
|
+
shot: shoot
|
103
|
+
shown: show
|
104
|
+
shrunken: shrink
|
105
|
+
shrunk: shrink
|
106
|
+
shut: shut
|
107
|
+
sung: sing
|
108
|
+
sunk: sink
|
109
|
+
sat: sit
|
110
|
+
slain: slay
|
111
|
+
slept: sleep
|
112
|
+
slid: slide
|
113
|
+
snuck: sneak
|
114
|
+
spoken: speak
|
115
|
+
sped: speed
|
116
|
+
spent: spend
|
117
|
+
spilt: spill
|
118
|
+
spun: spin
|
119
|
+
spit: spit
|
120
|
+
spat: spit
|
121
|
+
split: split
|
122
|
+
spread: spread
|
123
|
+
sprung: spring
|
124
|
+
stood: stand
|
125
|
+
stolen: steal
|
126
|
+
stuck: stick
|
127
|
+
stung: sting
|
128
|
+
stunk: stink
|
129
|
+
strewn: strew
|
130
|
+
struck: strike
|
131
|
+
stricken: strike
|
132
|
+
striven: strive
|
133
|
+
sworn: swear
|
134
|
+
swept: sweep
|
135
|
+
swum: swim
|
136
|
+
swung: swing
|
137
|
+
taken: take
|
138
|
+
taught: teach
|
139
|
+
torn: tear
|
140
|
+
told: tell
|
141
|
+
thought: think
|
142
|
+
thriven: thrive
|
143
|
+
thrown: throw
|
144
|
+
undergone: undergo
|
145
|
+
understood: understand
|
146
|
+
upset: upset
|
147
|
+
woken: wake
|
148
|
+
worn: wear
|
149
|
+
woven: weave
|
150
|
+
wept: weep
|
151
|
+
won: win
|
152
|
+
wound: wind
|
153
|
+
withdrawn: withdraw
|
154
|
+
wrung: wring
|
155
|
+
written: write
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Microscope
|
2
|
+
class InstanceMethod
|
3
|
+
class BooleanInstanceMethod < InstanceMethod
|
4
|
+
def apply
|
5
|
+
infinitive_verb = self.class.past_participle_to_infinitive(field.name)
|
6
|
+
|
7
|
+
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
8
|
+
define_method "#{infinitive_verb}!" do
|
9
|
+
send("#{field.name}=", true)
|
10
|
+
save!
|
11
|
+
end
|
12
|
+
RUBY
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -3,6 +3,7 @@ module Microscope
|
|
3
3
|
class DateInstanceMethod < InstanceMethod
|
4
4
|
def apply
|
5
5
|
cropped_field = field.name.gsub(/_on$/, '')
|
6
|
+
infinitive_verb = self.class.past_participle_to_infinitive(cropped_field)
|
6
7
|
|
7
8
|
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
8
9
|
define_method "#{cropped_field}?" do
|
@@ -13,6 +14,11 @@ module Microscope
|
|
13
14
|
define_method "not_#{cropped_field}?" do
|
14
15
|
!#{cropped_field}?
|
15
16
|
end
|
17
|
+
|
18
|
+
define_method "#{infinitive_verb}!" do
|
19
|
+
send("#{field.name}=", Date.today)
|
20
|
+
save!
|
21
|
+
end
|
16
22
|
RUBY
|
17
23
|
end
|
18
24
|
end
|
@@ -3,6 +3,7 @@ module Microscope
|
|
3
3
|
class DatetimeInstanceMethod < InstanceMethod
|
4
4
|
def apply
|
5
5
|
cropped_field = field.name.gsub(/_at$/, '')
|
6
|
+
infinitive_verb = self.class.past_participle_to_infinitive(cropped_field)
|
6
7
|
|
7
8
|
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
8
9
|
define_method "#{cropped_field}?" do
|
@@ -13,6 +14,11 @@ module Microscope
|
|
13
14
|
define_method "not_#{cropped_field}?" do
|
14
15
|
!#{cropped_field}?
|
15
16
|
end
|
17
|
+
|
18
|
+
define_method "#{infinitive_verb}!" do
|
19
|
+
send("#{field.name}=", Time.now)
|
20
|
+
save!
|
21
|
+
end
|
16
22
|
RUBY
|
17
23
|
end
|
18
24
|
end
|
@@ -10,5 +10,16 @@ module Microscope
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
13
|
+
|
14
|
+
# Convert a past participle to its infinitive form
|
15
|
+
def self.past_participle_to_infinitive(participle)
|
16
|
+
if Microscope.irregular_verbs.include?(participle)
|
17
|
+
Microscope.irregular_verbs[participle]
|
18
|
+
elsif participle =~ /ed$/
|
19
|
+
participle.sub(/ed$/, '')
|
20
|
+
else
|
21
|
+
participle
|
22
|
+
end
|
23
|
+
end
|
13
24
|
end
|
14
25
|
end
|
data/lib/microscope/version.rb
CHANGED
data/lib/microscope.rb
CHANGED
@@ -9,9 +9,18 @@ require "microscope/scope/datetime_scope"
|
|
9
9
|
require "microscope/scope/date_scope"
|
10
10
|
|
11
11
|
require "microscope/instance_method"
|
12
|
+
require "microscope/instance_method/boolean_instance_method"
|
12
13
|
require "microscope/instance_method/datetime_instance_method"
|
13
14
|
require "microscope/instance_method/date_instance_method"
|
14
15
|
|
16
|
+
module Microscope
|
17
|
+
IRREGULAR_VERBS_FILE = File.expand_path('../../data/irregular_verbs.yml', __FILE__)
|
18
|
+
|
19
|
+
def self.irregular_verbs
|
20
|
+
@irregular_verbs ||= YAML.load_file(IRREGULAR_VERBS_FILE)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
15
24
|
class ActiveRecord::Base
|
16
25
|
def self.acts_as_microscope(options = {})
|
17
26
|
return unless table_exists?
|
data/microscope.gemspec
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Microscope::InstanceMethod::BooleanInstanceMethod do
|
4
|
+
before do
|
5
|
+
run_migration do
|
6
|
+
create_table(:animals, force: true) do |t|
|
7
|
+
t.boolean :fed, default: false
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
microscope 'Animal'
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#feed!' do
|
15
|
+
let(:animal) { Animal.create(fed: false) }
|
16
|
+
it { expect { animal.feed! }.to change { animal.reload.fed? }.from(false).to(true) }
|
17
|
+
end
|
18
|
+
end
|
@@ -36,4 +36,12 @@ describe Microscope::InstanceMethod::DateInstanceMethod do
|
|
36
36
|
it { should be_not_started }
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
describe '#start!' do
|
41
|
+
let(:stubbed_date) { Date.parse('2020-03-18 08:00:00') }
|
42
|
+
before { Date.stub(:today).and_return(stubbed_date) }
|
43
|
+
|
44
|
+
let(:event) { Event.create(started_on: nil) }
|
45
|
+
it { expect { event.start! }.to change { event.reload.started_on }.from(nil).to(stubbed_date) }
|
46
|
+
end
|
39
47
|
end
|
@@ -34,4 +34,12 @@ describe Microscope::InstanceMethod::DatetimeInstanceMethod do
|
|
34
34
|
it { should be_not_started }
|
35
35
|
end
|
36
36
|
end
|
37
|
+
|
38
|
+
describe '#start!' do
|
39
|
+
let(:stubbed_date) { Time.parse('2020-03-18 08:00:00') }
|
40
|
+
before { Time.stub(:now).and_return(stubbed_date) }
|
41
|
+
|
42
|
+
let(:event) { Event.create(started_at: nil) }
|
43
|
+
it { expect { event.start! }.to change { event.reload.started_at }.from(nil).to(stubbed_date) }
|
44
|
+
end
|
37
45
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: microscope
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Prévost
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -123,6 +123,20 @@ dependencies:
|
|
123
123
|
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: 0.3.13
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: coveralls
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
type: :development
|
134
|
+
prerelease: false
|
135
|
+
version_requirements: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
126
140
|
description: Microscope adds useful scopes targeting ActiveRecord boolean and datetime
|
127
141
|
fields.
|
128
142
|
email:
|
@@ -139,10 +153,12 @@ files:
|
|
139
153
|
- LICENSE.md
|
140
154
|
- README.md
|
141
155
|
- Rakefile
|
156
|
+
- data/irregular_verbs.yml
|
142
157
|
- gemfiles/Gemfile.activerecord-3.2.x
|
143
158
|
- gemfiles/Gemfile.activerecord-4.0
|
144
159
|
- lib/microscope.rb
|
145
160
|
- lib/microscope/instance_method.rb
|
161
|
+
- lib/microscope/instance_method/boolean_instance_method.rb
|
146
162
|
- lib/microscope/instance_method/date_instance_method.rb
|
147
163
|
- lib/microscope/instance_method/datetime_instance_method.rb
|
148
164
|
- lib/microscope/scope.rb
|
@@ -151,6 +167,7 @@ files:
|
|
151
167
|
- lib/microscope/scope/datetime_scope.rb
|
152
168
|
- lib/microscope/version.rb
|
153
169
|
- microscope.gemspec
|
170
|
+
- spec/microscope/instance_method/boolean_instance_method_spec.rb
|
154
171
|
- spec/microscope/instance_method/date_instance_method_spec.rb
|
155
172
|
- spec/microscope/instance_method/datetime_instance_method_spec.rb
|
156
173
|
- spec/microscope/scope/boolean_scope_spec.rb
|
@@ -184,12 +201,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
201
|
version: '0'
|
185
202
|
requirements: []
|
186
203
|
rubyforge_project:
|
187
|
-
rubygems_version: 2.0
|
204
|
+
rubygems_version: 2.1.0
|
188
205
|
signing_key:
|
189
206
|
specification_version: 4
|
190
207
|
summary: Microscope adds useful scopes targeting ActiveRecord boolean and datetime
|
191
208
|
fields.
|
192
209
|
test_files:
|
210
|
+
- spec/microscope/instance_method/boolean_instance_method_spec.rb
|
193
211
|
- spec/microscope/instance_method/date_instance_method_spec.rb
|
194
212
|
- spec/microscope/instance_method/datetime_instance_method_spec.rb
|
195
213
|
- spec/microscope/scope/boolean_scope_spec.rb
|