microscope 0.5.5 → 0.5.6
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 +2 -2
- data/lib/microscope/instance_method.rb +9 -0
- data/lib/microscope/instance_method/date_instance_method.rb +13 -4
- data/lib/microscope/instance_method/datetime_instance_method.rb +13 -4
- data/lib/microscope/version.rb +1 -1
- data/spec/microscope/instance_method/date_instance_method_spec.rb +7 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e77782559a4a6f577799416e0d323bcb8089416
|
4
|
+
data.tar.gz: e37d379691cecc853ebc6bbe1fc0776916ef4a64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 441722b20fb836160b35dd3f813a925d4f00e8f44174ee4d4b1c0eadef178159f7123415f030b16d16663329d3f519b4c7e50bb61d0d8715531b54af2516e9c6
|
7
|
+
data.tar.gz: 911f487cae9156a2d9445893207ecebcecaf818fe48ad4f706f4f36fc56200fce9b13183179453495d383138da14d9416cff8f7ea3019e54266d0dcef913dc2e
|
data/README.md
CHANGED
@@ -115,6 +115,6 @@ The microscope logo is based on [this lovely icon](http://thenounproject.com/nou
|
|
115
115
|
|
116
116
|
## About Mirego
|
117
117
|
|
118
|
-
Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We
|
118
|
+
[Mirego](http://mirego.com) is a team of passionate people who believe that work is a place where you can innovate and have fun. We're a team of [talented people](http://life.mirego.com) who imagine and build beautiful Web and mobile applications. We come together to share ideas and [change the world](http://mirego.org).
|
119
119
|
|
120
|
-
We also love
|
120
|
+
We also [love open-source software](http://open.mirego.com) and we try to give back to the community as much as we can.
|
@@ -1,5 +1,14 @@
|
|
1
1
|
module Microscope
|
2
2
|
class InstanceMethod < Struct.new(:model, :field)
|
3
|
+
def initialize(*args)
|
4
|
+
super
|
5
|
+
@field_name = field.name
|
6
|
+
end
|
7
|
+
|
8
|
+
def cropped_field
|
9
|
+
@cropped_field ||= @field_name.gsub(@cropped_field_regex, '')
|
10
|
+
end
|
11
|
+
|
3
12
|
# Inject ActiveRecord scopes into a model
|
4
13
|
def self.inject_instance_methods(model, fields, options = {})
|
5
14
|
fields.each do |field|
|
@@ -1,19 +1,28 @@
|
|
1
1
|
module Microscope
|
2
2
|
class InstanceMethod
|
3
3
|
class DateInstanceMethod < InstanceMethod
|
4
|
+
def initialize(*args)
|
5
|
+
super
|
6
|
+
|
7
|
+
@now = 'Date.today'
|
8
|
+
@cropped_field_regex = /_on$/
|
9
|
+
end
|
10
|
+
|
4
11
|
def apply
|
5
|
-
|
12
|
+
return unless @field_name =~ @cropped_field_regex
|
13
|
+
|
14
|
+
cropped_field = field.name.gsub(@cropped_field_regex, '')
|
6
15
|
infinitive_verb = self.class.past_participle_to_infinitive(cropped_field)
|
7
16
|
|
8
17
|
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
9
18
|
define_method "#{cropped_field}?" do
|
10
19
|
value = send("#{field.name}")
|
11
|
-
!value.nil? && value <=
|
20
|
+
!value.nil? && value <= #{@now}
|
12
21
|
end
|
13
22
|
|
14
23
|
define_method "#{cropped_field}=" do |value|
|
15
24
|
if Microscope::InstanceMethod.value_to_boolean(value)
|
16
|
-
self.#{field.name} ||=
|
25
|
+
self.#{field.name} ||= #{@now}
|
17
26
|
else
|
18
27
|
self.#{field.name} = nil
|
19
28
|
end
|
@@ -24,7 +33,7 @@ module Microscope
|
|
24
33
|
end
|
25
34
|
|
26
35
|
define_method "#{infinitive_verb}!" do
|
27
|
-
send("#{field.name}=",
|
36
|
+
send("#{field.name}=", #{@now})
|
28
37
|
save!
|
29
38
|
end
|
30
39
|
RUBY
|
@@ -1,19 +1,28 @@
|
|
1
1
|
module Microscope
|
2
2
|
class InstanceMethod
|
3
3
|
class DatetimeInstanceMethod < InstanceMethod
|
4
|
+
def initialize(*args)
|
5
|
+
super
|
6
|
+
|
7
|
+
@now = 'Time.now'
|
8
|
+
@cropped_field_regex = /_at$/
|
9
|
+
end
|
10
|
+
|
4
11
|
def apply
|
5
|
-
|
12
|
+
return unless @field_name =~ @cropped_field_regex
|
13
|
+
|
14
|
+
cropped_field = field.name.gsub(@cropped_field_regex, '')
|
6
15
|
infinitive_verb = self.class.past_participle_to_infinitive(cropped_field)
|
7
16
|
|
8
17
|
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
9
18
|
define_method "#{cropped_field}?" do
|
10
19
|
value = send("#{field.name}")
|
11
|
-
!value.nil? && value <=
|
20
|
+
!value.nil? && value <= #{@now}
|
12
21
|
end
|
13
22
|
|
14
23
|
define_method "#{cropped_field}=" do |value|
|
15
24
|
if Microscope::InstanceMethod.value_to_boolean(value)
|
16
|
-
self.#{field.name} ||=
|
25
|
+
self.#{field.name} ||= #{@now}
|
17
26
|
else
|
18
27
|
self.#{field.name} = nil
|
19
28
|
end
|
@@ -24,7 +33,7 @@ module Microscope
|
|
24
33
|
end
|
25
34
|
|
26
35
|
define_method "#{infinitive_verb}!" do
|
27
|
-
send("#{field.name}=",
|
36
|
+
send("#{field.name}=", #{@now})
|
28
37
|
save!
|
29
38
|
end
|
30
39
|
RUBY
|
data/lib/microscope/version.rb
CHANGED
@@ -4,6 +4,7 @@ describe Microscope::InstanceMethod::DateInstanceMethod do
|
|
4
4
|
before do
|
5
5
|
run_migration do
|
6
6
|
create_table(:events, force: true) do |t|
|
7
|
+
t.date :start_date, default: nil
|
7
8
|
t.date :started_on, default: nil
|
8
9
|
end
|
9
10
|
end
|
@@ -11,6 +12,12 @@ describe Microscope::InstanceMethod::DateInstanceMethod do
|
|
11
12
|
microscope 'Event'
|
12
13
|
end
|
13
14
|
|
15
|
+
describe '#start_date being ignored' do
|
16
|
+
specify do
|
17
|
+
expect { Event.create(start_date: 2.months.ago) }.to_not raise_error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
14
21
|
describe '#started?' do
|
15
22
|
context 'with positive result' do
|
16
23
|
subject { Event.create(started_on: 2.months.ago) }
|
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: 0.5.
|
4
|
+
version: 0.5.6
|
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: 2014-
|
12
|
+
date: 2014-02-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|