opium 1.1.7 → 1.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/generators/opium/model_generator.rb +4 -0
- data/lib/opium/extensions/array.rb +1 -1
- data/lib/opium/extensions/boolean.rb +1 -1
- data/lib/opium/extensions/false_class.rb +1 -1
- data/lib/opium/extensions/geo_point.rb +32 -28
- data/lib/opium/extensions/hash.rb +1 -1
- data/lib/opium/extensions/string.rb +1 -2
- data/lib/opium/extensions/true_class.rb +1 -1
- data/lib/opium/version.rb +1 -1
- data/spec/opium/extensions/array_spec.rb +2 -2
- data/spec/opium/extensions/boolean_spec.rb +27 -13
- data/spec/opium/extensions/geo_point_spec.rb +60 -19
- data/spec/opium/extensions/hash_spec.rb +2 -2
- data/spec/opium/extensions/string_spec.rb +3 -3
- data/spec/opium/model_spec.rb +1 -1
- data/spec/opium/user_spec.rb +1 -1
- 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: 13bf8b7b6c86a85e42ef4efd054179cd07ec22d9
|
4
|
+
data.tar.gz: 328524b3e01c8ade53ffa6a2e8d7d306dc3b90f8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a950bcccc7f3d52d077f983701dc15c5e93136fe9682022f79a40953efb1f0f968ee827834983b1d6e75324c49d865e69bdbf8426e388a700da62301b9c2ac82
|
7
|
+
data.tar.gz: 10f6b86273cf753b873a667b31b3f30993682a177fb6ed121b0f1e8aa80156ac8dd07494db380099288c965c09c0ad8bd094806e7bab3bb8640c7489b3b14c45
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
## 1.1.8
|
2
|
+
### Resolved Issues
|
3
|
+
- #41: Boolean and GeoPoint are now namespaced within Opium. The ModelGenerator also maps attribute types for these classes.
|
4
|
+
- #42: GeoPoint now is capable of converting from String in `.to_ruby`
|
5
|
+
|
1
6
|
## 1.1.7
|
2
7
|
### Resolved Issues
|
3
8
|
- #40: `Opium::File.to_ruby` now correctly handles JSON string representation of hashes.
|
@@ -1,37 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
module Opium
|
2
|
+
class GeoPoint
|
3
|
+
def initialize( value )
|
4
|
+
self.latitude, self.longitude = *
|
5
|
+
case value
|
6
|
+
when Hash
|
7
|
+
[value[:latitude] || value['latitude'], value[:longitude] || value['longitude']]
|
8
|
+
when Array
|
9
|
+
[value.first, value.last]
|
10
|
+
when /^[+-]?\d+(\.\d+)?\s*,\s*[+-]?\d+(\.\d+)?$/
|
11
|
+
value.split(',').map {|c| c.to_f}
|
12
|
+
else
|
13
|
+
raise ArgumentError.new( "invalid value for GeoPoint: \"#{ value }\"" )
|
14
|
+
end
|
15
|
+
end
|
13
16
|
|
14
|
-
|
17
|
+
attr_accessor :latitude, :longitude
|
15
18
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
def to_geo_point
|
20
|
+
self
|
21
|
+
end
|
19
22
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
def to_parse
|
24
|
+
{ "__type" => "GeoPoint", "latitude" => self.latitude, "longitude" => self.longitude }
|
25
|
+
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
class << self
|
29
|
-
def to_ruby(object)
|
30
|
-
object.to_geo_point unless object.nil?
|
27
|
+
def to_s
|
28
|
+
"#{ self.latitude },#{ self.longitude }"
|
31
29
|
end
|
30
|
+
|
31
|
+
class << self
|
32
|
+
def to_ruby(object)
|
33
|
+
object.to_geo_point unless object.nil?
|
34
|
+
end
|
32
35
|
|
33
|
-
|
34
|
-
|
36
|
+
def to_parse(object)
|
37
|
+
object.to_geo_point.to_parse
|
38
|
+
end
|
35
39
|
end
|
36
40
|
end
|
37
41
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Hash
|
2
2
|
def to_geo_point
|
3
|
-
return GeoPoint.new(self) if [:latitude, :longitude].all? {|required| self.key? required}
|
3
|
+
return Opium::GeoPoint.new(self) if [:latitude, :longitude].all? {|required| self.key? required}
|
4
4
|
raise ArgumentError.new( "invalid value for GeoPoint: \"#{self}\"" )
|
5
5
|
end
|
6
6
|
|
@@ -6,8 +6,7 @@ class ::String
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def to_geo_point
|
9
|
-
|
10
|
-
raise ArgumentError.new("invalid value for GeoPoint: \"#{self}\"")
|
9
|
+
Opium::GeoPoint.new( self )
|
11
10
|
end
|
12
11
|
|
13
12
|
class << self
|
data/lib/opium/version.rb
CHANGED
@@ -5,7 +5,7 @@ describe Array do
|
|
5
5
|
|
6
6
|
describe 'instance' do
|
7
7
|
describe ':to_parse' do
|
8
|
-
subject { [GeoPoint.new( latitude: 33.33, longitude: -117.117 )] }
|
8
|
+
subject { [Opium::GeoPoint.new( latitude: 33.33, longitude: -117.117 )] }
|
9
9
|
|
10
10
|
it 'should call :to_parse on each element' do
|
11
11
|
subject.to_parse.tap do |result|
|
@@ -18,7 +18,7 @@ describe Array do
|
|
18
18
|
describe 'with two values' do
|
19
19
|
subject { [33.33, -117.117] }
|
20
20
|
|
21
|
-
it { subject.to_geo_point.should be_a_kind_of(GeoPoint) }
|
21
|
+
it { subject.to_geo_point.should be_a_kind_of( Opium::GeoPoint ) }
|
22
22
|
it 'should have the expected latitude and longitude' do
|
23
23
|
subject.to_geo_point.latitude.should == 33.33
|
24
24
|
subject.to_geo_point.longitude.should == -117.117
|
@@ -1,26 +1,40 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Boolean do
|
4
|
-
subject { Boolean }
|
5
|
-
it { should respond_to(:to_ruby).with(1).argument }
|
6
|
-
it { should respond_to(:to_parse).with(1).argument }
|
3
|
+
describe Opium::Boolean do
|
4
|
+
subject { Opium::Boolean }
|
7
5
|
|
8
|
-
it
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
it { is_expected.to respond_to( :to_ruby, :to_parse ).with( 1 ).argument }
|
7
|
+
|
8
|
+
describe '.to_ruby' do
|
9
|
+
let(:result) { subject.to_ruby( convert_from ) }
|
10
|
+
|
11
|
+
context 'with valid boolean objects' do
|
12
|
+
["true", "false", true, false, 1.0, 1, 0.0, 0].each do |value|
|
13
|
+
let(:convert_from) { value }
|
14
|
+
|
15
|
+
it { expect { result }.to_not raise_exception }
|
16
|
+
it { expect( result ).to be_a described_class }
|
17
|
+
it { expect( result ).to eq convert_from.to_bool }
|
18
|
+
end
|
12
19
|
end
|
13
20
|
end
|
14
21
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
22
|
+
describe '.to_parse' do
|
23
|
+
let(:result) { subject.to_parse( convert_from ) }
|
24
|
+
|
25
|
+
context 'with valid boolean objects' do
|
26
|
+
["true", "false", true, false, 1.0, 1, 0.0, 0].each do |value|
|
27
|
+
let(:convert_from) { value }
|
28
|
+
|
29
|
+
it { expect { result }.to_not raise_exception }
|
30
|
+
it { expect( result ).to be_a described_class }
|
31
|
+
it { expect( result ).to eq convert_from.to_bool }
|
32
|
+
end
|
19
33
|
end
|
20
34
|
end
|
21
35
|
|
22
36
|
describe "instance" do
|
23
|
-
subject { Class.new { include Boolean }.new }
|
37
|
+
subject { Class.new { include Opium::Boolean }.new }
|
24
38
|
it { should respond_to(:to_ruby, :to_parse).with(0).arguments }
|
25
39
|
its(:to_ruby) { should == subject }
|
26
40
|
its(:to_parse) { should == subject }
|
@@ -1,35 +1,76 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe GeoPoint do
|
4
|
-
subject {
|
3
|
+
describe Opium::GeoPoint do
|
4
|
+
subject { described_class }
|
5
5
|
|
6
|
-
it {
|
6
|
+
it { is_expected.to respond_to( :to_ruby, :to_parse ).with( 1 ).argument }
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
describe '.to_ruby' do
|
9
|
+
let(:result) { subject.to_ruby( convert_from ) }
|
10
|
+
|
11
|
+
context 'with valid object representations' do
|
12
|
+
[ "33.33, -117.117", {latitude: 33.33, longitude: -117.117}, [33.33, -117.117], described_class.new( [33.33, -117.117] ) ].each do |value|
|
13
|
+
let(:convert_from) { value }
|
14
|
+
it { expect { result }.to_not raise_exception }
|
15
|
+
it { expect( result ).to be_a described_class }
|
16
|
+
it( 'sets the proper latitude' ) { expect( result.latitude ).to eq 33.33 }
|
17
|
+
it( 'sets the proper longitude' ) { expect( result.longitude ).to eq -117.117 }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'with invalid object representations' do
|
22
|
+
[ "malformed", {latitude: 0, bad_key: :unknown}, [0], 1, 1.0, true, false ].each do |value|
|
23
|
+
let(:convert_from) { value }
|
24
|
+
it { expect { subject.to_ruby( value ) }.to raise_exception }
|
25
|
+
end
|
14
26
|
end
|
15
27
|
end
|
16
28
|
|
17
|
-
|
18
|
-
|
19
|
-
|
29
|
+
describe '.to_parse' do
|
30
|
+
let(:result) { subject.to_parse( convert_from ) }
|
31
|
+
let(:expected) { { "__type" => "GeoPoint", "latitude" => 33.33, "longitude" => -117.117 } }
|
32
|
+
|
33
|
+
context 'with valid object representations' do
|
34
|
+
[ "33.33, -117.117", {latitude: 33.33, longitude: -117.117}, [33.33, -117.117], described_class.new( [33.33, -117.117] ) ].each do |value|
|
35
|
+
let(:convert_from) { value }
|
36
|
+
|
37
|
+
it { expect { result }.to_not raise_exception }
|
38
|
+
it { expect( result ).to eq expected }
|
39
|
+
end
|
20
40
|
end
|
21
41
|
end
|
22
42
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
43
|
+
describe '#initialize' do
|
44
|
+
let(:result) { described_class.new( initialize_from ) }
|
45
|
+
|
46
|
+
context 'with an array value' do
|
47
|
+
let(:initialize_from) { [ 33.33, -117.117 ] }
|
48
|
+
|
49
|
+
it { expect { result }.to_not raise_exception }
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with a hash value' do
|
53
|
+
let(:initialize_from) { { latitude: 33.33, longitude: -117.117 } }
|
54
|
+
|
55
|
+
it { expect { result }.to_not raise_exception }
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'with a string value' do
|
59
|
+
let(:initialize_from) { "33.33, -117.117" }
|
60
|
+
|
61
|
+
it { expect { result }.to_not raise_exception }
|
62
|
+
end
|
63
|
+
|
64
|
+
context 'with anything else' do
|
65
|
+
let(:initialize_from) { 42 }
|
66
|
+
|
67
|
+
it { expect { result }.to raise_exception }
|
68
|
+
end
|
28
69
|
end
|
29
70
|
|
30
71
|
describe "instance" do
|
31
72
|
describe "with an array value" do
|
32
|
-
subject {
|
73
|
+
subject { described_class.new [33.33, -117.117] }
|
33
74
|
it { should respond_to(:latitude, :longitude, :to_geo_point, :to_parse).with(0).arguments }
|
34
75
|
it { should respond_to(:latitude=, :longitude=).with(1).argument }
|
35
76
|
|
@@ -41,7 +82,7 @@ describe GeoPoint do
|
|
41
82
|
end
|
42
83
|
|
43
84
|
describe "with a hash value" do
|
44
|
-
subject {
|
85
|
+
subject { described_class.new latitude: 33.33, longitude: -117.117 }
|
45
86
|
it { should respond_to(:latitude, :longitude, :to_geo_point, :to_parse).with(0).arguments }
|
46
87
|
it { should respond_to(:latitude=, :longitude=).with(1).argument }
|
47
88
|
|
@@ -5,7 +5,7 @@ describe Hash do
|
|
5
5
|
|
6
6
|
describe "instance" do
|
7
7
|
describe ":to_parse" do
|
8
|
-
subject { { 'foo' => GeoPoint.new( latitude: 33.33, longitude: -117.117 ) } }
|
8
|
+
subject { { 'foo' => Opium::GeoPoint.new( latitude: 33.33, longitude: -117.117 ) } }
|
9
9
|
|
10
10
|
it 'should return a new hash, with :to_parse called on each value' do
|
11
11
|
subject.to_parse.tap do |result|
|
@@ -18,7 +18,7 @@ describe Hash do
|
|
18
18
|
describe ":to_geo_point" do
|
19
19
|
subject { { latitude: 33.33, longitude: -117.117 } }
|
20
20
|
|
21
|
-
it { subject.to_geo_point.should be_a_kind_of(GeoPoint) }
|
21
|
+
it { subject.to_geo_point.should be_a_kind_of( Opium::GeoPoint ) }
|
22
22
|
it "should have the expected latitude and longitude" do
|
23
23
|
subject.to_geo_point.latitude.should == 33.33
|
24
24
|
subject.to_geo_point.longitude.should == -117.117
|
@@ -35,14 +35,14 @@ describe String do
|
|
35
35
|
|
36
36
|
it "should be able to convert various values to true" do
|
37
37
|
%w[true t yes y 1].each do |value|
|
38
|
-
value.to_bool.should be_a_kind_of( Boolean )
|
38
|
+
value.to_bool.should be_a_kind_of( Opium::Boolean )
|
39
39
|
value.to_bool.should == true
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should be able to convert various values to false" do
|
44
44
|
[""] + %w[false f no n 0].each do |value|
|
45
|
-
value.to_bool.should be_a_kind_of( Boolean )
|
45
|
+
value.to_bool.should be_a_kind_of( Opium::Boolean )
|
46
46
|
value.to_bool.should == false
|
47
47
|
end
|
48
48
|
end
|
@@ -53,7 +53,7 @@ describe String do
|
|
53
53
|
|
54
54
|
it ":to_geo_point should be able to convert a 'lat, lng' value" do
|
55
55
|
result = "33.33, -117.117".to_geo_point
|
56
|
-
result.should be_a_kind_of(GeoPoint)
|
56
|
+
result.should be_a_kind_of( Opium::GeoPoint )
|
57
57
|
result.latitude.should == 33.33
|
58
58
|
result.longitude.should == -117.117
|
59
59
|
end
|
data/spec/opium/model_spec.rb
CHANGED
data/spec/opium/user_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opium
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Bowers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|