towsta 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,6 +24,9 @@ module Towsta
24
24
  if @json == " "
25
25
  puts 'Maybe your secret is wrong...'
26
26
  return false
27
+ elsif @json[0] != "{"
28
+ puts "something wrong with the server"
29
+ return false
27
30
  else
28
31
  return true
29
32
  end
@@ -49,11 +52,6 @@ module Towsta
49
52
  end
50
53
  end
51
54
 
52
- def self.update_or_create arg
53
- args = JSON.parse arg
54
- eval(args[:vertical]).update_or_create args[:attributes]
55
- end
56
-
57
55
  def just_do_it
58
56
  return false if @hash == " "
59
57
  begin
@@ -73,6 +71,17 @@ module Towsta
73
71
  true
74
72
  end
75
73
 
74
+ def self.callback json
75
+ json = JSON.parse json, :symbolize_names => true
76
+ if json[:action] == 'create'
77
+ eval(json[:vertical]).new json[:attributes]
78
+ elsif json[:action] == 'update'
79
+ eval(json[:vertical]).update json[:attributes]
80
+ else
81
+ eval(json[:vertical]).destroy json[:attributes][:id]
82
+ end
83
+ end
84
+
76
85
  end
77
86
 
78
87
  end
data/lib/towsta/tree.rb CHANGED
@@ -2,7 +2,7 @@ module Towsta
2
2
 
3
3
  class Tree
4
4
 
5
- attr_accessor :item, :left, :right
5
+ attr_accessor :parent, :item, :left, :right
6
6
 
7
7
  def initialize element
8
8
  @item = element
@@ -14,10 +14,15 @@ module Towsta
14
14
 
15
15
  def add_left tree
16
16
  @left = tree
17
+ @left.parent = self
17
18
  end
18
19
 
19
20
  def add_right tree
20
21
  @right = tree
22
+ @right.parent = self
23
+ end
24
+
25
+ def delete element
21
26
  end
22
27
 
23
28
  def find id
@@ -1,3 +1,3 @@
1
1
  module Towsta
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -40,11 +40,6 @@ module Towsta
40
40
  self.tree ? self.tree.find(id) : nil
41
41
  end
42
42
 
43
- def self.update_or_create args
44
- element = self.find args[:id]
45
- element ? element.update(args) : self.new(args)
46
- end
47
-
48
43
  def initialize args
49
44
  args.each {|k,v| eval "self.#{k}= '#{v}';"}
50
45
  self.class.tree ? self.class.tree.add(self) : self.class.tree=(Tree.new(self))
@@ -55,6 +50,23 @@ module Towsta
55
50
  args.each {|k,v| eval "self.#{k}= '#{v}';"}
56
51
  end
57
52
 
53
+ def self.update args
54
+ self.find(args[:id]).update(args)
55
+ end
56
+
57
+ def destroy
58
+ self.class.all.delete self
59
+ self.class.tree.delete self
60
+ self
61
+ end
62
+
63
+ def self.destroy id
64
+ element = self.find id
65
+ self.all.delete element
66
+ self.tree.delete element
67
+ element
68
+ end
69
+
58
70
  def find_horizontal id
59
71
  Vertical.all.each do |v|
60
72
  horizontal = v.find_by_id id.to_i
data/test.json CHANGED
@@ -1 +1 @@
1
- {"name":"test","structures":[{"name":"Book","slices":{"name":"main","author":"user","review":"formated","id":"integer"}},{"name":"Asdas","slices":{"author":"user","id":"integer","asdads":"main"}},{"name":"Movie","slices":{"name":"main","author":"user","id":"integer","book":"boolean"}},{"name":"Movies","slices":{"name":"main","author":"user","review":"formated","id":"integer","data_de_lancamento":"date","book":"vertical"}}],"verticals":[{"horizontals":[{"name":"Kama Sutra","author":6,"review":"Sex positions book","id":6},{"name":"Shit my dad says","author":6,"review":"lot of shits my dad said","id":7}]},{"horizontals":[]},{"horizontals":[]},{"horizontals":[{"name":"Porn dance","author":6,"review":"aoshdoashd","id":12,"data_de_lancamento":"03/24/2011","book":"6"}]}],"revision":26,"users":[{"nick":"Admin","id":6,"email":"admin@test.com"}]}
1
+ {"name":"test","structures":[{"name":"Book","slices":{"name":"main","author":"user","review":"formated","id":"integer"}},{"name":"Movie","slices":{"name":"main","author":"user","review":"formated","id":"integer","data_de_lancamento":"date","book":"vertical"}}],"verticals":[{"horizontals":[{"name":"Kama Sutra","author":6,"review":"Sex positions book","id":6},{"name":"Shit my dad says","author":6,"review":"lot of shits my dad said","id":7}]},{"horizontals":[{"name":"Porn dance","author":6,"review":"aoshdoashd","id":12,"data_de_lancamento":"03/24/2011","book":"6"}]}],"revision":30,"users":[{"nick":"Admin","id":6,"email":"admin@test.com"}]}
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 2
9
- version: 0.1.2
8
+ - 4
9
+ version: 0.1.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mortaro
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-03-02 00:00:00 -03:00
17
+ date: 2011-03-10 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency