microscope 0.5.10 → 0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e689cfc89dab08583830dd95f1f5cd8be83581f
4
- data.tar.gz: cf02e022cbb8fccfcf1c0d4bba6d5896a54a056b
3
+ metadata.gz: 7b92f3130f66038fbee86f9e5adaa467e6800dfe
4
+ data.tar.gz: 4ee59ea3ff8050b8abd0cc6bb0d9bb668ebaf3ce
5
5
  SHA512:
6
- metadata.gz: d2ca0c502bd8c445f0fe796ebc412d446c7728bfe871946158d104021b0d9ff3306a05aaca0d8f781c7f0dfbe322f6349a4015e060b0b3d1de1f95e42a3fb4e5
7
- data.tar.gz: 12210ee893b5a1603049b2b036397186690a88b7b0bd408865e62898e3212656fb31955f2591b333af7ac3f5a1b25395ca18b573beb68e547b87a48120ab56d2
6
+ metadata.gz: 08464cec95542735521be16501b95f2d0a8d65cdaeb2bb1baa6b172af3f510e9de8847fec80bd57f8d28b6d0828758e50896b0bf5cc033d646503e4238e765fd
7
+ data.tar.gz: 5aca9e965185926b4c12ba062b828df3de172e07503c53393cddeef4abea512800f088b7c37a96b35501c1e80eeb14d54fd976a623f9af4f8f5cb31dac9c9352
data/README.md CHANGED
@@ -29,7 +29,7 @@ create_table "events" do |t|
29
29
  t.string "name"
30
30
  t.boolean "special"
31
31
  t.datetime "expired_at"
32
- t.date "started_on"
32
+ t.date "archived_on"
33
33
  end
34
34
 
35
35
  class Event < ActiveRecord::Base
@@ -57,39 +57,59 @@ Event.expired_after_or_at(2.months.from_now)
57
57
  Event.expired_between(2.months.ago..1.month.from_now)
58
58
  # SELECT * FROM `events` where `events`.`expired_at` BETWEEN '2013-05-05 15:43:42' AND '2013-08-05 15:43:42'
59
59
 
60
- Event.started_before(2.days.ago)
61
- # SELECT * FROM `events` where `events`.`started_on` < '2013-07-03'
60
+ Event.archived_before(2.days.ago)
61
+ # SELECT * FROM `events` where `events`.`archived_on` < '2013-07-03'
62
62
 
63
- Event.started_between(2.days.ago..3.days.from_now)
64
- # SELECT * FROM `events` where `events`.`started_on` BETWEEN '2013-07-03' AND '2013-07-08'
63
+ Event.archived_between(2.days.ago..3.days.from_now)
64
+ # SELECT * FROM `events` where `events`.`archived_on` BETWEEN '2013-07-03' AND '2013-07-08'
65
65
 
66
- Event.started
67
- # SELECT * FROM `events` where `events`.`started_at` IS NOT NULL AND `events`.`started_at` <= '2013-07-05 15:43:42'
66
+ Event.archived
67
+ # SELECT * FROM `events` where `events`.`archived_on` IS NOT NULL AND `events`.`archived_on` <= '2013-07-05 15:43:42'
68
68
 
69
- Event.not_started
70
- # SELECT * FROM `events` where `events`.`started_at` IS NULL OR `events`.`started_at` > '2013-07-05 15:43:42'
69
+ Event.not_archived
70
+ # SELECT * FROM `events` where `events`.`archived_on` IS NULL OR `events`.`archived_on` > '2013-07-05 15:43:42'
71
71
  ```
72
72
 
73
73
  Microscope also adds three instance methods to the model per scope.
74
74
 
75
75
  ```ruby
76
- event = Event.started.first
77
- # SELECT * FROM `events` where `events`.`started_at` IS NOT NULL AND `events`.`started_at` <= '2013-07-05 15:43:42' LIMIT 1
76
+ event = Event.archived.first
77
+ # SELECT * FROM `events` where `events`.`archived_on` IS NOT NULL AND `events`.`archived_on` <= '2013-07-05 15:43:42' LIMIT 1
78
78
 
79
- event.started? # => true
80
- event.not_started? # => false
79
+ event.archived? # => true
80
+ event.not_archived? # => false
81
81
 
82
- event = Event.unstarted.first
83
- event.started? # => false
82
+ event = Event.unarchived.first
83
+ event.archived? # => false
84
84
 
85
- event.start!
86
- event.started? # => true
87
- event.started_at # => 2013-07-05 15:43:44 (Time.now)
85
+ event.archive!
86
+ event.archived? # => true
87
+ event.archived_at # => 2013-07-05 15:43:44 (Time.now)
88
88
  ```
89
89
 
90
90
  ### Options
91
91
 
92
- You can use a few options when calling `acts_as_microscope`:
92
+ #### Special verbs
93
+
94
+ Microscope uses a rather simple process to convert field names to infinitive
95
+ verbs. It just removes the `d` if there’s one at the end of the verb. It also
96
+ has its own irregular verbs list.
97
+
98
+ For example, a `liked_at` field name will give `like!` and `unlike!` instance
99
+ methods to records.
100
+
101
+ But you can configure Microscope to use your own special verbs. For example:
102
+
103
+ ```ruby
104
+ # config/initializers/microscope.rb
105
+ Microscope.configure do |config|
106
+ config.special_verbs = { 'extracted' => 'extract', 'started' => 'start' }
107
+ end
108
+ ```
109
+
110
+ #### On `acts_as_microscope`
111
+
112
+ You can also use a few options when calling `acts_as_microscope`:
93
113
 
94
114
  ```ruby
95
115
  class Event < ActiveRecord::Base
@@ -18,7 +18,6 @@ burnt: burn
18
18
  burst: burst
19
19
  bought: buy
20
20
  caught: catch
21
- canceled: cancel
22
21
  cancelled: cancel
23
22
  chosen: choose
24
23
  clung: cling
@@ -32,17 +31,14 @@ dived: dive
32
31
  done: do
33
32
  drawn: draw
34
33
  dreamt: dream
35
- dreamed: dream
36
34
  drunk: drink
37
35
  driven: drive
38
36
  eaten: eat
39
- extracted: extract
40
37
  fallen: fall
41
38
  fed: feed
42
39
  felt: feel
43
40
  fought: fight
44
41
  found: find
45
- filtered: filter
46
42
  fit: fit
47
43
  fled: flee
48
44
  flung: fling
@@ -125,7 +121,6 @@ spat: spit
125
121
  split: split
126
122
  spread: spread
127
123
  sprung: spring
128
- started: start
129
124
  stood: stand
130
125
  stolen: steal
131
126
  stuck: stick
data/lib/microscope.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "microscope/version"
2
2
 
3
+ require 'ostruct'
3
4
  require 'active_record'
4
5
  require 'active_support'
5
6
 
@@ -16,8 +17,22 @@ require "microscope/instance_method/date_instance_method"
16
17
  module Microscope
17
18
  IRREGULAR_VERBS_FILE = File.expand_path('../../data/irregular_verbs.yml', __FILE__)
18
19
 
19
- def self.irregular_verbs
20
- @irregular_verbs ||= YAML.load_file(IRREGULAR_VERBS_FILE)
20
+ def self.special_verbs
21
+ irregular_verbs_from_yaml ||= YAML.load_file(IRREGULAR_VERBS_FILE)
22
+ special_verbs_from_configuration ||= configuration.special_verbs
23
+
24
+ @special_verbs ||= begin
25
+ irregular_verbs_from_yaml.merge(special_verbs_from_configuration)
26
+ end
27
+ end
28
+
29
+ def self.configure
30
+ @configuration = configuration
31
+ yield(@configuration)
32
+ end
33
+
34
+ def self.configuration
35
+ @configuration ||= OpenStruct.new(special_verbs: {})
21
36
  end
22
37
  end
23
38
 
@@ -24,8 +24,8 @@ module Microscope
24
24
  def self.past_participle_to_infinitive(key)
25
25
  *key, participle = key.split('_')
26
26
 
27
- infinitive = if Microscope.irregular_verbs.include?(participle)
28
- Microscope.irregular_verbs[participle]
27
+ infinitive = if Microscope.special_verbs.include?(participle)
28
+ Microscope.special_verbs[participle]
29
29
  elsif participle =~ /ed$/
30
30
  participle.sub(/d$/, '')
31
31
  else
@@ -1,3 +1,3 @@
1
1
  module Microscope
2
- VERSION = '0.5.10'
2
+ VERSION = '0.6'
3
3
  end
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Microscope::InstanceMethod::DateInstanceMethod do
4
4
  before do
5
+ Microscope.configure do |config|
6
+ config.special_verbs = { 'started' => 'start' }
7
+ end
8
+
5
9
  run_migration do
6
10
  create_table(:events, force: true) do |t|
7
11
  t.date :start_date, default: nil
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Microscope::InstanceMethod::DatetimeInstanceMethod do
4
4
  before do
5
+ Microscope.configure do |config|
6
+ config.special_verbs = { 'started' => 'start' }
7
+ end
8
+
5
9
  run_migration do
6
10
  create_table(:events, force: true) do |t|
7
11
  t.datetime :started_at, default: nil
@@ -3,8 +3,14 @@ require 'spec_helper'
3
3
  describe Microscope::InstanceMethod do
4
4
  describe :ClassMethods do
5
5
  describe :past_participle_to_infinitive do
6
- let(:past_participles) { ['liked', 'loved', 'gateway_canceled', 'started', 'fed'] }
7
- let(:infinitives) { ['like', 'love', 'gateway_cancel', 'start', 'feed'] }
6
+ before do
7
+ Microscope.configure do |config|
8
+ config.special_verbs = { 'started' => 'start', 'foo' => 'bar', 'canceled' => 'cancel' }
9
+ end
10
+ end
11
+
12
+ let(:past_participles) { ['liked', 'loved', 'gateway_canceled', 'started', 'fed', 'foo'] }
13
+ let(:infinitives) { ['like', 'love', 'gateway_cancel', 'start', 'feed', 'bar'] }
8
14
  let(:mapped_past_participles) { past_participles.map { |v| Microscope::InstanceMethod.past_participle_to_infinitive(v) } }
9
15
 
10
16
  specify do
data/spec/spec_helper.rb CHANGED
@@ -19,7 +19,12 @@ RSpec.configure do |config|
19
19
  config.include ModelMacros
20
20
 
21
21
  config.before :each do
22
+ # Establish ActiveRecord database connection
22
23
  adapter = ENV['DB_ADAPTER'] || 'sqlite3'
23
24
  setup_database(adapter: adapter, database: 'microscope_test')
25
+
26
+ # Reset internal variables
27
+ Microscope.instance_variable_set(:@configuration, nil)
28
+ Microscope.instance_variable_set(:@special_verbs, nil)
24
29
  end
25
30
  end
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.10
4
+ version: '0.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-04-21 00:00:00.000000000 Z
12
+ date: 2014-04-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport