muve 0.0.0 → 0.0.1

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: 8e0a98cfd3af0c5386fdb04db259e42575703b7f
4
- data.tar.gz: 3ec568b3d16b5e165c12689ec26184997a2eb8d1
3
+ metadata.gz: e64ab439f78e810ebff042a097baf5b95eaba0ac
4
+ data.tar.gz: 1911f6965e437dab3fe5630b16e7594a09395738
5
5
  SHA512:
6
- metadata.gz: 98a38f7cb5a064d6791a28bfaf45a7eaca2d102eaa7facb12facbdc9791d61fe6fccdbeba0bcabe31dc44e365951e00972e185e644cbf1d53c4c764fde478aaf
7
- data.tar.gz: 9853c8c1018636279f2dbcee0c4edceb3cbc943d1f68a0b62732adab0f45aaffad50d17324d066eb07d9f42525db03ac9b647f39157b11547408d64f80462605
6
+ metadata.gz: f4f53bcfb178526d45860ff5bc19f1654532dddde18f67677816982031f41b03505237f1271e505bfcbac558329caf814418dc3a0a042d76efa913106a2dbeeb
7
+ data.tar.gz: 9e5efb1a4511f3f008af45abdc9724474e72329a2f312436b07d2d649654688f0fa5abdec664241dd59c08bed80621e6f00cc3ec6d78867bb8a63ef3c6835874
data/lib/muve.rb CHANGED
@@ -1,5 +1,36 @@
1
1
  require "muve/version"
2
2
 
3
+ # = Muve
4
+ # The muve gem provides a abstraction layer for the Muve resources which
5
+ # include:
6
+ # * locations, the places of interest to be travelled to and fro
7
+ # * travellers, the wonderful creatures doing the travelling
8
+ # * movements, the appearances of a traveller at a location
9
+ #
10
+ # Although the gem is named *muve* which is short and sweet, the codename
11
+ # for the project is *Muvement* because is serves as a tool to help with
12
+ # geolocation services.
13
+ #
14
+ # This gem is mostly for internal use and I expect it to be refactored numerous
15
+ # times to improve its usability and implementation.
3
16
  module Muve
17
+ require "muve/errors"
18
+ require "muve/model"
4
19
  require "muve/location"
20
+ require "muve/traveller"
21
+ require "muve/movement"
22
+
23
+ module Model
24
+ def connection
25
+ Model.connection
26
+ end
27
+
28
+ def self.connection
29
+ @@conn ||= Object.new
30
+ end
31
+ end
32
+
33
+ def self.init
34
+ Model.connection
35
+ end
5
36
  end
@@ -0,0 +1,7 @@
1
+ module MuveError
2
+ class MuveError < StandardError
3
+ end
4
+
5
+ class MuveSaveError < MuveError
6
+ end
7
+ end
data/lib/muve/location.rb CHANGED
@@ -1,26 +1,31 @@
1
- class Location
2
- attr_accessor :latitude, :longitude
3
-
4
- alias_method :lat, :latitude
5
- alias_method :lat=, :latitude=
1
+ module Muve
2
+ class Location
3
+ include Model
6
4
 
7
- alias_method :lng, :longitude
8
- alias_method :lng=, :longitude=
9
- alias_method :long, :longitude
10
- alias_method :long=, :longitude=
11
-
12
- def initialize(latitude, longitude, type=:wgs84)
13
- @latitude, @longitude = latitude, longitude
14
- end
15
-
16
- def valid?
17
- return false unless latitude.abs <= 90 && longitude.abs <= 180
18
- end
19
-
20
- def invalid?
21
- !valid?
22
- end
23
-
24
- def random(center, range)
5
+ attr_accessor :latitude, :longitude
6
+
7
+ alias_method :lat, :latitude
8
+ alias_method :lat=, :latitude=
9
+
10
+ alias_method :lng, :longitude
11
+ alias_method :lng=, :longitude=
12
+ alias_method :long, :longitude
13
+ alias_method :long=, :longitude=
14
+
15
+ def initialize(latitude=nil, longitude=nil, type=:wgs84)
16
+ @latitude, @longitude = latitude, longitude
17
+ end
18
+
19
+ def valid?
20
+ return false unless latitude.abs <= 90 && longitude.abs <= 180
21
+ true
22
+ end
23
+
24
+ def invalid?
25
+ !valid?
26
+ end
27
+
28
+ def random(center, range)
29
+ end
25
30
  end
26
31
  end
data/lib/muve/model.rb ADDED
@@ -0,0 +1,40 @@
1
+ module Muve
2
+ module Model
3
+ include MuveError
4
+
5
+ def initialize
6
+ @new_record = true
7
+ end
8
+
9
+ def save!
10
+ create_or_update || raise(MuveSaveError)
11
+ end
12
+
13
+ def save
14
+ create_or_update
15
+ end
16
+
17
+ def create
18
+ end
19
+
20
+ def update
21
+ end
22
+
23
+ def new_record?
24
+ @new_record ||= true
25
+ end
26
+
27
+ def valid?
28
+ false
29
+ end
30
+
31
+ def invalid?
32
+ !valid?
33
+ end
34
+
35
+ private
36
+ def create_or_update
37
+ result = new_record? ? create : update
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,35 @@
1
+ module Muve
2
+ class Movement
3
+ include Model
4
+
5
+ attr_accessor :traveller, :traveller_id, :location, :time
6
+
7
+ def initialize(traveller=nil, location=nil, time=Time.now)
8
+ @traveller, @location, @time = traveller, location, time
9
+ end
10
+
11
+ def valid?
12
+ assocs.each do |assoc|
13
+ return false unless !assoc.nil? && assoc.valid?
14
+ end
15
+ flds.each do |field|
16
+ return false unless time
17
+ end
18
+ true
19
+ end
20
+
21
+ private
22
+ def assocs
23
+ [
24
+ @traveller,
25
+ @location
26
+ ]
27
+ end
28
+
29
+ def flds
30
+ [
31
+ @time
32
+ ]
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ module Muve
2
+ class Traveller
3
+ include Model
4
+
5
+ attr_accessor :id
6
+
7
+ def initialize(id=nil)
8
+ @id = id
9
+ end
10
+
11
+ def valid?
12
+ !id.nil?
13
+ end
14
+ end
15
+ end
data/lib/muve/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Muve
2
- VERSION = "0.0.0"
2
+ VERSION = "0.0.1"
3
3
  end
data/muve.gemspec CHANGED
@@ -22,4 +22,7 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rake"
23
23
  s.add_development_dependency "rspec", "~> 3.0.0"
24
24
  s.add_development_dependency "ffaker"
25
+ s.add_development_dependency "factory_girl", "~> 4.0"
26
+
27
+ s.required_ruby_version = '>= 1.9.2'
25
28
  end
data/spec/factories.rb ADDED
@@ -0,0 +1,16 @@
1
+ FactoryGirl.define do
2
+ factory Muve::Location do
3
+ lat { Faker::Geolocation.lat }
4
+ long { Faker::Geolocation.lng }
5
+ end
6
+
7
+ factory Muve::Traveller do
8
+ id { SecureRandom.uuid }
9
+ end
10
+
11
+ factory Muve::Movement do
12
+ traveller { build(Muve::Traveller) }
13
+ #traveller_id { SecureRandom.uuid }
14
+ location { build(Muve::Location) }
15
+ end
16
+ end
@@ -1,27 +1,27 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'Location' do
3
+ describe Muve::Location do
4
4
  before do
5
5
  @lat, @lng = Faker::Geolocation.lat, Faker::Geolocation.lng
6
6
  end
7
7
 
8
8
  it 'knows its latitude and longitude' do
9
- expect(Location.new(@lat, @lng).latitude).to eq(@lat)
10
- expect(Location.new(@lat, @lng).longitude).to eq(@lng)
9
+ expect(Muve::Location.new(@lat, @lng).latitude).to eq(@lat)
10
+ expect(Muve::Location.new(@lat, @lng).longitude).to eq(@lng)
11
11
  end
12
12
 
13
13
  it 'gets the longitude through its aliases' do
14
- location = Location.new(@lat, @lng)
14
+ location = Muve::Location.new(@lat, @lng)
15
15
  expect(location.lng).to eq(@lng)
16
16
  end
17
17
 
18
18
  it 'gets the latitude through aliases' do
19
- location = Location.new(@lat, @lng)
19
+ location = Muve::Location.new(@lat, @lng)
20
20
  expect(location.lat).to eq(@lat)
21
21
  end
22
22
 
23
23
  it 'sets the longitude through its aliases' do
24
- location = Location.new(@lat, @lng)
24
+ location = Muve::Location.new(@lat, @lng)
25
25
 
26
26
  longitude = Faker::Geolocation.lng
27
27
  location.lng = longitude
@@ -33,19 +33,19 @@ describe 'Location' do
33
33
  end
34
34
 
35
35
  it 'sets the latitude through its aliases' do
36
- location = Location.new(@lat, @lng)
36
+ location = Muve::Location.new(@lat, @lng)
37
37
  latitude = Faker::Geolocation.lat
38
38
  location.lat = latitude
39
39
  expect(location.latitude).to eq(latitude)
40
40
  end
41
41
 
42
42
  it 'is invalid when latitude exceeds bounds' do
43
- expect(Location.new(-181, @lng)).to be_invalid
44
- expect(Location.new( 181, @lng)).to be_invalid
43
+ expect(Muve::Location.new(-91, @lng)).to be_invalid
44
+ expect(Muve::Location.new( 91, @lng)).to be_invalid
45
45
  end
46
46
 
47
47
  it 'is invalid when longitude exceeds bounds' do
48
- expect(Location.new(@lat, -91)).to be_invalid
49
- expect(Location.new(@lat, 90)).to be_invalid
48
+ expect(Muve::Location.new(@lat, -181)).to be_invalid
49
+ expect(Muve::Location.new(@lat, 181)).to be_invalid
50
50
  end
51
51
  end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Muve::Movement do
4
+ it 'knows a location and a traveller and possibly a time' do
5
+ expect(Muve::Movement.new).to respond_to(:traveller)
6
+ expect(Muve::Movement.new).to respond_to(:location)
7
+ expect(Muve::Movement.new).to respond_to(:time)
8
+ end
9
+
10
+ it 'is invalid without a traveller' do
11
+ expect(build(Muve::Movement, traveller: nil)).to be_invalid
12
+ end
13
+
14
+ it 'is invalid without a location' do
15
+ expect(build(Muve::Movement, location: nil)).to be_invalid
16
+ end
17
+
18
+ it 'assumes the current time unless specified' do
19
+ expect(build(Muve::Movement).time).to be_within(2).of(Time.now)
20
+ end
21
+
22
+ it 'accepts keeps the specified' do
23
+ last_time = Time.now - rand(500000)
24
+ expect(build(Muve::Movement, time: last_time).time).to eq(last_time)
25
+ end
26
+
27
+ it 'is valid with a traveller and location' do
28
+ expect(build(Muve::Movement)).to be_valid
29
+ end
30
+
31
+ it 'knows a connection' do
32
+ expect(Muve::Movement.new).to respond_to(:connection)
33
+ end
34
+
35
+ it 'shares the connection among all instances' do
36
+ Muve.init
37
+
38
+ connection = Muve::Model.connection
39
+ expect(connection).not_to eq(nil)
40
+
41
+ expect(Muve::Movement.new.connection).to be(connection)
42
+ expect(Muve::Location.new.connection).to be(connection)
43
+ expect(Muve::Traveller.new.connection).to be(connection)
44
+ end
45
+ end
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ Bundler.setup
4
4
  require 'muve'
5
5
 
6
6
  require 'ffaker'
7
+ require 'factory_girl'
7
8
 
8
9
  # This file was generated by the `rspec --init` command. Conventionally, all
9
10
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -22,6 +23,11 @@ require 'ffaker'
22
23
  #
23
24
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
24
25
  RSpec.configure do |config|
26
+ config.include FactoryGirl::Syntax::Methods
27
+
28
+ config.before(:suite) do
29
+ require 'factories.rb'
30
+ end
25
31
  # The settings below are suggested to provide a good initial experience
26
32
  # with RSpec, but feel free to customize to your heart's content.
27
33
  =begin
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Muve::Traveller do
4
+ it 'has an id' do
5
+ expect(Muve::Traveller.new).to respond_to(:id)
6
+ end
7
+
8
+ it 'is invalid without an id' do
9
+ expect(Muve::Traveller.new).to be_invalid
10
+ expect(Muve::Traveller.new(SecureRandom.uuid)).to be_valid
11
+ end
12
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: muve
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Asabina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: factory_girl
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.0'
69
83
  description: Basic helpers to be used with Muvement
70
84
  email:
71
85
  - david@supr.nu
@@ -78,11 +92,18 @@ files:
78
92
  - LICENSE.txt
79
93
  - Rakefile
80
94
  - lib/muve.rb
95
+ - lib/muve/errors.rb
81
96
  - lib/muve/location.rb
97
+ - lib/muve/model.rb
98
+ - lib/muve/movement.rb
99
+ - lib/muve/traveller.rb
82
100
  - lib/muve/version.rb
83
101
  - muve.gemspec
102
+ - spec/factories.rb
84
103
  - spec/location_spec.rb
104
+ - spec/movement_spec.rb
85
105
  - spec/spec_helper.rb
106
+ - spec/traveller_spec.rb
86
107
  homepage: ''
87
108
  licenses:
88
109
  - MIT
@@ -95,7 +116,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
95
116
  requirements:
96
117
  - - ">="
97
118
  - !ruby/object:Gem::Version
98
- version: '0'
119
+ version: 1.9.2
99
120
  required_rubygems_version: !ruby/object:Gem::Requirement
100
121
  requirements:
101
122
  - - ">="
@@ -108,5 +129,8 @@ signing_key:
108
129
  specification_version: 4
109
130
  summary: muve gem
110
131
  test_files:
132
+ - spec/factories.rb
111
133
  - spec/location_spec.rb
134
+ - spec/movement_spec.rb
112
135
  - spec/spec_helper.rb
136
+ - spec/traveller_spec.rb