jaysus 0.1.1 → 0.1.2
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.
- data/VERSION +1 -1
- data/jaysus.gemspec +3 -1
- data/lib/jaysus/base.rb +16 -5
- data/lib/jaysus/local.rb +1 -1
- data/lib/jaysus/remote.rb +3 -3
- data/spec/local_spec.rb +21 -3
- data/spec/remote_spec.rb +12 -3
- data/spec/support/kalipso_site.rb +18 -0
- metadata +5 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/jaysus.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{jaysus}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Paul Campbell"]
|
@@ -42,6 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
"spec/support/debugger.rb",
|
43
43
|
"spec/support/fakeweb.rb",
|
44
44
|
"spec/support/jaysus.rb",
|
45
|
+
"spec/support/kalipso_site.rb",
|
45
46
|
"spec/support/site.rb"
|
46
47
|
]
|
47
48
|
s.homepage = %q{http://github.com/paulca/jaysus}
|
@@ -56,6 +57,7 @@ Gem::Specification.new do |s|
|
|
56
57
|
"spec/support/debugger.rb",
|
57
58
|
"spec/support/fakeweb.rb",
|
58
59
|
"spec/support/jaysus.rb",
|
60
|
+
"spec/support/kalipso_site.rb",
|
59
61
|
"spec/support/site.rb"
|
60
62
|
]
|
61
63
|
|
data/lib/jaysus/base.rb
CHANGED
@@ -55,7 +55,7 @@ module Jaysus
|
|
55
55
|
def self.decode(id, &block)
|
56
56
|
ActiveSupport::JSON.decode(
|
57
57
|
yield
|
58
|
-
)[self.
|
58
|
+
)[self.store_file_dir_name.singularize]
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.model_base
|
@@ -71,9 +71,8 @@ module Jaysus
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def self.model_name
|
74
|
-
parts = super.split('::')
|
75
|
-
|
76
|
-
ActiveModel::Name.new(name_part.constantize)
|
74
|
+
parts = super.reverse.split('::',2).reverse.map { |p| p.reverse }
|
75
|
+
ActiveModel::Name.new(parts.first.constantize)
|
77
76
|
end
|
78
77
|
|
79
78
|
def self.plural_name
|
@@ -95,8 +94,20 @@ module Jaysus
|
|
95
94
|
dir
|
96
95
|
end
|
97
96
|
|
97
|
+
def self.object_name
|
98
|
+
self.model_name.split('::').last
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.plural_object_name
|
102
|
+
self.object_name.underscore.pluralize
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.singular_object_name
|
106
|
+
self.object_name.underscore.singularize
|
107
|
+
end
|
108
|
+
|
98
109
|
def self.store_file_dir_name
|
99
|
-
self.
|
110
|
+
self.plural_object_name
|
100
111
|
end
|
101
112
|
|
102
113
|
def self.method_missing(method, *args)
|
data/lib/jaysus/local.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Jaysus
|
2
2
|
module Local
|
3
|
-
|
4
3
|
def self.store_dir
|
5
4
|
@store_dir ||= Pathname.new('.')
|
6
5
|
end
|
@@ -31,6 +30,7 @@ module Jaysus
|
|
31
30
|
|
32
31
|
module ClassMethods
|
33
32
|
def all
|
33
|
+
# debugger if self.model_name == 'Kalipso::Site'
|
34
34
|
records = []
|
35
35
|
Dir[store_file_dir.join('*')].each do |id|
|
36
36
|
records << find(id)
|
data/lib/jaysus/remote.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Jaysus
|
2
|
-
module Remote
|
2
|
+
module Remote
|
3
3
|
def self.base_url
|
4
4
|
@base_url ||= ''
|
5
5
|
end
|
@@ -47,7 +47,7 @@ module Jaysus
|
|
47
47
|
|
48
48
|
module ClassMethods
|
49
49
|
def model_url
|
50
|
-
"#{Jaysus::Remote.base_url}/#{self.
|
50
|
+
"#{Jaysus::Remote.base_url}/#{self.plural_object_name}"
|
51
51
|
end
|
52
52
|
|
53
53
|
def all
|
@@ -55,7 +55,7 @@ module Jaysus
|
|
55
55
|
ActiveSupport::JSON.decode(RestClient.get(model_url,{
|
56
56
|
'Accept' => 'application/json'
|
57
57
|
})).each do |raw_record|
|
58
|
-
records << new(raw_record[self.
|
58
|
+
records << new(raw_record[self.singular_object_name])
|
59
59
|
end
|
60
60
|
records
|
61
61
|
end
|
data/spec/local_spec.rb
CHANGED
@@ -12,10 +12,28 @@ describe Jaysus::Local do
|
|
12
12
|
describe "finder methods" do
|
13
13
|
before(:each) { FileUtils.cp('spec/fixtures/1', Site::Local.store_file_dir) }
|
14
14
|
|
15
|
+
describe ".store_file_dir_name" do
|
16
|
+
context "normal" do
|
17
|
+
subject { Site::Local }
|
18
|
+
its(:store_file_dir_name) { should == 'sites' }
|
19
|
+
end
|
20
|
+
context "within a module" do
|
21
|
+
subject { Kalipso::Site::Local }
|
22
|
+
its(:store_file_dir_name) { should == 'sites' }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
15
26
|
describe ".all" do
|
16
|
-
|
17
|
-
|
18
|
-
|
27
|
+
context "normal" do
|
28
|
+
subject { Site::Local.all }
|
29
|
+
its(:length) { should == 1}
|
30
|
+
its(:first) { should be_a_kind_of(Site::Local) }
|
31
|
+
end
|
32
|
+
context "within a module" do
|
33
|
+
subject { Kalipso::Site::Local.all }
|
34
|
+
its(:length) { should == 1}
|
35
|
+
its(:first) { should be_a_kind_of(Kalipso::Site::Local) }
|
36
|
+
end
|
19
37
|
end
|
20
38
|
|
21
39
|
describe ".find" do
|
data/spec/remote_spec.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
3
|
describe Jaysus::Remote do
|
4
|
+
|
4
5
|
let(:site) { Site::Remote.new({ :title => "New Site" }) }
|
5
6
|
|
6
7
|
describe ".all" do
|
@@ -12,9 +13,17 @@ describe Jaysus::Remote do
|
|
12
13
|
}
|
13
14
|
).and_return(File.read('spec/fixtures/all.json'))
|
14
15
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
context "normal" do
|
17
|
+
subject { Site::Remote.all.first }
|
18
|
+
it { should_not be_nil }
|
19
|
+
its(:title) { should == "I'm from all" }
|
20
|
+
end
|
21
|
+
|
22
|
+
context "within a module" do
|
23
|
+
subject { Kalipso::Site::Remote.all.first }
|
24
|
+
it { should_not be_nil }
|
25
|
+
its(:title) { should == "I'm from all" }
|
26
|
+
end
|
18
27
|
end
|
19
28
|
|
20
29
|
describe ".find" do
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Kalipso
|
2
|
+
module Site
|
3
|
+
class Base < Jaysus::Base
|
4
|
+
primary_key :id
|
5
|
+
attribute :id
|
6
|
+
attribute :title
|
7
|
+
attribute :user_id
|
8
|
+
end
|
9
|
+
|
10
|
+
class Local < Base
|
11
|
+
include Jaysus::Local
|
12
|
+
end
|
13
|
+
|
14
|
+
class Remote < Base
|
15
|
+
include Jaysus::Remote
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jaysus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Paul Campbell
|
@@ -193,6 +193,7 @@ files:
|
|
193
193
|
- spec/support/debugger.rb
|
194
194
|
- spec/support/fakeweb.rb
|
195
195
|
- spec/support/jaysus.rb
|
196
|
+
- spec/support/kalipso_site.rb
|
196
197
|
- spec/support/site.rb
|
197
198
|
has_rdoc: true
|
198
199
|
homepage: http://github.com/paulca/jaysus
|
@@ -235,4 +236,5 @@ test_files:
|
|
235
236
|
- spec/support/debugger.rb
|
236
237
|
- spec/support/fakeweb.rb
|
237
238
|
- spec/support/jaysus.rb
|
239
|
+
- spec/support/kalipso_site.rb
|
238
240
|
- spec/support/site.rb
|