microscope 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 24e09b4e48791db9f310f31e0fe03e5bd128e81b
4
- data.tar.gz: a5a0daa121df4e1881be79830ad9dc7a56c47f09
3
+ metadata.gz: 0e77782559a4a6f577799416e0d323bcb8089416
4
+ data.tar.gz: e37d379691cecc853ebc6bbe1fc0776916ef4a64
5
5
  SHA512:
6
- metadata.gz: 063f89d86a2addd04a19809b0470df9b2cad71be676223e420118540606c072d7176c608b11a406542783b5e8130973794e656a8189f398c5b90acdd670dab52
7
- data.tar.gz: ce3228220d767572b5c511d9a30862150b437fc7729b2560c9d8355206f4d4956f8713efa4c8d61d172f16c01c3ca0cf3e32ed7947137b3c469d837f788462af
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 proudly build mobile applications for [iPhone](http://mirego.com/en/iphone-app-development/ "iPhone application development"), [iPad](http://mirego.com/en/ipad-app-development/ "iPad application development"), [Android](http://mirego.com/en/android-app-development/ "Android application development"), [Blackberry](http://mirego.com/en/blackberry-app-development/ "Blackberry application development"), [Windows Phone](http://mirego.com/en/windows-phone-app-development/ "Windows Phone application development") and [Windows 8](http://mirego.com/en/windows-8-app-development/ "Windows 8 application development") in beautiful Quebec City.
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 [open-source software](http://open.mirego.com/) and we try to extract as much code as possible from our projects to give back to the community.
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
- cropped_field = field.name.gsub(/_on$/, '')
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 <= Date.today
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} ||= Date.today
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}=", Date.today)
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
- cropped_field = field.name.gsub(/_at$/, '')
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 <= Time.now
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} ||= Time.now
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}=", Time.now)
36
+ send("#{field.name}=", #{@now})
28
37
  save!
29
38
  end
30
39
  RUBY
@@ -1,3 +1,3 @@
1
1
  module Microscope
2
- VERSION = '0.5.5'
2
+ VERSION = '0.5.6'
3
3
  end
@@ -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.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-01-15 00:00:00.000000000 Z
12
+ date: 2014-02-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport