cot 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/Gemfile.lock +50 -28
- data/Rakefile +9 -2
- data/cot.gemspec +13 -12
- data/lib/cot.rb +0 -1
- data/lib/cot/frame.rb +10 -11
- data/lib/cot/rspec/matchers.rb +8 -9
- data/lib/cot/version.rb +1 -1
- data/spec/lib/cot/frame_spec.rb +42 -40
- data/spec/spec_helper.rb +2 -1
- metadata +31 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97cc9be92f280e8658df89c21a99f4696a051cf2
|
4
|
+
data.tar.gz: 072105df4b9c734f20e1834193a37f76fad112e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68a07d3af871d1793999cdafd4cab1ee7c1134ee78d917f85976dade39e77189f4b67d28c75090d0c14abe255f5a714984254426af2ff08dd4241bcc3f5805b9
|
7
|
+
data.tar.gz: a568ee0327301c1cfaf2adcb5352ffd89ff51f264f02ad2aa440c2bf8a75d13f5eca3a34625cf8032ed486d1a9955bcda27544bdd803b796df7dd83185d5fb8c
|
data/.rubocop.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,44 +1,64 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
cot (0.1.
|
4
|
+
cot (0.1.1)
|
5
5
|
activemodel
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activemodel (4.
|
11
|
-
activesupport (= 4.
|
12
|
-
builder (~> 3.1
|
13
|
-
activesupport (4.
|
14
|
-
i18n (~> 0.6, >= 0.6.
|
15
|
-
|
16
|
-
|
10
|
+
activemodel (4.1.4)
|
11
|
+
activesupport (= 4.1.4)
|
12
|
+
builder (~> 3.1)
|
13
|
+
activesupport (4.1.4)
|
14
|
+
i18n (~> 0.6, >= 0.6.9)
|
15
|
+
json (~> 1.7, >= 1.7.7)
|
16
|
+
minitest (~> 5.1)
|
17
17
|
thread_safe (~> 0.1)
|
18
|
-
tzinfo (~>
|
19
|
-
|
20
|
-
builder (3.
|
21
|
-
diff-lcs (1.2.
|
22
|
-
i18n (0.6.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
rspec
|
31
|
-
|
32
|
-
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
ast (2.0.0)
|
20
|
+
builder (3.2.2)
|
21
|
+
diff-lcs (1.2.5)
|
22
|
+
i18n (0.6.11)
|
23
|
+
json (1.8.1)
|
24
|
+
minitest (5.4.0)
|
25
|
+
parser (2.2.0.pre.3)
|
26
|
+
ast (>= 1.1, < 3.0)
|
27
|
+
slop (~> 3.4, >= 3.4.5)
|
28
|
+
powerpack (0.0.9)
|
29
|
+
rainbow (2.0.0)
|
30
|
+
rspec (3.0.0)
|
31
|
+
rspec-core (~> 3.0.0)
|
32
|
+
rspec-expectations (~> 3.0.0)
|
33
|
+
rspec-mocks (~> 3.0.0)
|
34
|
+
rspec-core (3.0.2)
|
35
|
+
rspec-support (~> 3.0.0)
|
36
|
+
rspec-expectations (3.0.2)
|
37
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
38
|
+
rspec-support (~> 3.0.0)
|
39
|
+
rspec-its (1.0.1)
|
40
|
+
rspec-core (>= 2.99.0.beta1)
|
41
|
+
rspec-expectations (>= 2.99.0.beta1)
|
42
|
+
rspec-mocks (3.0.2)
|
43
|
+
rspec-support (~> 3.0.0)
|
44
|
+
rspec-support (3.0.2)
|
45
|
+
rubocop (0.24.1)
|
46
|
+
json (>= 1.7.7, < 2)
|
47
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
48
|
+
powerpack (~> 0.0.6)
|
49
|
+
rainbow (>= 1.99.1, < 3.0)
|
50
|
+
ruby-progressbar (~> 1.4)
|
51
|
+
ruby-progressbar (1.5.1)
|
33
52
|
shoulda (3.5.0)
|
34
53
|
shoulda-context (~> 1.0, >= 1.0.1)
|
35
54
|
shoulda-matchers (>= 1.4.1, < 3.0)
|
36
|
-
shoulda-context (1.1
|
37
|
-
shoulda-matchers (2.
|
55
|
+
shoulda-context (1.2.1)
|
56
|
+
shoulda-matchers (2.6.1)
|
38
57
|
activesupport (>= 3.0.0)
|
39
|
-
|
40
|
-
|
41
|
-
tzinfo (
|
58
|
+
slop (3.5.0)
|
59
|
+
thread_safe (0.3.4)
|
60
|
+
tzinfo (1.2.1)
|
61
|
+
thread_safe (~> 0.1)
|
42
62
|
|
43
63
|
PLATFORMS
|
44
64
|
ruby
|
@@ -47,4 +67,6 @@ DEPENDENCIES
|
|
47
67
|
bundler (>= 1.0.0)
|
48
68
|
cot!
|
49
69
|
rspec
|
70
|
+
rspec-its
|
71
|
+
rubocop
|
50
72
|
shoulda
|
data/Rakefile
CHANGED
@@ -8,6 +8,13 @@ RSpec::Core::RakeTask.new('spec') do |spec|
|
|
8
8
|
spec.rspec_opts = '--tag ~broken'
|
9
9
|
end
|
10
10
|
|
11
|
+
require 'rubocop'
|
12
|
+
if defined? RuboCop
|
13
|
+
desc 'run rubocop'
|
14
|
+
task :rubocop do
|
15
|
+
puts `rubocop`
|
16
|
+
end
|
17
|
+
end
|
11
18
|
|
12
|
-
task :
|
13
|
-
task :
|
19
|
+
task default: [:spec, :rubocop]
|
20
|
+
task test: :spec
|
data/cot.gemspec
CHANGED
@@ -1,25 +1,26 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
3
|
-
require
|
2
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'cot/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'cot'
|
7
7
|
s.version = Cot::VERSION
|
8
8
|
|
9
|
-
s.authors = [
|
9
|
+
s.authors = ['Joseph Henrich']
|
10
10
|
s.email = ['crimsonknave@gmail.com']
|
11
|
-
s.homepage =
|
12
|
-
s.summary =
|
13
|
-
s.description =
|
11
|
+
s.homepage = 'http://github.com/crimsonknave/cot'
|
12
|
+
s.summary = 'Simplifies creating models for rest based resources'
|
13
|
+
s.description = 'Simplifies creating models for rest based resources'
|
14
14
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
16
16
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
-
s.require_paths = [
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
18
|
+
s.require_paths = ['lib']
|
19
19
|
|
20
20
|
s.add_dependency 'activemodel'
|
21
|
-
s.add_development_dependency 'shoulda',
|
22
|
-
s.add_development_dependency 'bundler',
|
23
|
-
s.add_development_dependency 'rspec',
|
21
|
+
s.add_development_dependency 'shoulda', '>= 0'
|
22
|
+
s.add_development_dependency 'bundler', '>= 1.0.0'
|
23
|
+
s.add_development_dependency 'rspec', '>= 0'
|
24
|
+
s.add_development_dependency 'rspec-its', '>= 0'
|
25
|
+
s.add_development_dependency 'rubocop', '>= 0'
|
24
26
|
end
|
25
|
-
|
data/lib/cot.rb
CHANGED
data/lib/cot/frame.rb
CHANGED
@@ -5,18 +5,19 @@ module Cot
|
|
5
5
|
end
|
6
6
|
include ActiveModel::Dirty
|
7
7
|
|
8
|
-
def initialize(payload={})
|
8
|
+
def initialize(payload = {})
|
9
9
|
@data = convert_keys payload
|
10
10
|
end
|
11
11
|
|
12
12
|
def exists?
|
13
|
-
#TODO: Have this key off a defined primary key instead of defaulting to id
|
13
|
+
# TODO: Have this key off a defined primary key instead of defaulting to id
|
14
14
|
id
|
15
15
|
end
|
16
16
|
|
17
17
|
def defined_properties
|
18
18
|
self.class.attr_methods
|
19
19
|
end
|
20
|
+
|
20
21
|
def properties_mapping
|
21
22
|
self.class.mappings
|
22
23
|
end
|
@@ -33,7 +34,7 @@ module Cot
|
|
33
34
|
self.class.inverted_search_mappings ||= search_mappings.invert
|
34
35
|
end
|
35
36
|
|
36
|
-
def self.search_property(name, args={})
|
37
|
+
def self.search_property(name, args = {})
|
37
38
|
@search_mappings ||= {}
|
38
39
|
|
39
40
|
key = args[:from] ? args[:from] : name
|
@@ -43,11 +44,11 @@ module Cot
|
|
43
44
|
# TODO: Create an enum declaration that will automagically map a symbol to
|
44
45
|
# another value (such as an int) so that the user of the library doesn't need
|
45
46
|
# to know what number scheduled status is (for example)
|
46
|
-
def self.enum(
|
47
|
-
|
47
|
+
def self.enum(_name, _args = {})
|
48
|
+
fail 'enum is not yet implemented'
|
48
49
|
end
|
49
50
|
|
50
|
-
def self.property(name, args={})
|
51
|
+
def self.property(name, args = {})
|
51
52
|
@mappings ||= {}
|
52
53
|
@attr_methods ||= []
|
53
54
|
@search_mappings ||= {}
|
@@ -82,12 +83,13 @@ module Cot
|
|
82
83
|
def serializable_hash
|
83
84
|
attrs = {}
|
84
85
|
defined_properties.each do |m|
|
85
|
-
attrs[inverted_properties_mapping.fetch(m,m)] = self[m]
|
86
|
+
attrs[inverted_properties_mapping.fetch(m, m)] = self[m]
|
86
87
|
end
|
87
88
|
attrs
|
88
89
|
end
|
89
90
|
|
90
91
|
private
|
92
|
+
|
91
93
|
def convert_key(key)
|
92
94
|
key = key.to_sym
|
93
95
|
properties_mapping.fetch(key, key).to_sym
|
@@ -96,11 +98,8 @@ module Cot
|
|
96
98
|
def convert_keys(hash)
|
97
99
|
return {} unless hash
|
98
100
|
{}.tap do |ret|
|
99
|
-
hash.each_pair
|
100
|
-
ret[convert_key k] = v
|
101
|
-
end
|
101
|
+
hash.each_pair { |k, v| ret[convert_key k] = v }
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
105
104
|
end
|
106
105
|
end
|
data/lib/cot/rspec/matchers.rb
CHANGED
@@ -12,13 +12,12 @@ RSpec::Matchers.define :set_search_property do |field|
|
|
12
12
|
self
|
13
13
|
end
|
14
14
|
end
|
15
|
+
|
15
16
|
RSpec::Matchers.define :set_property do |field|
|
16
17
|
match do |base|
|
17
18
|
@tests = {}
|
18
19
|
@tests[:attr_methods] = base.attr_methods.include?(field.to_sym)
|
19
|
-
if @from
|
20
|
-
@tests[:mappings] = base.mappings[@from.to_sym] == field
|
21
|
-
end
|
20
|
+
@tests[:mappings] = base.mappings[@from.to_sym] == field if @from
|
22
21
|
if @searchable
|
23
22
|
key = @from ? @from : field
|
24
23
|
@tests[:searchable] = base.search_mappings[field] == key
|
@@ -34,21 +33,21 @@ RSpec::Matchers.define :set_property do |field|
|
|
34
33
|
@from = from
|
35
34
|
self
|
36
35
|
end
|
36
|
+
|
37
37
|
def searchable
|
38
38
|
@searchable = true
|
39
39
|
self
|
40
40
|
end
|
41
41
|
|
42
42
|
description do
|
43
|
-
from_string = @from ? "from #{@from}" :
|
44
|
-
search_string = @searchable ?
|
45
|
-
"
|
43
|
+
from_string = @from ? "from #{@from}" : ''
|
44
|
+
search_string = @searchable ? 'to be searchable' : ''
|
45
|
+
"sets property #{field} #{from_string} #{search_string}"
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
failed = @tests.select{|
|
48
|
+
failure_message do
|
49
|
+
failed = @tests.keys.select { |v| !v }
|
50
50
|
"Expected the property #{field} to be set, but the following attributes weren't set correctly #{failed}"
|
51
51
|
end
|
52
52
|
|
53
53
|
end
|
54
|
-
|
data/lib/cot/version.rb
CHANGED
data/spec/lib/cot/frame_spec.rb
CHANGED
@@ -2,86 +2,88 @@ require 'spec_helper'
|
|
2
2
|
describe Cot::Frame do
|
3
3
|
before :each do
|
4
4
|
class TestObject < Cot::Frame
|
5
|
-
property :foo, :
|
5
|
+
property :foo, from: :bar
|
6
6
|
property :id
|
7
|
-
search_property :john, :
|
7
|
+
search_property :john, from: :crichton
|
8
8
|
end
|
9
|
-
@foo = TestObject.new(:
|
9
|
+
@foo = TestObject.new(bar: 'this will be foo', id: 5)
|
10
10
|
end
|
11
11
|
subject { @foo }
|
12
12
|
its(:to_json) { should be_kind_of String }
|
13
13
|
its(:serializable_hash) { should be_kind_of Hash }
|
14
|
-
|
15
|
-
|
14
|
+
it 'has two keys' do
|
15
|
+
expect(subject.serializable_hash.size).to eq 2
|
16
|
+
end
|
17
|
+
it 'needs more serialziable tests'
|
16
18
|
its(:id) { should eq 5 }
|
17
19
|
its(:foo) { should eq 'this will be foo' }
|
18
20
|
|
19
21
|
context 'exists?' do
|
20
|
-
it '
|
21
|
-
@foo.exists
|
22
|
+
it 'is true if id is present' do
|
23
|
+
expect(@foo.exists?).to be_truthy
|
22
24
|
end
|
23
|
-
it '
|
24
|
-
foo = TestObject.new(:
|
25
|
-
foo.exists
|
25
|
+
it 'is false if id is not present' do
|
26
|
+
foo = TestObject.new(foo: 5)
|
27
|
+
expect(foo.exists?).to be_falsey
|
26
28
|
end
|
27
29
|
end
|
28
30
|
context 'defined_properties' do
|
29
|
-
it '
|
30
|
-
@foo.defined_properties.
|
31
|
+
it 'includes foo' do
|
32
|
+
expect(@foo.defined_properties).to include :foo
|
31
33
|
end
|
32
|
-
it '
|
33
|
-
@foo.defined_properties.
|
34
|
+
it 'is an array' do
|
35
|
+
expect(@foo.defined_properties).to be_kind_of Array
|
34
36
|
end
|
35
37
|
end
|
36
38
|
context 'properties_mapping' do
|
37
|
-
it '
|
38
|
-
@foo.properties_mapping.
|
39
|
-
@foo.properties_mapping[:bar].
|
39
|
+
it 'has bar => foo' do
|
40
|
+
expect(@foo.properties_mapping).to have_key :bar
|
41
|
+
expect(@foo.properties_mapping[:bar]).to eq :foo
|
40
42
|
end
|
41
43
|
end
|
42
44
|
context 'inverted_properties_mapping' do
|
43
|
-
it '
|
44
|
-
@foo.inverted_properties_mapping.
|
45
|
-
@foo.inverted_properties_mapping[:foo].
|
45
|
+
it 'has foo => bar' do
|
46
|
+
expect(@foo.inverted_properties_mapping).to have_key :foo
|
47
|
+
expect(@foo.inverted_properties_mapping[:foo]).to eq :bar
|
46
48
|
end
|
47
49
|
end
|
48
50
|
context 'search_mappings' do
|
49
|
-
it '
|
50
|
-
@foo.search_mappings.
|
51
|
-
@foo.search_mappings[:john].
|
51
|
+
it 'has john => crichton' do
|
52
|
+
expect(@foo.search_mappings).to have_key :john
|
53
|
+
expect(@foo.search_mappings[:john]).to eq :crichton
|
52
54
|
end
|
53
55
|
end
|
54
56
|
context 'inverted_search_mappings' do
|
55
|
-
it '
|
56
|
-
@foo.inverted_search_mappings.
|
57
|
-
@foo.inverted_search_mappings[:crichton].
|
57
|
+
it 'has crichton => john' do
|
58
|
+
expect(@foo.inverted_search_mappings).to have_key :crichton
|
59
|
+
expect(@foo.inverted_search_mappings[:crichton]).to eq :john
|
58
60
|
end
|
59
61
|
end
|
60
62
|
context 'search_property' do
|
61
|
-
it '
|
62
|
-
TestObject.search_mappings.
|
63
|
-
TestObject.search_mappings[:john].
|
63
|
+
it 'adds to search_mappings' do
|
64
|
+
expect(TestObject.search_mappings).to have_key :john
|
65
|
+
expect(TestObject.search_mappings[:john]).to be :crichton
|
64
66
|
end
|
65
67
|
end
|
66
68
|
context 'property' do
|
67
|
-
it '
|
68
|
-
TestObject.mappings.
|
69
|
-
TestObject.mappings[:bar].
|
69
|
+
it 'adds to mappings' do
|
70
|
+
expect(TestObject.mappings).to have_key :bar
|
71
|
+
expect(TestObject.mappings[:bar]).to be :foo
|
70
72
|
end
|
71
|
-
it '
|
73
|
+
it 'creates accessor methods' do
|
72
74
|
foo = TestObject.new
|
73
|
-
foo.
|
74
|
-
foo.
|
75
|
+
expect(foo).to respond_to :foo
|
76
|
+
expect(foo).to respond_to :foo=
|
75
77
|
end
|
76
78
|
|
77
|
-
it '
|
78
|
-
TestObject.attr_methods.
|
79
|
+
it 'adds to attr_methods' do
|
80
|
+
expect(TestObject.attr_methods).to include(:foo)
|
79
81
|
end
|
80
82
|
|
81
|
-
it 'accessor methods
|
83
|
+
it 'accessor methods uses []' do
|
82
84
|
foo = TestObject.new
|
83
|
-
foo.
|
84
|
-
foo.foo.
|
85
|
+
expect(foo).to receive('[]').once.and_return 'this is foo'
|
86
|
+
expect(foo.foo).to eq 'this is foo'
|
85
87
|
end
|
86
88
|
end
|
87
89
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joseph Henrich
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-its
|
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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
69
97
|
description: Simplifies creating models for rest based resources
|
70
98
|
email:
|
71
99
|
- crimsonknave@gmail.com
|
@@ -74,6 +102,7 @@ extensions: []
|
|
74
102
|
extra_rdoc_files: []
|
75
103
|
files:
|
76
104
|
- .gitignore
|
105
|
+
- .rubocop.yml
|
77
106
|
- .ruby-gemset
|
78
107
|
- .ruby-version
|
79
108
|
- Gemfile
|