copperegg-revealmetrics 0.7.1 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,94 +0,0 @@
1
- module CopperEgg
2
- class Tag
3
- include CopperEgg::Mixins::Persistence
4
-
5
- resource "tags"
6
-
7
- attr_accessor :name, :objects
8
-
9
- def load_attributes(attributes)
10
- @objects_original = []
11
-
12
- attributes.each do |name, value|
13
- if name.to_s == "id"
14
- @id = value
15
- elsif !respond_to?("#{name}=")
16
- next
17
- elsif name.to_s == "objects"
18
- @objects = value.map { |object| object["idv"].to_s.gsub(/\|$/, "") }
19
- @objects_original = @objects.clone
20
- else
21
- send "#{name}=", value
22
- end
23
- end
24
- end
25
-
26
- def name
27
- @name || @id
28
- end
29
-
30
- def valid?
31
- @error = nil
32
-
33
- if self.name.nil? || self.name.to_s.strip.empty?
34
- @error = "Name can't be blank."
35
- return false
36
- end
37
-
38
- if self.name.to_s.match(/[^\w-]/)
39
- @error = "Name contains invalid characters."
40
- return false
41
- end
42
-
43
- if self.objects.nil? || self.objects.empty?
44
- @error = "You must define at least one object."
45
- return false
46
- end
47
-
48
- unless self.objects.kind_of?(Array)
49
- @error = "Invalid objects field."
50
- return false
51
- end
52
-
53
- if self.objects.any? { |object| !object.kind_of?(String) }
54
- @error = "Invalid object identifier."
55
- return false
56
- end
57
-
58
- true
59
- end
60
-
61
- def delete
62
- self.class.request_200({:id => name, :request_type => "delete"})
63
- end
64
-
65
- def save
66
- unless valid?
67
- raise ValidationError.new(@error)
68
- end
69
-
70
- remove_objects(@objects_original - @objects)
71
- add_objects(@objects - @objects_original)
72
- @objects_original = @objects
73
- end
74
-
75
- def update
76
- save
77
- end
78
-
79
- def to_hash
80
- {"tag" => name, "ids" => objects}
81
- end
82
-
83
- private
84
-
85
- def remove_objects(ids)
86
- self.class.request_200({:id => name, :ids => ids, :request_type => "delete"}) unless ids.empty?
87
- end
88
-
89
- def add_objects(ids)
90
- self.class.request_200({:tag => name, :ids => ids, :request_type => "post"}) unless ids.empty?
91
- end
92
-
93
- end
94
- end
@@ -1,3 +0,0 @@
1
- module CopperEgg
2
- GEM_VERSION = "0.7.1"
3
- end