superstore 1.0.4 → 1.0.5
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 +4 -4
- data/lib/superstore/attribute_methods/definition.rb +1 -1
- data/lib/superstore/attribute_methods/typecasting.rb +2 -2
- data/lib/superstore/attribute_methods.rb +1 -1
- data/lib/superstore/persistence.rb +1 -1
- data/lib/superstore/tasks/ks.rake +5 -0
- data/lib/superstore/types/json_type.rb +16 -2
- data/lib/superstore/types/time_type.rb +2 -1
- data/superstore.gemspec +1 -1
- data/test/support/pg.rb +1 -0
- data/test/test_helper.rb +2 -2
- data/test/unit/attribute_methods/dirty_test.rb +14 -0
- data/test/unit/attribute_methods/typecasting_test.rb +3 -3
- data/test/unit/types/json_type_test.rb +5 -1
- data/test/unit/types/time_type_test.rb +4 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7bc1d983f476687ecd39026cc3cd006bd371a53e
|
|
4
|
+
data.tar.gz: 8698caa08eaf6a434caa2b32ef18fc151559ccc6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6f6015ca26eb40b308dd763fb35c508ec6eff5b3e01198c34c0baaad7c655b4a87d7d7979ff319b7a51f5de2bcafbaf92b6721eac328532991c65bac8f00c879
|
|
7
|
+
data.tar.gz: c0dd0e4a5a9e9975184318a223498a77891f7998d2a627bb90e73be4b21ab49653037a9e71a8d5d39615b06c281b581a8930d1196f04c4010a38c2ca7f890526
|
|
@@ -42,9 +42,9 @@ module Superstore
|
|
|
42
42
|
attribute_definitions[name.to_s] = AttributeMethods::Definition.new(name, coder, options)
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
def typecast_attribute(
|
|
45
|
+
def typecast_attribute(name, value)
|
|
46
46
|
if attribute_definition = attribute_definitions[name.to_s]
|
|
47
|
-
attribute_definition.instantiate(
|
|
47
|
+
attribute_definition.instantiate(value)
|
|
48
48
|
else
|
|
49
49
|
raise NoMethodError, "Unknown attribute #{name.inspect}"
|
|
50
50
|
end
|
|
@@ -67,7 +67,7 @@ module Superstore
|
|
|
67
67
|
def typecast_persisted_attributes(object, attributes)
|
|
68
68
|
attributes.each do |key, value|
|
|
69
69
|
if definition = attribute_definitions[key]
|
|
70
|
-
attributes[key] = definition.instantiate(
|
|
70
|
+
attributes[key] = definition.instantiate(value)
|
|
71
71
|
else
|
|
72
72
|
attributes.delete(key)
|
|
73
73
|
end
|
|
@@ -12,6 +12,7 @@ ks_namespace = namespace :ks do
|
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
desc 'Remove the keyspace in config/superstore.yml for the current environment'
|
|
15
16
|
task drop: :environment do
|
|
16
17
|
begin
|
|
17
18
|
Superstore::CassandraSchema.drop_keyspace Superstore::Base.config[:keyspace]
|
|
@@ -24,11 +25,14 @@ ks_namespace = namespace :ks do
|
|
|
24
25
|
end
|
|
25
26
|
end
|
|
26
27
|
|
|
28
|
+
desc 'Alias for ks:drop and ks:setup'
|
|
27
29
|
task reset: [:drop, :setup]
|
|
28
30
|
|
|
31
|
+
desc 'Alias for ks:create and ks:structure:load'
|
|
29
32
|
task setup: [:create, :_load]
|
|
30
33
|
|
|
31
34
|
namespace :structure do
|
|
35
|
+
desc 'Serialize the current structure for the keyspace in config/superstore.yml to the SCHEMA environment variable (defaults to "$RAILS_ROOT/ks/structure.cql")'
|
|
32
36
|
task dump: :environment do
|
|
33
37
|
filename = ENV['SCHEMA'] || "#{Rails.root}/ks/structure.cql"
|
|
34
38
|
File.open(filename, "w:utf-8") do |file|
|
|
@@ -36,6 +40,7 @@ ks_namespace = namespace :ks do
|
|
|
36
40
|
end
|
|
37
41
|
end
|
|
38
42
|
|
|
43
|
+
desc 'Load the structure for the keyspace in config/superstore.yml from the SCHEMA environment variable (defaults to "$RAILS_ROOT/ks/structure.cql")'
|
|
39
44
|
task load: :environment do
|
|
40
45
|
filename = ENV['SCHEMA'] || "#{Rails.root}/ks/structure.cql"
|
|
41
46
|
File.open(filename) do |file|
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
module Superstore
|
|
2
2
|
module Types
|
|
3
3
|
class JsonType < BaseType
|
|
4
|
-
def encode(
|
|
5
|
-
ActiveSupport::JSON.encode(
|
|
4
|
+
def encode(data)
|
|
5
|
+
ActiveSupport::JSON.encode(data)
|
|
6
6
|
end
|
|
7
7
|
|
|
8
8
|
def decode(str)
|
|
9
9
|
ActiveSupport::JSON.decode(str)
|
|
10
10
|
end
|
|
11
|
+
|
|
12
|
+
def typecast(data)
|
|
13
|
+
return data if ActiveSupport.parse_json_times
|
|
14
|
+
|
|
15
|
+
if data.acts_like?(:time) || data.acts_like?(:date)
|
|
16
|
+
data.as_json
|
|
17
|
+
elsif data.is_a?(Array)
|
|
18
|
+
data.map { |d| typecast(d) }
|
|
19
|
+
elsif data.is_a?(Hash)
|
|
20
|
+
data.each_with_object({}) { |(key, value), hash| hash[key] = typecast(value) }
|
|
21
|
+
else
|
|
22
|
+
data
|
|
23
|
+
end
|
|
24
|
+
end
|
|
11
25
|
end
|
|
12
26
|
end
|
|
13
27
|
end
|
|
@@ -2,7 +2,8 @@ module Superstore
|
|
|
2
2
|
module Types
|
|
3
3
|
class TimeType < BaseType
|
|
4
4
|
def encode(time)
|
|
5
|
-
raise ArgumentError.new("#{time.inspect}
|
|
5
|
+
raise ArgumentError.new("#{time.inspect} does not respond to #to_time") unless time.is_a?(Time) || time.respond_to?(:to_time)
|
|
6
|
+
time = time.to_time unless time.is_a?(Time)
|
|
6
7
|
time.utc.xmlschema(6)
|
|
7
8
|
end
|
|
8
9
|
|
data/superstore.gemspec
CHANGED
data/test/support/pg.rb
CHANGED
data/test/test_helper.rb
CHANGED
|
@@ -51,6 +51,20 @@ class Superstore::AttributeMethods::DirtyTest < Superstore::TestCase
|
|
|
51
51
|
assert record.changed?
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
+
test 'typecast json with times' do
|
|
55
|
+
record = temp_object do
|
|
56
|
+
json :stuff
|
|
57
|
+
end.create(stuff: {'time' => Time.new(2004, 12, 24, 6, 42, 21)})
|
|
58
|
+
|
|
59
|
+
record.reload
|
|
60
|
+
|
|
61
|
+
record.stuff = {'time' => Time.new(2004, 12, 24, 6, 42, 21)}
|
|
62
|
+
assert !record.changed?
|
|
63
|
+
|
|
64
|
+
record.stuff = {'time' => Time.new(2004, 12, 24, 6, 42, 22)}
|
|
65
|
+
assert record.changed?
|
|
66
|
+
end
|
|
67
|
+
|
|
54
68
|
test 'unapplied_changes' do
|
|
55
69
|
record = temp_object do
|
|
56
70
|
float :price
|
|
@@ -36,11 +36,11 @@ class Superstore::AttributeMethods::TypecastingTest < Superstore::TestCase
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
test 'typecast_attribute' do
|
|
39
|
-
assert_equal 1, TestIssue.typecast_attribute(
|
|
40
|
-
assert_equal 1, TestIssue.typecast_attribute(
|
|
39
|
+
assert_equal 1, TestIssue.typecast_attribute('price', 1)
|
|
40
|
+
assert_equal 1, TestIssue.typecast_attribute(:price, 1)
|
|
41
41
|
|
|
42
42
|
assert_raise NoMethodError do
|
|
43
|
-
TestIssue.typecast_attribute(
|
|
43
|
+
TestIssue.typecast_attribute('wtf', 1)
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
@@ -19,5 +19,9 @@ class Superstore::Types::JsonTypeTest < Superstore::Types::TestCase
|
|
|
19
19
|
assert_equal(['a', 'b'], coder.decode(['a', 'b'].to_json))
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
test 'typecast' do
|
|
23
|
+
assert_equal({'enabled' => false}, coder.typecast('enabled' => false))
|
|
24
|
+
assert_equal({'born_at' => "2004-12-24T00:00:00Z"}, coder.typecast('born_at' => Time.utc(2004, 12, 24)))
|
|
25
|
+
assert_equal(["2004-12-24T00:00:00Z"], coder.typecast([Time.utc(2004, 12, 24)]))
|
|
26
|
+
end
|
|
23
27
|
end
|
|
@@ -3,6 +3,10 @@ require 'test_helper'
|
|
|
3
3
|
class Superstore::Types::TimeTypeTest < Superstore::Types::TestCase
|
|
4
4
|
test 'encode' do
|
|
5
5
|
assert_equal '2004-12-24T01:02:03.000000Z', coder.encode(Time.utc(2004, 12, 24, 1, 2, 3))
|
|
6
|
+
assert_equal '2004-12-24T01:02:03.000000Z', coder.encode(DateTime.new(2004, 12, 24, 1, 2, 3))
|
|
7
|
+
assert_raise ArgumentError do
|
|
8
|
+
coder.encode 123
|
|
9
|
+
end
|
|
6
10
|
end
|
|
7
11
|
|
|
8
12
|
test 'decode' do
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: superstore
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Michael Koziarski
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2014-
|
|
12
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: activemodel
|