cistern 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,18 +6,7 @@ module Cistern::Attributes
6
6
  :integer => lambda{|v,opts| v && v.to_i},
7
7
  :float => lambda{|v,opts| v && v.to_f},
8
8
  :array => lambda{|v,opts| [*v]},
9
- :boolean => Proc.new do |v, opts|
10
- {
11
- true => true,
12
- "true" => true,
13
- "1" => true,
14
- 1 => true,
15
- false => false,
16
- "false" => false,
17
- "0" => false,
18
- 0 => false,
19
- }[v]
20
- end,
9
+ :boolean => lambda{|v,opts| ['true', '1'].include?(v.to_s.downcase)}
21
10
  }
22
11
  end
23
12
 
@@ -76,8 +65,9 @@ module Cistern::Attributes
76
65
  @attributes ||= []
77
66
  @attributes |= [name]
78
67
 
79
- for new_alias in [*options[:aliases]]
80
- aliases[new_alias] = name
68
+ Array(options[:aliases]).each do |new_alias|
69
+ aliases[new_alias] ||= []
70
+ aliases[new_alias] << name
81
71
  end
82
72
  end
83
73
 
@@ -125,8 +115,10 @@ module Cistern::Attributes
125
115
  def merge_attributes(new_attributes = {})
126
116
  for key, value in new_attributes
127
117
  unless self.class.ignored_attributes.include?(key)
128
- if aliased_key = self.class.aliases[key]
129
- send("#{aliased_key}=", value)
118
+ if self.class.aliases.has_key?(key)
119
+ self.class.aliases[key].each do |aliased_key|
120
+ send("#{aliased_key}=", value)
121
+ end
130
122
  elsif self.respond_to?("#{key}=", true)
131
123
  send("#{key}=", value)
132
124
  else
@@ -1,3 +1,3 @@
1
1
  module Cistern
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -31,6 +31,13 @@ describe "Cistern::Model" do
31
31
  attribute :butternut, type: :integer, aliases: "squash", squash: "id"
32
32
  attribute :custom, parser: lambda{|v, opts| "X!#{v}"}
33
33
 
34
+ attribute :same_alias_1, aliases: "nested"
35
+ attribute :same_alias_2, aliases: "nested"
36
+
37
+ attribute :same_alias_squashed_1, aliases: "nested", squash: "attr_1"
38
+ attribute :same_alias_squashed_2, aliases: "nested", squash: "attr_2"
39
+ attribute :same_alias_squashed_3, aliases: "nested", squash: "attr_2"
40
+
34
41
  def save
35
42
  requires :flag
36
43
  end
@@ -76,6 +83,21 @@ describe "Cistern::Model" do
76
83
  TypeSpec.new({"squash" => {"id" => "12"}}).butternut.should == 12
77
84
  end
78
85
 
86
+ context "allowing the same alias for multiple attributes" do
87
+ it "should do so when not squashing" do
88
+ type_spec = TypeSpec.new({"nested" => "bamboo"})
89
+ type_spec.same_alias_1.should == "bamboo"
90
+ type_spec.same_alias_2.should == "bamboo"
91
+ end
92
+
93
+ it "should do so when squashing" do
94
+ type_spec = TypeSpec.new({"nested" => {"attr_1" => "bamboo", "attr_2" => "panda"}})
95
+ type_spec.same_alias_squashed_1.should == "bamboo"
96
+ type_spec.same_alias_squashed_2.should == "panda"
97
+ type_spec.same_alias_squashed_3.should == "panda"
98
+ end
99
+ end
100
+
79
101
  it "should slice out unaccounted for attributes" do
80
102
  TypeSpec.new({"something" => {"id" => "12"}}).attributes.keys.should_not include("something")
81
103
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cistern
3
3
  version: !ruby/object:Gem::Version
4
+ version: 0.3.1
4
5
  prerelease:
5
- version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Josh Lane
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-29 00:00:00.000000000 Z
12
+ date: 2013-09-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: API client framework extracted from Fog
15
15
  email: