microscope 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -1
- data/LICENSE.md +1 -1
- data/README.md +1 -1
- data/UPGRADE.md +37 -0
- data/lib/microscope/instance_method.rb +7 -5
- data/lib/microscope/instance_method/datetime_instance_method.rb +1 -1
- data/lib/microscope/scope.rb +7 -7
- data/lib/microscope/scope/boolean_scope.rb +3 -3
- data/lib/microscope/scope/datetime_scope.rb +2 -2
- data/lib/microscope/version.rb +1 -1
- data/microscope.gemspec +1 -1
- data/spec/microscope/scope/boolean_scope_spec.rb +4 -2
- data/spec/support/macros/model_macros.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1282869f83f7716bed7b98f51ffbf10ac549af20
|
4
|
+
data.tar.gz: ce43d2a660b015851ff0a336f7aa68e3dbe853d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1aac23cb4ae88a3177eec3a41d2d2a59de034ab8ccea6374293f22e9f286b7c12d89d7adf41e263d8ceb23743d0b81c092bada433415eec66009b1cc7e0b5f78
|
7
|
+
data.tar.gz: b4602d97dde4ce2404e088ec64d7c79890e345f48623510b127e8f5f0f88b85bcc16d17fd392057dfc6c69ca0b4dcf550b830f7509239e13db43ebcf30345226
|
data/.travis.yml
CHANGED
@@ -18,7 +18,9 @@ before_script:
|
|
18
18
|
- mysql -e 'create database microscope_test;'
|
19
19
|
- psql -c 'create database microscope_test;' -U postgres
|
20
20
|
|
21
|
-
script:
|
21
|
+
script:
|
22
|
+
- 'echo "Checking code style" && bundle exec phare'
|
23
|
+
- 'echo "Running tests" && bundle exec rake spec'
|
22
24
|
|
23
25
|
notifications:
|
24
26
|
hipchat:
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
@@ -123,7 +123,7 @@ User.updated_before(2.months.ago) # works!
|
|
123
123
|
|
124
124
|
## License
|
125
125
|
|
126
|
-
`Microscope` is © 2013-
|
126
|
+
`Microscope` is © 2013-2015 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/microscope/blob/master/LICENSE.md) file.
|
127
127
|
|
128
128
|
The microscope logo is based on [this lovely icon](http://thenounproject.com/noun/microscope/#icon-No9056) by [Scott Lewis](http://thenounproject.com/iconify), from The Noun Project. Used under a [Creative Commons BY 3.0](http://creativecommons.org/licenses/by/3.0/) license.
|
129
129
|
|
data/UPGRADE.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
## v1.0
|
2
|
+
|
3
|
+
Microscope no longer adds instance methods based on the "imperative" grammatical mood.
|
4
|
+
|
5
|
+
It now adds the `mark_as_<verb>!` instance method which does the same thing as
|
6
|
+
the `mark_as_<verb>` method but then calls `save!` on the record.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
# Before 1.0
|
10
|
+
class Event < ActiveRecord::Base
|
11
|
+
acts_as_microscope
|
12
|
+
end
|
13
|
+
|
14
|
+
event = Event.new(started_on: nil)
|
15
|
+
|
16
|
+
event.mark_as_started
|
17
|
+
event.started_on # => 2015-02-23T07:58:31-0500
|
18
|
+
event.reload.started_on # => nil
|
19
|
+
|
20
|
+
event.start!
|
21
|
+
event.reload.started_on # => 2015-02-23T07:58:31-0500
|
22
|
+
|
23
|
+
# After 1.0
|
24
|
+
class Event < ActiveRecord::Base
|
25
|
+
acts_as_microscope
|
26
|
+
end
|
27
|
+
|
28
|
+
event = Event.new(started_on: nil)
|
29
|
+
|
30
|
+
event.mark_as_started
|
31
|
+
event.started_on # => 2015-02-23T07:58:31-0500
|
32
|
+
event.reload.started_on # => nil
|
33
|
+
|
34
|
+
event.start! # NoMethodError
|
35
|
+
event.mark_as_started!
|
36
|
+
event.reload.started_on # => 2015-02-23T07:58:32-0500
|
37
|
+
```
|
@@ -1,12 +1,14 @@
|
|
1
1
|
module Microscope
|
2
|
-
class InstanceMethod
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class InstanceMethod
|
3
|
+
attr_reader :model, :field
|
4
|
+
|
5
|
+
def initialize(model, field)
|
6
|
+
@model = model
|
7
|
+
@field = field
|
6
8
|
end
|
7
9
|
|
8
10
|
def cropped_field
|
9
|
-
@cropped_field ||= @
|
11
|
+
@cropped_field ||= @field.name.gsub(@cropped_field_regex, '')
|
10
12
|
end
|
11
13
|
|
12
14
|
# Inject ActiveRecord scopes into a model
|
@@ -11,7 +11,7 @@ module Microscope
|
|
11
11
|
def apply
|
12
12
|
@cropped_field = field.name.gsub(@cropped_field_regex, '')
|
13
13
|
|
14
|
-
model.class_eval(apply_methods) if @
|
14
|
+
model.class_eval(apply_methods) if @field.name =~ @cropped_field_regex
|
15
15
|
end
|
16
16
|
|
17
17
|
protected
|
data/lib/microscope/scope.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
module Microscope
|
2
|
-
class Scope
|
3
|
-
|
4
|
-
super
|
2
|
+
class Scope
|
3
|
+
attr_reader :model, :field
|
5
4
|
|
6
|
-
|
7
|
-
@
|
5
|
+
def initialize(model, field)
|
6
|
+
@model = model
|
7
|
+
@field = field
|
8
8
|
end
|
9
9
|
|
10
10
|
def quoted_field
|
11
|
-
@quoted_field ||= "#{ActiveRecord::Base.connection.quote_table_name(@table_name)}.#{ActiveRecord::Base.connection.quote_column_name(@
|
11
|
+
@quoted_field ||= "#{ActiveRecord::Base.connection.quote_table_name(@model.table_name)}.#{ActiveRecord::Base.connection.quote_column_name(@field.name)}"
|
12
12
|
end
|
13
13
|
|
14
14
|
def cropped_field
|
15
|
-
@cropped_field ||= @
|
15
|
+
@cropped_field ||= @field.name.gsub(@cropped_field_regex, '')
|
16
16
|
end
|
17
17
|
|
18
18
|
# Inject ActiveRecord scopes into a model
|
@@ -3,9 +3,9 @@ module Microscope
|
|
3
3
|
class BooleanScope < Scope
|
4
4
|
def apply
|
5
5
|
model.class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
6
|
-
scope "#{@
|
7
|
-
scope "not_#{@
|
8
|
-
scope "un#{@
|
6
|
+
scope "#{@field.name}", lambda { where("#{@field.name}" => true) }
|
7
|
+
scope "not_#{@field.name}", lambda { where("#{@field.name}" => false) }
|
8
|
+
scope "un#{@field.name}", lambda { not_#{@field.name} }
|
9
9
|
RUBY
|
10
10
|
end
|
11
11
|
end
|
@@ -12,7 +12,7 @@ module Microscope
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def apply
|
15
|
-
model.class_eval(apply_scopes) if @
|
15
|
+
model.class_eval(apply_scopes) if @field.name =~ @cropped_field_regex
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
@@ -29,7 +29,7 @@ module Microscope
|
|
29
29
|
scope "#{cropped_field}_after#{@now_suffix}", lambda { where('#{quoted_field} > ?', #{@now}) }
|
30
30
|
scope "#{cropped_field}_after_or#{@now_suffix}", lambda { where('#{quoted_field} >= ?', #{@now}) }
|
31
31
|
|
32
|
-
scope "#{cropped_field}_between", lambda { |range| where("#{@
|
32
|
+
scope "#{cropped_field}_between", lambda { |range| where("#{@field.name}" => range) }
|
33
33
|
|
34
34
|
scope "#{cropped_field}", lambda { where('#{quoted_field} IS NOT NULL AND #{quoted_field} <= ?', #{@now}) }
|
35
35
|
scope "not_#{cropped_field}", lambda { where('#{quoted_field} IS NULL OR #{quoted_field} > ?', #{@now}) }
|
data/lib/microscope/version.rb
CHANGED
data/microscope.gemspec
CHANGED
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'sqlite3'
|
28
28
|
spec.add_development_dependency 'pg'
|
29
29
|
spec.add_development_dependency 'mysql2', '~> 0.3.13'
|
30
|
-
spec.add_development_dependency 'rubocop', '
|
30
|
+
spec.add_development_dependency 'rubocop', '0.29'
|
31
31
|
spec.add_development_dependency 'phare'
|
32
32
|
end
|
@@ -3,12 +3,14 @@ require 'spec_helper'
|
|
3
3
|
describe Microscope::Scope::BooleanScope do
|
4
4
|
before do
|
5
5
|
run_migration do
|
6
|
-
create_table(:
|
6
|
+
create_table(:oh_users, force: true) do |t|
|
7
7
|
t.boolean :active, default: false
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
microscope 'User'
|
11
|
+
microscope 'User' do
|
12
|
+
self.table_name = 'oh_users'
|
13
|
+
end
|
12
14
|
end
|
13
15
|
|
14
16
|
describe 'positive scope' do
|
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: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Prévost
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-
|
13
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activesupport
|
@@ -128,16 +128,16 @@ dependencies:
|
|
128
128
|
name: rubocop
|
129
129
|
requirement: !ruby/object:Gem::Requirement
|
130
130
|
requirements:
|
131
|
-
- -
|
131
|
+
- - '='
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version: '0.
|
133
|
+
version: '0.29'
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
|
-
- -
|
138
|
+
- - '='
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version: '0.
|
140
|
+
version: '0.29'
|
141
141
|
- !ruby/object:Gem::Dependency
|
142
142
|
name: phare
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- LICENSE.md
|
171
171
|
- README.md
|
172
172
|
- Rakefile
|
173
|
+
- UPGRADE.md
|
173
174
|
- gemfiles/Gemfile.activerecord-4.1
|
174
175
|
- lib/microscope.rb
|
175
176
|
- lib/microscope/instance_method.rb
|