store_schema 0.0.1 → 0.1.0

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: d13d481527cfe8e42df69d8c0ac8277a09d0b2f7
4
- data.tar.gz: 4bfba69ec1c4ce763a544aa8eb1cdd3ec7aad8eb
3
+ metadata.gz: 5a05dab9a51e83ac7afde53a40dc65dddd2d388d
4
+ data.tar.gz: 9036c033e270aebcd9f08fd56da0b7553db09b67
5
5
  SHA512:
6
- metadata.gz: 870cf0a943b7c6c27c8a11eb961b65ae05033471f76d755391baf1a7e8f88be8bd959c3b7d3a4faa0c3c323ef91119909414e5ef5099d08b8b463d6f5968a0d8
7
- data.tar.gz: b8db099f6f49b350e53aa39483d7200db482b40f3deacab9b1151fff93ed9d5132de10d22e3f0e81122ae90ebe3f4202103851674ad9c9c12954637a0466d859
6
+ metadata.gz: 1c0a5cf4d0bf2a57a75c788aa619317fed9a7d5accedd181d027f6b9011b726d38a8c49389ab1e1a252668defa1c8f08b8a34ee281f21ce92962c5ba3610520c
7
+ data.tar.gz: c764b979e4d63d8ce23898e309200a0671102eba64a8a56255c8e434c6866a87f7dd11ed2d635bef9ae94eb806b323d85898680eed88fc79563292f094122e54
@@ -2,6 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
4
  - 2.1.0
5
+ - 2.2.0
5
6
  - rbx-2.2
6
7
  gemfile:
7
8
  - .gemfiles/4.0.gemfile
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 Michael van Rooijen
1
+ Copyright (c) 2015 Michael van Rooijen
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- # StoreSchema
1
+ # Store Schema
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/store_schema.svg)](http://badge.fury.io/rb/store_schema)
3
4
  [![Code Climate](https://codeclimate.com/github/meskyanichi/store_schema.png)](https://codeclimate.com/github/meskyanichi/store_schema)
4
5
  [![Build Status](https://travis-ci.org/meskyanichi/store_schema.svg)](https://travis-ci.org/meskyanichi/store_schema)
5
6
 
@@ -7,6 +8,8 @@ StoreSchema, for Rails/ActiveRecord 4.0.0+, enhances `ActiveRecord::Base.store_a
7
8
 
8
9
  This library was developed for- and extracted from [HireFire].
9
10
 
11
+ The documentation can be found on [RubyDoc].
12
+
10
13
 
11
14
  ### Compatibility
12
15
 
@@ -17,7 +20,7 @@ This library was developed for- and extracted from [HireFire].
17
20
 
18
21
  ### Installation
19
22
 
20
- Distributed at a gem, hosted at [RubyGems.org].
23
+ Add the gem to your Gemfile and run `bundle`.
21
24
 
22
25
  ```rb
23
26
  gem "store_schema"
@@ -37,10 +40,13 @@ class Website < ActiveRecord::Base
37
40
  # Tell ActiveRecord that we want to serialize the :config attribute
38
41
  # and store the serialized data as text in the config column.
39
42
  #
40
- # If you're using PostreSQL's "hstore" column-type instead of the
41
- # "text" column-type, you don't have to define `serialize :config`.
43
+ # By default, `store` serializes your data as YAML. You can swap this out for
44
+ # any other coder you want. For example JSON or Oj (high performance JSON).
45
+ #
46
+ # If you're using PostgreSQL's hstore or json column-type instead of the
47
+ # text column-type, you should'nt define `store :config`.
42
48
  #
43
- serialize :config
49
+ store :config, coder: JSON
44
50
 
45
51
  # Define a schema for the store. This syntax is similar to
46
52
  # ActiveRecord::Migration.
@@ -100,7 +106,8 @@ See above example.
100
106
  If you need to be able to query these serialized attributes,
101
107
  consider using [PostgreSQL's HStore Extension]. If you do not need to
102
108
  be able to query the serialized data, you can simply use a text-type column
103
- and use the `serialize` method in your model which works with any SQL database.
109
+ and use the `store <column>[, coder: JSON]` method in your model which works
110
+ with any SQL database.
104
111
 
105
112
 
106
113
  ### Contributing
@@ -134,6 +141,12 @@ rspec spec
134
141
  rubycritic lib
135
142
  ```
136
143
 
144
+ To run the local documentation server:
145
+
146
+ ```
147
+ yard server --reload
148
+ ```
149
+
137
150
  Create a new branch and start hacking:
138
151
 
139
152
  ```
@@ -145,13 +158,14 @@ Submit a pull request.
145
158
 
146
159
  ### Author / License
147
160
 
148
- Copyright (c) 2014 Michael van Rooijen ( [@meskyanichi] )<br />
161
+ Copyright (c) 2015 Michael van Rooijen ( [@meskyanichi] )<br />
149
162
  Released under the MIT [License].
150
163
 
151
164
  [@meskyanichi]: https://twitter.com/meskyanichi
152
165
  [HireFire]: http://hirefire.io
153
166
  [Passing Specs]: https://travis-ci.org/meskyanichi/store_schema
154
167
  [Code Climate Score]: https://codeclimate.com/github/meskyanichi/store_schema
168
+ [RubyDoc]: http://rubydoc.info/github/meskyanichi/store_schema/master/frames
155
169
  [License]: https://github.com/meskyanichi/store_schema/blob/master/LICENSE
156
170
  [RubyGems.org]: https://rubygems.org/gems/store_schema
157
171
  [PostgreSQL's HStore Extension]: http://www.postgresql.org/docs/9.3/static/hstore.html
@@ -1,5 +1,4 @@
1
1
  class StoreSchema::AccessorDefiner
2
- class InvalidValueType < StandardError; end
3
2
 
4
3
  # @return [Class]
5
4
  #
@@ -64,25 +63,15 @@ class StoreSchema::AccessorDefiner
64
63
  # Enhances the store setter by adding data conversion capabilities.
65
64
  #
66
65
  def define_setter
67
- _klass = klass
68
- _column = column
69
66
  _type = type
70
- _attribute = attribute
71
67
 
72
68
  klass.send(:define_method, "#{attribute}=") do |value|
73
- if value.is_a?(NilClass)
74
- super(value)
75
- else
76
- converted_value = StoreSchema::Converter
77
- .new(value, _type).to_db
69
+ converted_value = StoreSchema::Converter.new(value, _type).to_db
78
70
 
79
- if converted_value
80
- super(converted_value)
81
- else
82
- raise InvalidValueType,
83
- "#{value} (#{value.class}) for " +
84
- "#{_klass}##{_column}.#{_attribute} (#{_type})"
85
- end
71
+ if converted_value
72
+ super(converted_value)
73
+ else
74
+ super(nil)
86
75
  end
87
76
  end
88
77
  end
@@ -1,4 +1,4 @@
1
- module StoreSchema::Converter::Base
1
+ class StoreSchema::Converter::Base
2
2
 
3
3
  # @return [Object]
4
4
  #
@@ -1,7 +1,6 @@
1
1
  require_relative "base"
2
2
 
3
- class StoreSchema::Converter::Boolean
4
- include StoreSchema::Converter::Base
3
+ class StoreSchema::Converter::Boolean < StoreSchema::Converter::Base
5
4
 
6
5
  # @return [String] the database representation of a true value.
7
6
  #
@@ -1,7 +1,6 @@
1
1
  require_relative "base"
2
2
 
3
- class StoreSchema::Converter::DateTime
4
- include StoreSchema::Converter::Base
3
+ class StoreSchema::Converter::DateTime < StoreSchema::Converter::Base
5
4
 
6
5
  # @return [String] the database format for storing a DateTime object.
7
6
  #
@@ -1,7 +1,6 @@
1
1
  require_relative "base"
2
2
 
3
- class StoreSchema::Converter::Float
4
- include StoreSchema::Converter::Base
3
+ class StoreSchema::Converter::Float < StoreSchema::Converter::Base
5
4
 
6
5
  # Converts the {#value} to a database-storable value.
7
6
  #
@@ -1,7 +1,6 @@
1
1
  require_relative "base"
2
2
 
3
- class StoreSchema::Converter::Integer
4
- include StoreSchema::Converter::Base
3
+ class StoreSchema::Converter::Integer < StoreSchema::Converter::Base
5
4
 
6
5
  # Converts the {#value} to a database-storable value.
7
6
  #
@@ -1,7 +1,6 @@
1
1
  require_relative "base"
2
2
 
3
- class StoreSchema::Converter::String
4
- include StoreSchema::Converter::Base
3
+ class StoreSchema::Converter::String < StoreSchema::Converter::Base
5
4
 
6
5
  # Simply returns {#value} if it's a String.
7
6
  #
@@ -1,3 +1,3 @@
1
1
  module StoreSchema
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -19,12 +19,9 @@ RSpec.describe "StoreSchema" do
19
19
  expect(website.reload.name).to eq("Store Schema")
20
20
  end
21
21
 
22
- it "does not accept invalid data types" do
23
- expect { website.update_attribute(:name, true) }
24
- .to raise_error(
25
- StoreSchema::AccessorDefiner::InvalidValueType,
26
- "true (TrueClass) for Website#config.name (string)"
27
- )
22
+ it "should convert to nil if incompatible type" do
23
+ website.update_attribute(:name, true)
24
+ expect(website.name).to eq(nil)
28
25
  end
29
26
  end
30
27
 
@@ -42,20 +39,14 @@ RSpec.describe "StoreSchema" do
42
39
  expect(website.visitors).to eq(1337)
43
40
  end
44
41
 
45
- it "does not accept invalid string formats" do
46
- expect { website.update_attribute(:visitors, "abc") }
47
- .to raise_error(
48
- StoreSchema::AccessorDefiner::InvalidValueType,
49
- "abc (String) for Website#config.visitors (integer)"
50
- )
42
+ it "should convert to nil if incompatible value" do
43
+ website.update_attribute(:visitors, "abc")
44
+ expect(website.visitors).to eq(nil)
51
45
  end
52
46
 
53
- it "does not accept invalid data types" do
54
- expect { website.update_attribute(:visitors, true) }
55
- .to raise_error(
56
- StoreSchema::AccessorDefiner::InvalidValueType,
57
- "true (TrueClass) for Website#config.visitors (integer)"
58
- )
47
+ it "should convert to nil if incompatible type" do
48
+ website.update_attribute(:visitors, true)
49
+ expect(website.visitors).to eq(nil)
59
50
  end
60
51
  end
61
52
 
@@ -85,20 +76,14 @@ RSpec.describe "StoreSchema" do
85
76
  expect(website.apdex).to eq(1.0)
86
77
  end
87
78
 
88
- it "does not accept invalid string formats" do
89
- expect { website.update_attribute(:apdex, "abc") }
90
- .to raise_error(
91
- StoreSchema::AccessorDefiner::InvalidValueType,
92
- "abc (String) for Website#config.apdex (float)"
93
- )
79
+ it "should convert to nil if incompatible value" do
80
+ website.update_attribute(:apdex, "abc")
81
+ expect(website.apdex).to eq(nil)
94
82
  end
95
83
 
96
- it "does not accept invalid data types" do
97
- expect { website.update_attribute(:apdex, true) }
98
- .to raise_error(
99
- StoreSchema::AccessorDefiner::InvalidValueType,
100
- "true (TrueClass) for Website#config.apdex (float)"
101
- )
84
+ it "should convert to nil if incompatible type" do
85
+ website.update_attribute(:apdex, true)
86
+ expect(website.apdex).to eq(nil)
102
87
  end
103
88
  end
104
89
 
@@ -118,12 +103,9 @@ RSpec.describe "StoreSchema" do
118
103
  end
119
104
  end
120
105
 
121
- it "does not accept invalid data types" do
122
- expect { website.update_attribute(:ssl, "abc") }
123
- .to raise_error(
124
- StoreSchema::AccessorDefiner::InvalidValueType,
125
- "abc (String) for Website#config.ssl (boolean)"
126
- )
106
+ it "should convert to nil if incompatible type" do
107
+ website.update_attribute(:ssl, "abc")
108
+ expect(website.ssl).to eq(nil)
127
109
  end
128
110
  end
129
111
 
@@ -153,20 +135,14 @@ RSpec.describe "StoreSchema" do
153
135
  expect(website.published_at.class).to eq(DateTime)
154
136
  end
155
137
 
156
- it "does not accept invalid string formats" do
157
- expect { website.update_attribute(:published_at, "abc") }
158
- .to raise_error(
159
- StoreSchema::AccessorDefiner::InvalidValueType,
160
- "abc (String) for Website#config.published_at (datetime)"
161
- )
138
+ it "should convert to nil if incompatible value" do
139
+ website.update_attribute(:published_at, "abc")
140
+ expect(website.published_at).to eq(nil)
162
141
  end
163
142
 
164
- it "does not accept invalid data types" do
165
- expect { website.update_attribute(:published_at, true) }
166
- .to raise_error(
167
- StoreSchema::AccessorDefiner::InvalidValueType,
168
- "true (TrueClass) for Website#config.published_at (datetime)"
169
- )
143
+ it "should convert to nil if incompatible type" do
144
+ website.update_attribute(:published_at, true)
145
+ expect(website.published_at).to eq(nil)
170
146
  end
171
147
  end
172
148
  end
@@ -9,13 +9,6 @@ require "store_schema"
9
9
  require File.expand_path("../support/models", __FILE__)
10
10
 
11
11
  RSpec.configure do |config|
12
- config.mock_framework = :mocha
13
-
14
- config.before do
15
- DatabaseCleaner.start
16
- end
17
-
18
- config.after do
19
- DatabaseCleaner.clean
20
- end
12
+ config.before { DatabaseCleaner.start }
13
+ config.after { DatabaseCleaner.clean }
21
14
  end
@@ -1,4 +1,3 @@
1
- ActiveRecord::Base.logger = Logger.new(LOG_PATH)
2
1
  ActiveRecord::Base.establish_connection(
3
2
  adapter: "sqlite3", database: ":memory:"
4
3
  )
@@ -1,14 +1,8 @@
1
- require "fileutils"
2
- require "logger"
3
1
  require "pry"
4
2
  require "sqlite3"
5
3
  require "active_record"
6
4
 
7
5
  ROOT_PATH = File.expand_path("../../..", __FILE__)
8
6
  SPEC_PATH = File.join(ROOT_PATH, "spec")
9
- TMP_PATH = File.join(ROOT_PATH, "tmp")
10
- LOG_PATH = File.join(TMP_PATH, "store_schema.log")
11
-
12
- FileUtils.mkdir_p(TMP_PATH)
13
7
 
14
8
  require "#{SPEC_PATH}/support/db"
@@ -1,6 +1,6 @@
1
1
  class Website < ActiveRecord::Base
2
2
 
3
- serialize :config
3
+ store :config, coder: JSON
4
4
 
5
5
  store_schema :config do |s|
6
6
  s.string :name
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency "bundler"
21
21
  spec.add_development_dependency "rake"
22
22
  spec.add_development_dependency "rspec"
23
- spec.add_development_dependency "mocha"
24
23
  spec.add_development_dependency "sqlite3"
25
24
  spec.add_development_dependency "database_cleaner"
26
25
  spec.add_development_dependency "pry"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-19 00:00:00.000000000 Z
11
+ date: 2015-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: mocha
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: sqlite3
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -179,7 +165,7 @@ files:
179
165
  - lib/store_schema/converter/string.rb
180
166
  - lib/store_schema/module.rb
181
167
  - lib/store_schema/version.rb
182
- - spec/lib/casted_store_accessor_spec.rb
168
+ - spec/lib/store_schema_spec.rb
183
169
  - spec/spec_helper.rb
184
170
  - spec/support/db.rb
185
171
  - spec/support/env.rb
@@ -205,12 +191,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
191
  version: '0'
206
192
  requirements: []
207
193
  rubyforge_project:
208
- rubygems_version: 2.4.1
194
+ rubygems_version: 2.4.5
209
195
  signing_key:
210
196
  specification_version: 4
211
197
  summary: Enhances ActiveRecord::Base.store_accessor with data conversion capabilities.
212
198
  test_files:
213
- - spec/lib/casted_store_accessor_spec.rb
199
+ - spec/lib/store_schema_spec.rb
214
200
  - spec/spec_helper.rb
215
201
  - spec/support/db.rb
216
202
  - spec/support/env.rb