microscope 1.0.0 → 1.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dae239d9a336e0f5dae1eb39800dbf21eecef2d5
4
- data.tar.gz: 2afd2fc1a3eaa7dddb9282a1f1a8daee169a8ec9
3
+ metadata.gz: 1282869f83f7716bed7b98f51ffbf10ac549af20
4
+ data.tar.gz: ce43d2a660b015851ff0a336f7aa68e3dbe853d4
5
5
  SHA512:
6
- metadata.gz: 9348ae5d7f3f2bfd6be7b7f4beebe8f1b82fd052ba0ca56df81c7f66dc81825e6281a8153c0628a501be3d91c29cb0003396c5ecf6b0f6c6b5393e1cbe053316
7
- data.tar.gz: cbcf09bb50632e1794b7c6095e03e3ef7bb1e7adc97d7538f906cf4e027a59dd9ce1a3e35e1c70e598d285fb813b22b6e1f6a8dcb9556dd6f5fef6d512fb805e
6
+ metadata.gz: 1aac23cb4ae88a3177eec3a41d2d2a59de034ab8ccea6374293f22e9f286b7c12d89d7adf41e263d8ceb23743d0b81c092bada433415eec66009b1cc7e0b5f78
7
+ data.tar.gz: b4602d97dde4ce2404e088ec64d7c79890e345f48623510b127e8f5f0f88b85bcc16d17fd392057dfc6c69ca0b4dcf550b830f7509239e13db43ebcf30345226
@@ -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: "echo 'DO IT' && bundle exec rake spec"
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2014, Mirego
1
+ Copyright (c) 2013-2015, Mirego
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
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-2014 [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.
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
 
@@ -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 < Struct.new(:model, :field)
3
- def initialize(*args)
4
- super
5
- @field_name = field.name
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 ||= @field_name.gsub(@cropped_field_regex, '')
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 @field_name =~ @cropped_field_regex
14
+ model.class_eval(apply_methods) if @field.name =~ @cropped_field_regex
15
15
  end
16
16
 
17
17
  protected
@@ -1,18 +1,18 @@
1
1
  module Microscope
2
- class Scope < Struct.new(:model, :field)
3
- def initialize(*args)
4
- super
2
+ class Scope
3
+ attr_reader :model, :field
5
4
 
6
- @field_name = field.name
7
- @table_name = model.name.tableize
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(@field_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 ||= @field_name.gsub(@cropped_field_regex, '')
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 "#{@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} }
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 @field_name =~ @cropped_field_regex
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("#{@field_name}" => range) }
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}) }
@@ -1,3 +1,3 @@
1
1
  module Microscope
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -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', '~> 0.28'
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(:users, force: true) do |t|
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
@@ -2,8 +2,8 @@ module ModelMacros
2
2
  # Create a new microscope model
3
3
  def microscope(klass_name, options = {}, &block)
4
4
  spawn_model klass_name, ActiveRecord::Base do
5
- acts_as_microscope options
6
5
  instance_exec(&block) if block
6
+ acts_as_microscope options
7
7
  end
8
8
  end
9
9
 
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.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-01-12 00:00:00.000000000 Z
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.28'
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.28'
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