liner 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 +7 -0
- data/lib/liner.rb +7 -1
- data/lib/liner/base.rb +2 -2
- data/lib/liner/hashable.rb +1 -0
- data/lib/liner/serializable.rb +1 -11
- data/lib/liner/version.rb +1 -1
- data/test/liner/base_test.rb +6 -1
- data/test/liner/inspectable_test.rb +3 -3
- data/test/liner/serializable_test.rb +9 -0
- data/test/liner_test.rb +5 -5
- data/test/test_helper.rb +4 -2
- metadata +13 -20
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1031b1dc95208b1a8692204114af88b6e46ee907
|
4
|
+
data.tar.gz: f4a3cb0860e01d58d748bf0b000ef1e38b8a6290
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0cd932e7fddb88187281890814b89af03ef3c01fc0bcc635fa3f6f2d3614c624776a74f2ef7308c9cee013d004b7df82214f4483931921871af53ba571e9257f
|
7
|
+
data.tar.gz: 7722ba0e233b9ad646ec73be8fe5192c154d3442be4ff2f01138912f1648f96cdbd3004caec1851cc19ba7edabcd0bbe5d52bdbd3e4551528e0c45c8627832c5
|
data/lib/liner.rb
CHANGED
@@ -21,7 +21,13 @@ end
|
|
21
21
|
def Liner.apply(base, *keys)
|
22
22
|
keys = keys.map(&:to_sym).uniq.freeze
|
23
23
|
base.class_eval do
|
24
|
-
define_method
|
24
|
+
define_method :liner_keys do
|
25
|
+
begin
|
26
|
+
(super() + keys).uniq
|
27
|
+
rescue NoMethodError
|
28
|
+
keys
|
29
|
+
end
|
30
|
+
end
|
25
31
|
include Liner
|
26
32
|
keys.each do |key|
|
27
33
|
define_method(key){ self[key] }
|
data/lib/liner/base.rb
CHANGED
@@ -3,9 +3,9 @@ module Liner
|
|
3
3
|
def initialize(*args)
|
4
4
|
if args.count == 1 && args.first.respond_to?(:keys)
|
5
5
|
self.liner = args.first
|
6
|
-
elsif args.count >= 1 && args.count
|
6
|
+
elsif args.count >= 1 && args.count <= liner_keys.count
|
7
7
|
self.liner_values = args
|
8
|
-
|
8
|
+
elsif !args.empty?
|
9
9
|
raise ArgumentError, "Liner doesn't know how to initialize with `#{args}`."
|
10
10
|
end
|
11
11
|
end
|
data/lib/liner/hashable.rb
CHANGED
data/lib/liner/serializable.rb
CHANGED
@@ -1,17 +1,7 @@
|
|
1
1
|
module Liner
|
2
2
|
module Serializable
|
3
|
-
def self.included(base)
|
4
|
-
base.extend(ClassMethods)
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def json_create(o)
|
9
|
-
new o['liner']
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
3
|
def as_json(*)
|
14
|
-
|
4
|
+
to_h
|
15
5
|
end
|
16
6
|
|
17
7
|
def to_json(*args)
|
data/lib/liner/version.rb
CHANGED
data/test/liner/base_test.rb
CHANGED
@@ -6,9 +6,14 @@ describe Liner::Base do
|
|
6
6
|
beer.yeast.must_equal 'Top Fermenting'
|
7
7
|
end
|
8
8
|
it "should accept a list of values" do
|
9
|
-
burger =
|
9
|
+
burger = Cheeseburger.new('Sesame Seed', 'Soy', 'Cheddar')
|
10
10
|
burger.bun.must_equal 'Sesame Seed'
|
11
11
|
burger.cheese.must_equal 'Cheddar'
|
12
12
|
end
|
13
|
+
it "should accept no arguments" do
|
14
|
+
burger = Cheeseburger.new
|
15
|
+
burger.bun.must_equal nil
|
16
|
+
burger.cheese.must_equal nil
|
17
|
+
end
|
13
18
|
end
|
14
19
|
end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
describe Liner::Inspectable do
|
2
|
-
subject {
|
2
|
+
subject { Cheeseburger.new(meat: 'turkey') }
|
3
3
|
it "#inspect must include all attributes" do
|
4
|
-
subject.inspect.must_equal '#<
|
4
|
+
subject.inspect.must_equal '#<Cheeseburger bun=nil, meat="turkey", cheese=nil>'
|
5
5
|
end
|
6
6
|
it "#to_s must include all attributes" do
|
7
|
-
subject.to_s.must_equal '#<
|
7
|
+
subject.to_s.must_equal '#<Cheeseburger bun=nil, meat="turkey", cheese=nil>'
|
8
8
|
end
|
9
9
|
end
|
data/test/liner_test.rb
CHANGED
@@ -2,28 +2,28 @@ describe Liner do
|
|
2
2
|
describe :new do
|
3
3
|
let(:beer) { Beer.new(hops: 'columbus') }
|
4
4
|
let(:pizza) { Pizza.new(crust: 'thin') }
|
5
|
-
let(:
|
5
|
+
let(:cheeseburger){ Cheeseburger.new(bun: 'sesame') }
|
6
6
|
|
7
7
|
it "should create a new class" do
|
8
|
-
[Beer, Pizza, Burger].all?{|klass| klass.is_a? Class }
|
8
|
+
[Beer, Pizza, Burger, Cheeseburger].all?{|klass| klass.is_a? Class }
|
9
9
|
end
|
10
10
|
|
11
11
|
it "should define liner_keys" do
|
12
12
|
beer.liner_keys.must_equal [:hops, :yeast]
|
13
13
|
pizza.liner_keys.must_equal [:crust, :sauce]
|
14
|
-
|
14
|
+
cheeseburger.liner_keys.must_equal [:bun, :meat, :cheese]
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should define attribute getters" do
|
18
18
|
beer.must_respond_to :hops
|
19
19
|
pizza.must_respond_to :sauce
|
20
|
-
|
20
|
+
cheeseburger.must_respond_to :meat
|
21
21
|
end
|
22
22
|
|
23
23
|
it "should define attribute setters" do
|
24
24
|
beer.must_respond_to :yeast=
|
25
25
|
pizza.must_respond_to :crust=
|
26
|
-
|
26
|
+
cheeseburger.must_respond_to :bun=
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,20 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: liner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Josh Lewis
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-02-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
17
|
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
@@ -22,7 +20,6 @@ dependencies:
|
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
24
|
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
@@ -30,33 +27,29 @@ dependencies:
|
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: minitest
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - '>='
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - '>='
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: A liner for Ruby objects. Add attribute, inspection, and equality methods.
|
@@ -84,38 +77,38 @@ files:
|
|
84
77
|
- test/liner/equalizable_test.rb
|
85
78
|
- test/liner/hashable_test.rb
|
86
79
|
- test/liner/inspectable_test.rb
|
80
|
+
- test/liner/serializable_test.rb
|
87
81
|
- test/liner_test.rb
|
88
82
|
- test/test_helper.rb
|
89
83
|
homepage: https://github.com/joshwlewis/liner
|
90
84
|
licenses:
|
91
85
|
- MIT
|
86
|
+
metadata: {}
|
92
87
|
post_install_message:
|
93
88
|
rdoc_options: []
|
94
89
|
require_paths:
|
95
90
|
- lib
|
96
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
92
|
requirements:
|
99
|
-
- -
|
93
|
+
- - '>='
|
100
94
|
- !ruby/object:Gem::Version
|
101
95
|
version: '0'
|
102
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
-
none: false
|
104
97
|
requirements:
|
105
|
-
- -
|
98
|
+
- - '>='
|
106
99
|
- !ruby/object:Gem::Version
|
107
100
|
version: '0'
|
108
101
|
requirements: []
|
109
102
|
rubyforge_project:
|
110
|
-
rubygems_version:
|
103
|
+
rubygems_version: 2.2.1
|
111
104
|
signing_key:
|
112
|
-
specification_version:
|
105
|
+
specification_version: 4
|
113
106
|
summary: A liner for Ruby objects. Add attribute, inspection, and equality methods.
|
114
107
|
test_files:
|
115
108
|
- test/liner/base_test.rb
|
116
109
|
- test/liner/equalizable_test.rb
|
117
110
|
- test/liner/hashable_test.rb
|
118
111
|
- test/liner/inspectable_test.rb
|
112
|
+
- test/liner/serializable_test.rb
|
119
113
|
- test/liner_test.rb
|
120
114
|
- test/test_helper.rb
|
121
|
-
has_rdoc:
|