cistern 0.11.0 → 0.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Guardfile +1 -1
- data/lib/cistern/attributes.rb +19 -10
- data/lib/cistern/version.rb +1 -1
- data/spec/model_spec.rb +5 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b042d8632a8caf3a3b22b917105d96a08c5a589d
|
4
|
+
data.tar.gz: d83e62f2b43df0cc5d8043065679e41f5372d7a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df23a5684addc4f8c446ec88b9b983e4d288b9bd1a09421478658c93f5fd67e88793f6b16ad7fb3191c69216702ce3b20536af7b3565d3db20b64183d9d34234
|
7
|
+
data.tar.gz: 6cebf42a5df2dfa6602c89d763f5c1d1a07b1b277bb4da34ed5ce682e6d64434815478e7e12a3cee2dc75d7b70ccb4b6cc944b52299e5b158bf01de596e87959
|
data/Guardfile
CHANGED
@@ -4,7 +4,7 @@ guard :bundler do
|
|
4
4
|
watch(/^.+\.gemspec/)
|
5
5
|
end
|
6
6
|
|
7
|
-
guard 'rspec', all_on_start: true, all_after_pass: true, cmd: 'bundle exec rspec' do
|
7
|
+
guard 'rspec', all_on_start: true, all_after_pass: true, cmd: 'bundle exec rspec', failed_mode: :focus do
|
8
8
|
watch(%r{^spec/.+_spec\.rb$})
|
9
9
|
watch(%r{^lib/(.+)\.rb$}) { "spec" }
|
10
10
|
watch('spec/spec_helper.rb') { "spec" }
|
data/lib/cistern/attributes.rb
CHANGED
@@ -12,13 +12,14 @@ module Cistern::Attributes
|
|
12
12
|
|
13
13
|
def self.transforms
|
14
14
|
@transforms ||= {
|
15
|
-
:squash => Proc.new do |k,
|
15
|
+
:squash => Proc.new do |k, _v, options|
|
16
|
+
v = Cistern::Hash.stringify_keys(_v)
|
16
17
|
squash = options[:squash]
|
18
|
+
|
17
19
|
if v.is_a?(::Hash) && squash.is_a?(Array)
|
18
20
|
travel = lambda do |tree, path|
|
19
21
|
if tree.is_a?(::Hash)
|
20
|
-
|
21
|
-
travel.call(subtree, path)
|
22
|
+
travel.call(tree[path.shift], path)
|
22
23
|
else tree
|
23
24
|
end
|
24
25
|
end
|
@@ -49,7 +50,7 @@ module Cistern::Attributes
|
|
49
50
|
end
|
50
51
|
|
51
52
|
def aliases
|
52
|
-
@aliases ||= {}
|
53
|
+
@aliases ||= Hash.new { |h,k| h[k] = [] }
|
53
54
|
end
|
54
55
|
|
55
56
|
def attributes
|
@@ -85,12 +86,16 @@ module Cistern::Attributes
|
|
85
86
|
if self.attributes[name]
|
86
87
|
raise(ArgumentError, "#{self.name} attribute[#{_name}] specified more than once")
|
87
88
|
else
|
89
|
+
if options[:squash]
|
90
|
+
options[:squash] = Array(options[:squash]).map(&:to_s)
|
91
|
+
end
|
88
92
|
self.attributes[name] = options
|
89
93
|
end
|
90
94
|
|
91
|
-
Array(options[:aliases]).
|
92
|
-
|
93
|
-
|
95
|
+
options[:aliases] = Array(options[:aliases]).map { |a| a.to_s.to_sym }
|
96
|
+
|
97
|
+
options[:aliases].each do |new_alias|
|
98
|
+
aliases[new_alias] << name.to_s.to_sym
|
94
99
|
end
|
95
100
|
end
|
96
101
|
|
@@ -168,13 +173,15 @@ module Cistern::Attributes
|
|
168
173
|
end
|
169
174
|
|
170
175
|
def merge_attributes(new_attributes = {})
|
171
|
-
new_attributes.each do |
|
176
|
+
new_attributes.each do |_key, value|
|
177
|
+
key = _key.to_s.to_sym
|
172
178
|
# find nested paths
|
173
179
|
value.is_a?(::Hash) && self.class.attributes.each do |name, options|
|
174
|
-
if (options[:squash] || []).first == key
|
180
|
+
if (options[:squash] || []).first == key.to_s
|
175
181
|
send("#{name}=", {key => value})
|
176
182
|
end
|
177
183
|
end
|
184
|
+
|
178
185
|
unless self.class.ignored_attributes.include?(key)
|
179
186
|
if self.class.aliases.has_key?(key)
|
180
187
|
self.class.aliases[key].each do |aliased_key|
|
@@ -182,7 +189,9 @@ module Cistern::Attributes
|
|
182
189
|
end
|
183
190
|
end
|
184
191
|
|
185
|
-
|
192
|
+
protected_methods = Cistern::Model.instance_methods - [:connection, :identity, :collection]
|
193
|
+
|
194
|
+
if !protected_methods.include?(key) && self.respond_to?("#{key}=", true)
|
186
195
|
send("#{key}=", value)
|
187
196
|
end
|
188
197
|
end
|
data/lib/cistern/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -59,6 +59,7 @@ describe "Cistern::Model" do
|
|
59
59
|
attribute :same_alias_squashed_1, squash: ["nested", "attr_1"]
|
60
60
|
attribute :same_alias_squashed_2, squash: ["nested", "attr_2"]
|
61
61
|
attribute :same_alias_squashed_3, squash: ["nested", "attr_2"]
|
62
|
+
attribute :adam_attributes, aliases: "attributes"
|
62
63
|
|
63
64
|
def save
|
64
65
|
requires :flag
|
@@ -69,6 +70,10 @@ describe "Cistern::Model" do
|
|
69
70
|
expect(TypeSpec.new(name: 1).name).to eq("1")
|
70
71
|
end
|
71
72
|
|
73
|
+
it "should handle a 'attributes' aliased attribute" do
|
74
|
+
expect(TypeSpec.new(attributes: "x").adam_attributes).to eq("x")
|
75
|
+
end
|
76
|
+
|
72
77
|
it "should parse time" do
|
73
78
|
time = Time.now
|
74
79
|
created_at = TypeSpec.new(created_at: time.to_s).created_at
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cistern
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: API client framework extracted from Fog
|
14
14
|
email:
|
@@ -87,3 +87,4 @@ test_files:
|
|
87
87
|
- spec/singular_spec.rb
|
88
88
|
- spec/spec_helper.rb
|
89
89
|
- spec/wait_for_spec.rb
|
90
|
+
has_rdoc:
|