simple_hstore_accessor 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NDFjMTc0YjMwMWUwOTVlMWY2MTExZTMwZjNiOWMwYjJhYjBlMmZiZA==
4
+ YmZlZjcxZTE1YTNiNGRjZTA4OTAyZTFkNzlhNTM0YzRmYTljOGU0MA==
5
5
  data.tar.gz: !binary |-
6
- MGE1ZTcxZmFmNzMwOWY3MWU0MGQ3NjBjNzM1NjE1MTBmMTdmZTlkNg==
6
+ MTgwNzNhY2Q3YjAwMDQ4ODViNjg5MzNiM2E0MmViNTZhOGQ1NmYzMQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NDc5YmRlZDVkOWRiZTk2MzUxNDY1NmQ3MmViMzY4M2YyMGVkNTdiMDE3ZGIw
10
- YjljYmM0YTQ3YjEyODhlNzU3YTMwNjQyMmU1NDY3YjUxZDNhYmRhYTRhMWM4
11
- YjA4YWQzZTVhZWE5YmFlNjg1MjY2YzQ4Njg0M2Q3NjFmZmUxZDQ=
9
+ ZDk1ZTJlOWI2NzExMjI2YTFkYmMzNzg2MmMyMGE2YzUwZmJhOTg4NDUxNWU1
10
+ N2E4Nzg1YTZiYmNiZjViMzU2ODFkMTc1YmQ5NmU0NmZkYmZhMjMzODhkOTI5
11
+ ZTFmNDAyYWVlNDAwNDY5M2JiZmYzZGE4OTdjOGYzYjUzNTEyZjA=
12
12
  data.tar.gz: !binary |-
13
- MzIyOGY3MWY0ZmVlMjVmMDZkMzhiNDNmMmMyYzk2YmZjOTNiMGQ4OWJmNTE0
14
- YmFhMTIxYjA4ZjMwNGU2Yzk5ODExODhjYzJkOGViZTNhYzRlY2MxZTM3Y2Nj
15
- YTlkYzVlOTc1OGJiNmZlNTU1ZjBkMjI1NzMyMGI0MjM2MmNlYTI=
13
+ MzVmMWZlZmE4ODlkMzRiY2RhYzA3OTlhOGM2MDg0NWE5YWRiODE4NDM0ODM1
14
+ NDM2MGI0MWYxZDRkOGIyNjVhOTkxMDBkM2I5MDM0ZjNmNDIzNTQ3NGYxM2Jj
15
+ OTY3ZTk0MGMyYTZmOGM4MTc3ZWM4OTI4ZDgwMWMxMDM4NWI0OWQ=
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
+ .idea/
1
2
  *.gem
2
3
  *.rbc
3
4
  .bundle
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ --tty
3
+ --format progress
4
+ --order random
5
+ --backtrace
data/Appraisals ADDED
@@ -0,0 +1,13 @@
1
+ appraise 'rails3.1' do
2
+ gem 'rails', '~> 3.1.0'
3
+ gem 'activerecord-postgres-hstore', '~> 0.6.0'
4
+ end
5
+
6
+ appraise 'rails3.2' do
7
+ gem 'rails', '~> 3.2.0'
8
+ gem 'activerecord-postgres-hstore', '~> 0.6.0'
9
+ end
10
+
11
+ appraise 'rails4.0' do
12
+ gem 'rails', '~> 4.0.0'
13
+ end
data/Makefile ADDED
@@ -0,0 +1,28 @@
1
+ RAILS_ENV = test
2
+ BUNDLE = RAILS_ENV=${RAILS_ENV} bundle
3
+ BUNDLE_OPTIONS = -j 2
4
+ RSPEC = rspec
5
+ APPRAISAL = appraisal
6
+
7
+ all: test
8
+
9
+ test: config/database bundler/install appraisal/install
10
+ ${BUNDLE} exec ${APPRAISAL} ${RSPEC} spec 2>&1
11
+
12
+ config/database:
13
+ touch spec/internal/config/database.yml
14
+ echo 'test:' >> spec/internal/config/database.yml
15
+ echo ' adapter: postgresql' >> spec/internal/config/database.yml
16
+ echo ' database: docker' >> spec/internal/config/database.yml
17
+ echo ' username: docker' >> spec/internal/config/database.yml
18
+ echo ' host: localhost' >> spec/internal/config/database.yml
19
+ echo ' min_messages: warning' >> spec/internal/config/database.yml
20
+
21
+ bundler/install:
22
+ if ! gem list bundler -i > /dev/null; then \
23
+ gem install bundler; \
24
+ fi
25
+ ${BUNDLE} install ${BUNDLE_OPTIONS}
26
+
27
+ appraisal/install:
28
+ ${BUNDLE} exec ${APPRAISAL} install
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # SimpleHstoreAccessor
2
2
 
3
+ [![Dolly](http://dolly.railsc.ru/badges/abak-press/simple_hstore_accessor/master)](http://dolly.railsc.ru/projects/125/builds/latest/?ref=master)
4
+
3
5
  Simple Hstore Accessor allows you to treat fields on an hstore column as though they were actual columns in Rails 3.
4
6
 
5
7
  ## Installation
@@ -36,4 +38,3 @@ end
36
38
  4. Commit your changes (`git commit -am 'Add some feature'`)
37
39
  5. Push to the branch (`git push origin my-new-feature`)
38
40
  6. Create new Pull Request
39
-
@@ -0,0 +1,2 @@
1
+ *.gemfile.lock
2
+ *.gemfile
@@ -1,5 +1,6 @@
1
1
  require 'active_support'
2
2
  require 'active_record'
3
+ require 'activerecord-postgres-hstore'
3
4
  require 'simple_hstore_accessor/version'
4
5
 
5
6
  module SimpleHstoreAccessor
@@ -16,6 +17,8 @@ module SimpleHstoreAccessor
16
17
  #
17
18
  # Returns nothing
18
19
  def store_accessor(hstore_attribute, *keys)
20
+ serialize hstore_attribute, ActiveRecord::Coders::Hstore
21
+
19
22
  Array(keys).flatten.each do |key|
20
23
  define_method("#{key}=") do |value|
21
24
  send("#{hstore_attribute}_will_change!")
@@ -24,6 +27,19 @@ module SimpleHstoreAccessor
24
27
  define_method(key) do
25
28
  send(hstore_attribute) && send(hstore_attribute)[key.to_s]
26
29
  end
30
+ define_method("#{key}_will_change!") { attribute_will_change!(key.to_s) }
31
+ define_method("#{key}_changed?") { attribute_changed?(key.to_s) }
32
+ end
33
+
34
+ define_method("#{hstore_attribute}=") do |new_properties|
35
+ current_properties = send(hstore_attribute) || {}
36
+
37
+ (current_properties.keys | new_properties.keys).each do |key|
38
+ next if current_properties[key].to_s == new_properties[key].to_s || !respond_to?("#{key}_will_change!")
39
+ send("#{key}_will_change!")
40
+ end
41
+
42
+ super(new_properties)
27
43
  end
28
44
  end
29
45
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleHstoreAccessor
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -18,9 +18,16 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'activerecord', '>= 3.1'
22
- spec.add_dependency 'activesupport'
21
+ spec.add_runtime_dependency 'activerecord', '>= 3.1'
22
+ spec.add_runtime_dependency 'activesupport'
23
+ spec.add_runtime_dependency 'activerecord-postgres-hstore', '~> 0.6.0'
23
24
 
24
25
  spec.add_development_dependency 'bundler', '~> 1.3'
25
26
  spec.add_development_dependency 'rake'
27
+
28
+ spec.add_development_dependency 'pg'
29
+ spec.add_development_dependency 'rspec', '>= 2.14.0'
30
+ spec.add_development_dependency 'appraisal', '>= 1.0.2'
31
+ spec.add_development_dependency 'combustion', '>= 0.5.3'
32
+ spec.add_development_dependency 'pry-debugger'
26
33
  end
@@ -0,0 +1,88 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Dummy do
5
+ let(:dummy) { described_class.new(latitude: 7, longitude: 11) }
6
+
7
+ it { expect(dummy).to respond_to(:coordinates) }
8
+
9
+ it { expect(dummy).to respond_to(:latitude) }
10
+ it { expect(dummy).to respond_to(:latitude=) }
11
+ it { expect(dummy).to respond_to(:latitude_will_change!) }
12
+ it { expect(dummy).to respond_to(:latitude_changed?) }
13
+
14
+ it { expect(dummy).to respond_to(:longitude) }
15
+ it { expect(dummy).to respond_to(:longitude=) }
16
+ it { expect(dummy).to respond_to(:longitude_will_change!) }
17
+ it { expect(dummy).to respond_to(:longitude_changed?) }
18
+
19
+ describe '#latitude' do
20
+ it { expect(dummy.latitude).to eq 7 }
21
+ end
22
+
23
+ describe '#longitude' do
24
+ it { expect(dummy.longitude).to eq 11 }
25
+ end
26
+
27
+ describe '#latitude=' do
28
+ it { expect { dummy.latitude = 14 }.to change { dummy.latitude }.from(7).to(14) }
29
+ end
30
+
31
+ describe '#longitude=' do
32
+ it { expect { dummy.longitude = 22 }.to change { dummy.longitude }.from(11).to(22) }
33
+ end
34
+
35
+ describe '#latitude_will_change!' do
36
+ before { dummy.latitude_will_change! }
37
+
38
+ it { expect(dummy).to be_latitude_changed }
39
+ end
40
+
41
+ describe '#longitude_will_change!' do
42
+ before { dummy.longitude_will_change! }
43
+
44
+ it { expect(dummy).to be_longitude_changed }
45
+ end
46
+
47
+ context 'when is new record' do
48
+ describe 'latitude_changed?' do
49
+ it { expect(dummy).to be_latitude_changed }
50
+ end
51
+
52
+ describe 'longitude_changed?' do
53
+ it { expect(dummy).to be_longitude_changed }
54
+ end
55
+ end
56
+
57
+ context 'when record is persisted' do
58
+ let(:dummy) { described_class.create(latitude: 7, longitude: 11) }
59
+
60
+ describe 'latitude_changed?' do
61
+ context 'when latitude is changed' do
62
+ before { dummy.latitude = 7 }
63
+
64
+ it { expect(dummy).not_to be_latitude_changed }
65
+ end
66
+
67
+ context 'when latitude is changed' do
68
+ before { dummy.latitude = 14 }
69
+
70
+ it { expect(dummy).to be_latitude_changed }
71
+ end
72
+ end
73
+
74
+ describe 'longitude_changed?' do
75
+ context 'when longitude is changed' do
76
+ before { dummy.longitude = 11 }
77
+
78
+ it { expect(dummy).not_to be_longitude_changed }
79
+ end
80
+
81
+ context 'when longitude is changed' do
82
+ before { dummy.longitude = 22 }
83
+
84
+ it { expect(dummy).to be_longitude_changed }
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ class Dummy < ActiveRecord::Base
3
+ serialize :coordinates, ActiveRecord::Coders::Hstore if ::ActiveRecord::VERSION::MAJOR < 4
4
+ store_accessor :coordinates, :latitude, :longitude
5
+ end
@@ -0,0 +1 @@
1
+ database.yml
File without changes
@@ -0,0 +1,5 @@
1
+ ActiveRecord::Schema.define do
2
+ create_table(:dummies, :force => true) do |t|
3
+ t.column :coordinates, :hstore
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ *.log
2
+ *.pid
@@ -0,0 +1 @@
1
+ /system/
File without changes
@@ -0,0 +1,6 @@
1
+ # coding: utf-8
2
+ require 'simple_hstore_accessor'
3
+ require 'activerecord-postgres-hstore' if ::ActiveRecord::VERSION::MAJOR < 4
4
+
5
+ require 'combustion'
6
+ Combustion.initialize! :active_record
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_hstore_accessor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey D.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-02 00:00:00.000000000 Z
11
+ date: 2015-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord-postgres-hstore
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,76 @@ dependencies:
66
80
  - - ! '>='
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: 2.14.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: 2.14.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: appraisal
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: 1.0.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: 1.0.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: combustion
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: 0.5.3
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: 0.5.3
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-debugger
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ! '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
69
153
  description: Simple Hstore Accessor extension for Rails 3
70
154
  email:
71
155
  - sclinede@gmail.com
@@ -74,13 +158,26 @@ extensions: []
74
158
  extra_rdoc_files: []
75
159
  files:
76
160
  - .gitignore
161
+ - .rspec
162
+ - Appraisals
77
163
  - Gemfile
78
164
  - LICENSE.txt
165
+ - Makefile
79
166
  - README.md
80
167
  - Rakefile
168
+ - gemfiles/.gitignore
81
169
  - lib/simple_hstore_accessor.rb
82
170
  - lib/simple_hstore_accessor/version.rb
83
171
  - simple_hstore_accessor.gemspec
172
+ - spec/app/models/dummy_spec.rb
173
+ - spec/internal/app/models/dummy.rb
174
+ - spec/internal/config/.gitignore
175
+ - spec/internal/config/environments/test.rb
176
+ - spec/internal/db/schema.rb
177
+ - spec/internal/log/.gitignore
178
+ - spec/internal/public/.gitignore
179
+ - spec/internal/public/favicon.ico
180
+ - spec/spec_helper.rb
84
181
  homepage: https://github.com/abak-press/simple_hstore_accessor
85
182
  licenses:
86
183
  - MIT
@@ -105,4 +202,13 @@ rubygems_version: 2.4.7
105
202
  signing_key:
106
203
  specification_version: 4
107
204
  summary: Simple Hstore Accessor extension for Rails 3
108
- test_files: []
205
+ test_files:
206
+ - spec/app/models/dummy_spec.rb
207
+ - spec/internal/app/models/dummy.rb
208
+ - spec/internal/config/.gitignore
209
+ - spec/internal/config/environments/test.rb
210
+ - spec/internal/db/schema.rb
211
+ - spec/internal/log/.gitignore
212
+ - spec/internal/public/.gitignore
213
+ - spec/internal/public/favicon.ico
214
+ - spec/spec_helper.rb