towsta 1.1.7 → 1.2.0

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.
data/bin/towsta CHANGED
@@ -37,6 +37,7 @@ if action == 'new'
37
37
  index = '%h1 Hello Towsta'
38
38
  File.open("#{project}/views/index.haml", 'w') {|f| f.write(index)}
39
39
  Dir.mkdir "#{project}/models"
40
+ Dir.mkdir "#{project}/controllers"
40
41
  Dir.mkdir "#{project}/public"
41
42
  Dir.mkdir "#{project}/views/stylesheets"
42
43
  css = "@import compass/reset\n"
@@ -51,7 +52,7 @@ if action == 'new'
51
52
  File.open("#{project}/views/stylesheets/#{project}.sass", 'w') {|f| f.write(css)}
52
53
  Dir.mkdir "#{project}/views/partials"
53
54
  head = "%title #{project}\n"
54
- head += "%meta{'http-equiv': 'Content-Type', content: 'text/html', charset: 'utf-8'}\n"
55
+ head += "%meta{:'http-equiv' => 'Content-Type', :content => 'text/html', :charset => 'utf-8'}\n"
55
56
  head += "%link{rel: 'stylesheet', type: 'text/css', href: '/stylesheets/#{project}.css'}\n"
56
57
  head += "%link{rel: 'shortcut icon', type: 'image/x-icon', href: '/images/favicon.png'}\n"
57
58
  head += "%script{src: '/js/jquery.js'}\n"
@@ -0,0 +1,18 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class BooleanKind < MainKind
5
+
6
+ def set content
7
+ @content = content == '1'
8
+ end
9
+
10
+ def export
11
+ return '1' if @content.class == TrueClass
12
+ '0'
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class DateKind < MainKind
5
+
6
+ def set content
7
+ return @content = content if content.class == DateTime
8
+ begin
9
+ @content = DateTime.strptime(content, '%m/%d/%Y')
10
+ rescue
11
+ @content = nil
12
+ end
13
+ end
14
+
15
+ def export
16
+ return @content.strftime('%m/%d/%Y') if content.class == DateTime
17
+ @content.to_s
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,23 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class DatetimeKind < MainKind
5
+
6
+ def set content
7
+ return @content = content if content.class == Time
8
+ begin
9
+ @content = DateTime.strptime(content, '%m/%d/%Y %H:%M').to_time
10
+ rescue
11
+ @content = nil
12
+ end
13
+ end
14
+
15
+ def export
16
+ return @content.strftime('%m/%d/%Y %H:%M') if @content.class == Time
17
+ @content.to_s
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class FileKind < MainKind
5
+
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class FormatedKind < MainKind
5
+
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class GalleryKind < MainKind
5
+
6
+ def set content
7
+ return @content = content if content.class == Array
8
+ begin
9
+ gal = JSON.parse(content, :symbolize_names => true)
10
+ @content = []
11
+ gal.each {|g| @content << Bresson::ImageReference.new(g)}
12
+ rescue
13
+ @content = []
14
+ end
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,17 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class ImageKind < MainKind
5
+
6
+ def set content
7
+ begin
8
+ @content = Bresson::ImageReference.new JSON.parse(content[1..-2], :symbolize_names => true)
9
+ rescue
10
+ @content = nil
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class IntegerKind < MainKind
5
+
6
+ def set content
7
+ @content = content.to_i
8
+ end
9
+
10
+ def compare object
11
+ self.get == object.to_i
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class LinkKind < MainKind
5
+
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,23 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class ListKind < MainKind
5
+
6
+ def set content
7
+ return @content = content.join(', ').split(', ') if content.class == Array
8
+ @content = content.to_s.split(', ')
9
+ end
10
+
11
+ def compare object
12
+ return @content.include? object if object.class == String
13
+ @content == object
14
+ end
15
+
16
+ def export
17
+ @content.join(', ')
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,35 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class MainKind
5
+
6
+ attr_accessor :content
7
+
8
+ def initialize content=nil
9
+ self.set content
10
+ end
11
+
12
+ def get
13
+ @content
14
+ end
15
+
16
+ def set content
17
+ @content = content.to_s
18
+ end
19
+
20
+ def compare object
21
+ self.get == object
22
+ end
23
+
24
+ def export
25
+ @content.to_s
26
+ end
27
+
28
+ def kind
29
+ self.class.to_s.split('::').last.gsub('Kind','').downcase
30
+ end
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,17 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class MoneyKind < MainKind
5
+
6
+ def set content
7
+ @content = content.to_f
8
+ end
9
+
10
+ def compare object
11
+ @content == object.to_f
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class PasswordKind < MainKind
5
+
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class TextKind < MainKind
5
+
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class UserKind < MainKind
5
+
6
+ def get
7
+ return @content if @content.class == User
8
+ user = User.find @content
9
+ @content = user if user
10
+ @content
11
+ end
12
+
13
+ def set content
14
+ return @content = content if content.class == User
15
+ return @content = content.to_i if content.to_i != 0
16
+ @content = nil
17
+ end
18
+
19
+ def compare object
20
+ return self.get.id.to_i == object.id.to_i if object.class == User
21
+ self.get.id.to_i == object.to_i
22
+ end
23
+
24
+ def export
25
+ return @content.id.to_s if @content.class == User
26
+ @content.to_s
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ module Towsta
2
+ module Kinds
3
+
4
+ class VerticalKind < MainKind
5
+
6
+ def get
7
+ return @content if @content.class != Fixnum
8
+ Vertical.all.each do |v|
9
+ horizontal = v.find_by_id @content
10
+ if horizontal
11
+ @content = horizontal
12
+ return horizontal
13
+ end
14
+ end
15
+ nil
16
+ end
17
+
18
+ def set content
19
+ return @content = content if klasses.include? content.class
20
+ @content = content.to_i
21
+ end
22
+
23
+ def compare object
24
+ self.get.id.to_i == object.id.to_i if klasses.include? object.class
25
+ self.get == object
26
+ end
27
+
28
+ def export
29
+ return @content.id.to_s if klasses.include? @content.class
30
+ @content.to_s
31
+ end
32
+
33
+ private
34
+
35
+ def klasses
36
+ Vertical.all + [User]
37
+ end
38
+
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,19 @@
1
+ module Towsta
2
+
3
+ class Login
4
+
5
+ def self.authenticate params
6
+ response = Towsta::Synchronizer.authentication_request params
7
+ session[:current_user] = response[:id] if response[:status]
8
+ response[:status]
9
+ end
10
+
11
+ def self.rescue
12
+ return User.find(session[:current_user]) if defined? User
13
+ session[:current_user]
14
+ end
15
+
16
+
17
+ end
18
+
19
+ end
data/lib/towsta/memory.rb CHANGED
@@ -7,12 +7,12 @@ module Towsta
7
7
  def self.recover params
8
8
  md5 = Memory.md5(params)
9
9
  if settings.cache.get(md5)
10
- puts 'Using cache to Towst'
11
- Towsta::Synchronizer.new :path => $towsta_path, :cache => settings.cache.get(md5)
10
+ puts "\nUsing cache to Towst"
11
+ Towsta::Synchronizer.new :path => $towsta_path, :cache => settings.cache.get(md5), :secret => $towsta_secret
12
12
  else
13
- puts 'Creating cache'
13
+ puts "\nCreating cache"
14
14
  syn = Towsta::Synchronizer.new :secret => $towsta_secret, :path => $towsta_path, :params => params
15
- settings.cache.set(md5,syn.json)
15
+ settings.cache.set(md5,syn.response)
16
16
  end
17
17
  end
18
18
 
@@ -21,7 +21,7 @@ module Towsta
21
21
  end
22
22
 
23
23
  def self.md5 params
24
- digest = Digest::MD5.hexdigest(params.inspect.to_s)
24
+ digest = Digest::MD5.hexdigest(params.inspect.to_s + 'Towsta')
25
25
  end
26
26
 
27
27
  end
@@ -1,7 +1,26 @@
1
+ enable :sessions
2
+
1
3
  helpers do
4
+
2
5
  def partial page
3
6
  haml "partials/_#{page}".to_sym
4
7
  end
8
+
9
+ def authenticate args
10
+ response = Towsta::Synchronizer.authentication_request args
11
+ session[:current_user] = response[:id] if response[:status]
12
+ response[:status]
13
+ end
14
+
15
+ def current_user
16
+ return User.find(session[:current_user]) if defined? User
17
+ session[:current_user]
18
+ end
19
+
20
+ def forget
21
+ session[:current_user] = nil
22
+ end
23
+
5
24
  end
6
25
 
7
26
  post '/flush' do
@@ -1,105 +1,111 @@
1
1
  module Towsta
2
2
  class Synchronizer
3
3
 
4
- attr_accessor :secret, :path, :json, :params, :cache
4
+ attr_accessor :secret, :params, :cache, :response
5
5
 
6
6
  def initialize args
7
7
  Vertical.all = []
8
8
  @secret = args[:secret]
9
- @path = "#{args[:path]}.json"
10
9
  @params = args[:params]
11
10
  @cache = args[:cache]
12
- synchronize ? backup : find_old
13
- puts just_do_it ? 'Ready to Towst!' : 'Unable to keep Towsting!'
11
+ if synchronize
12
+ create_verticals
13
+ puts " Ready to Towst!\n\n"
14
+ else
15
+ puts " Unable to keep Towsting!\n\n"
16
+ end
14
17
  end
15
18
 
19
+ def self.save_request export
20
+ begin
21
+ uri = URI.parse("http://manager.towsta.com/synchronizers/#{$towsta_secret}/import.json")
22
+ return JSON.parse Net::HTTP.post_form(uri, {:code => export.to_json}).body.to_s, :symbolize_names => true
23
+ rescue
24
+ return {:status => false}
25
+ end
26
+ end
27
+
28
+ def self.authentication_request params
29
+ begin
30
+ uri = URI.parse("http://manager.towsta.com/authenticate")
31
+ return JSON.parse Net::HTTP.post_form(uri, params).body.to_s, :symbolize_names => true
32
+ rescue
33
+ return {:status => false}
34
+ end
35
+ end
36
+
37
+ private
38
+
16
39
  def synchronize
17
- unless @cache.nil?
18
- @json = @cache
40
+ if has_secret && (cache_string || remote_string)
41
+ return false unless validate_secret
42
+ return false unless validate_response
19
43
  return true
20
44
  end
21
- unless @secret
22
- puts 'you cant synchronize without a secret...'
23
- return false
24
- end
45
+ false
46
+ end
47
+
48
+ def create_verticals
49
+ return false unless parse_json
50
+ create_vertical({:name => 'User', :slices => {:id => 'integer', :nick => 'text', :email => 'text'}}, @hash[:users])
51
+ @hash[:structures].each_with_index {|structure, i| create_vertical(structure, @hash[:verticals][i][:horizontals], @hash[:verticals][i][:occurrences])}
52
+ end
53
+
54
+ def remote_string
25
55
  begin
26
56
  uri = "/synchronizers/#{@secret}/#{Time.now.to_i}/export.json"
27
57
  uri += "?query=#{CGI::escape(@params.to_json)}" if @params
28
- Net::HTTP.start("manager.towsta.com"){|http| @json = http.get(uri).body}
29
- puts 'Synchronized with towsta...'
30
- if @json == " "
31
- puts 'Maybe your secret is wrong...'
32
- return false
33
- elsif @json[0] != "{"
34
- puts "something wrong with the server"
35
- return false
36
- else
37
- return true
38
- end
58
+ @response = Net::HTTP.start("manager.towsta.com"){|http| @json = http.get(uri).body}
59
+ puts "\nSynchronized with Towsta!"
60
+ return true
39
61
  rescue
40
- puts 'failed to synchronize with towsta...'
62
+ puts "\nFailed to synchronize with Towsta."
41
63
  return false
42
64
  end
43
65
  end
44
66
 
45
- def backup
46
- if @path != ".json"
47
- open(@path, "wb"){|file| file.write @json}
48
- puts "creating a backup in #{@path}"
49
- end
67
+ def cache_string
68
+ @response = @cache if @cache
69
+ !!@cache
50
70
  end
51
71
 
52
- def find_old
53
- unless File.exists? @path
54
- puts 'could not find any old version...'
55
- else
56
- @json = IO.read(@path).to_s
57
- puts 'assuming newest backup...'
58
- end
72
+ def validate_secret
73
+ return true if @response != " "
74
+ puts " maybe your secret is wrong"
75
+ false
76
+ end
77
+
78
+ def validate_response
79
+ return true if @response[0] == "{"
80
+ puts " something wrong with the server"
81
+ false
59
82
  end
60
83
 
61
- def just_do_it
62
- return false if @hash == " "
84
+ def has_secret
85
+ return true if @secret
86
+ puts "\nyou cant synchronize without a secret..."
87
+ false
88
+ end
89
+
90
+ def parse_json
63
91
  begin
64
- hash = JSON.parse @json, :symbolize_names => true
92
+ @hash = JSON.parse @response, :symbolize_names => true
93
+ return true
65
94
  rescue
66
- puts 'Something went wrong tryng to parse JSON.'
95
+ puts ' Something went wrong tryng to parse JSON.'
67
96
  return false
68
97
  end
69
- begin
70
- Object.send(:remove_const, :User)
71
- rescue;nil;end
72
- Vertical.create :name => 'User', :slices => {:id => 'integer', :nick => 'string', :email => 'string'}
73
- hash[:users].each {|user| User.new user}
74
- hash[:structures].each_with_index do |structure, i|
75
- begin
76
- Object.send(:remove_const, structure[:name].to_sym)
77
- rescue;nil;end
78
- Vertical.create structure
79
- Vertical.all << eval(structure[:name])
80
- hash[:verticals][i][:horizontals].each {|horizontal| Vertical.all.last.new horizontal}
81
- puts "vertical #{structure[:name]} was created with #{hash[:verticals][i][:horizontals].size} horizontals"
82
- if hash[:verticals][i][:occurrences].any?
83
- hash[:verticals][i][:occurrences].each do |occurrence|
84
- Vertical.all.last.add_occurrence occurrence
85
- end
86
- end
87
- end
88
- true
89
- end
90
-
91
- def self.callback json
92
- json = JSON.parse json, :symbolize_names => true
93
- return eval(json[:vertical]).new json[:attributes] if json[:action] == 'create'
94
- return eval(json[:vertical]).update json[:attributes] if json[:action] == 'update'
95
- eval(json[:vertical]).destroy json[:attributes][:id]
96
98
  end
97
99
 
98
- def authenticate code
99
- JSON.parse Net::HTTP.start("manager.towsta.com"){|http| @json = http.get("/synchronizers/#{@secret}/#{code}.json").body}, :symbolize_names => true
100
+ def create_vertical structure, horizontals, occurrences=[]
101
+ Object.instance_eval{ remove_const structure[:name].to_sym } if Object.const_defined?(structure[:name].to_sym)
102
+ Vertical.create structure
103
+ Vertical.all << eval(structure[:name])
104
+ horizontals.each {|horizontal| eval(structure[:name].to_s).new(horizontal)}
105
+ occurrences.each {|occurrence| eval(structure[:name].to_s).add_occurrence(occurrence)}
106
+ puts " class #{structure[:name]} was created with #{horizontals.size} instances"
100
107
  end
101
108
 
102
109
  end
103
110
 
104
111
  end
105
-
@@ -1,3 +1,3 @@
1
1
  module Towsta
2
- VERSION = "1.1.7"
2
+ VERSION = "1.2.0"
3
3
  end
@@ -4,7 +4,6 @@ module Towsta
4
4
 
5
5
  class << self
6
6
  attr_accessor :all
7
- # Vertical.all = []
8
7
  end
9
8
 
10
9
  def self.create(args)
@@ -15,10 +14,11 @@ module Towsta
15
14
  end
16
15
 
17
16
  args[:slices].each do |attr, kind|
18
- eval "def #{attr}= value; #{Vertical.parse_set attr, kind}; end;"
19
- eval "def #{attr}; #{Vertical.parse_get attr, kind}; end;"
20
- eval "def self.find_by_#{attr} value; #{Vertical.parse_find attr, kind}; nil; end;"
21
- eval "def self.find_all_by_#{attr} value; #{Vertical.parse_find_all attr, kind}; end;"
17
+ eval "def object_of_#{attr}; @#{attr}; end;"
18
+ eval "def #{attr}= value; @#{attr} ||= Towsta::Kinds::#{kind[0].upcase + kind[1..-1]}Kind.new; @#{attr}.set value; end;"
19
+ eval "def #{attr}; @#{attr}.get; end;"
20
+ eval "def self.find_by_#{attr} value; self.all.each {|e| return e if e.object_of_#{attr}.compare value}; nil; end;"
21
+ eval "def self.find_all_by_#{attr} value; found =[]; self.all.each {|e| found << e if e.object_of_#{attr}.compare value}; found; end;"
22
22
  eval "def option_for_#{attr} value; return {value: value, selected: 'selected'} if value == #{attr}; {value: value}; end"
23
23
  end
24
24
 
@@ -35,7 +35,7 @@ module Towsta
35
35
  end
36
36
 
37
37
  def initialize args
38
- args.each {|k,v| eval "self.#{k}= '#{v}';"}
38
+ self.attributes.merge(args).each {|k,v| eval "self.#{k}= '#{v}';"}
39
39
  self.class.all << self
40
40
  end
41
41
 
@@ -44,19 +44,9 @@ module Towsta
44
44
  self.save author
45
45
  end
46
46
 
47
- def self.update args
48
- self.find(args[:id]).update(args)
49
- end
50
-
51
47
  def destroy
52
- self.class.all.delete self
53
- self
54
- end
55
-
56
- def self.destroy id
57
- element = self.find id
58
- self.all.delete element
59
- element
48
+ # self.class.all.delete self
49
+ # self
60
50
  end
61
51
 
62
52
  def self.to_hash
@@ -69,17 +59,16 @@ module Towsta
69
59
  creator = author.email if author
70
60
  export = self.attributes
71
61
  export.delete :author
72
- export.delete :vertical
73
62
  export.delete :created_at
74
63
  export.delete :updated_at
75
64
  id_aux = export.delete(:id)
76
65
  id_aux ? id_aux : '0'
77
66
  export = {:creator => creator, :vertical => self.class.to_s, :attributes => export, :id => id_aux}
78
- uri = URI.parse("http://manager.towsta.com/synchronizers/#{$towsta_secret}/import.json")
79
- response = JSON.parse Net::HTTP.post_form(uri, {:code => export.to_json}).body.to_s, :symbolize_names => true
67
+ response = Towsta::Synchronizer.save_request export
80
68
  self.id = response[:id] if response[:status]
69
+ self.author = User.find_by_email creator
81
70
  Towsta::Memory.flush if $towsta_cache
82
- response
71
+ response[:status]
83
72
  end
84
73
 
85
74
  def self.random
@@ -88,38 +77,20 @@ module Towsta
88
77
  end
89
78
 
90
79
  def self.create args, creator=$towsta_default_author
91
- self.new(args.merge(:id => nil)).save creator
80
+ new = self.new(args.merge(:id => nil))
81
+ new.save creator
82
+ new
92
83
  end
93
84
 
94
85
  def attributes
95
- horizontal = {:vertical => self.class.to_s}
86
+ horizontal = {}
96
87
  self.class.attributes.each do |attr|
97
- foreings = Vertical.all + [User]
98
- if foreings.include? eval(attr.to_s).class
99
- horizontal[attr] = eval(attr.to_s).id
100
- elsif eval(attr.to_s).class == Time
101
- horizontal[attr] = eval(attr.to_s).strftime('%m/%d/%Y %H:%M')
102
- elsif eval(attr.to_s).class == DateTime
103
- horizontal[attr] = eval(attr.to_s).strftime('%m/%d/%Y')
104
- elsif eval(attr.to_s).class == TrueClass
105
- horizontal[attr] = 1
106
- elsif eval(attr.to_s).class == FalseClass
107
- horizontal[attr] = 0
108
- else
109
- horizontal[attr] = eval(attr.to_s).to_s
110
- end
88
+ slice = eval("self.object_of_#{attr.to_s}")
89
+ horizontal[attr] = slice ? slice.export : nil
111
90
  end
112
91
  horizontal
113
92
  end
114
93
 
115
- def find_horizontal id
116
- Vertical.all.each do |v|
117
- horizontal = v.find_by_id id.to_i
118
- return horizontal if horizontal
119
- end
120
- nil
121
- end
122
-
123
94
  def self.add_occurrence occurrence
124
95
  self.send(:define_singleton_method, "occurrences_of_#{occurrence[:name].downcase}") do
125
96
  eval occurrence[:items].inspect
@@ -133,74 +104,6 @@ module Towsta
133
104
  Object.const_set args[:name], klass
134
105
  end
135
106
 
136
- private
137
- def self.parse_get attr, kind
138
- return "@#{attr}.class == String ? self.find_horizontal(@#{attr}) : @#{attr}" if kind == 'vertical'
139
- "@#{attr}"
140
- end
141
-
142
- def self.parse_set attr, kind
143
- return "@#{attr} = \"\#{value.to_s}\"" if ['main','text','formated','password','link'].include? kind
144
- return "@#{attr} = value.to_f;" if kind == 'money'
145
- return "@#{attr} = value.to_i;" if kind == 'integer'
146
- return "@#{attr} = value == '1';" if kind == 'boolean'
147
- return "@#{attr} = Vertical.to_dt(value);" if kind == 'datetime'
148
- return "@#{attr} = Vertical.to_d(value);" if kind == 'date'
149
- return "@#{attr} = Vertical.to_bresson(value);" if kind == 'image'
150
- return "@#{attr} = User.find value.to_i;" if kind == 'user'
151
- return "@#{attr} = value.split(', ');" if kind == 'list'
152
- return "@#{attr} = Vertical.to_gallery(value.to_s);" if kind == 'gallery'
153
- "@#{attr} = value;"
154
- end
155
-
156
- def self.parse_find attr, kind
157
- return "self.all.each {|e| return e if e.#{attr} == value};" unless kind == 'list'
158
- "self.all.each {|e| return e if e.#{attr}.include?(value)};"
159
- end
160
-
161
- def self.parse_find_all attr, kind
162
- return "found =[]; self.all.each {|e| found << e if e.#{attr} == value}; found;" unless kind == 'list'
163
- "found =[]; self.all.each {|e| found << e if e.#{attr}.include?(value)}; found;"
164
- end
165
-
166
- def self.to_gallery value
167
- if value.class == String
168
- begin;
169
- gal = JSON.parse(value, :symbolize_names => true)
170
- arr = []
171
- gal.each do |g|
172
- arr << Bresson::ImageReference.new(g)
173
- end
174
- return arr
175
- rescue; nil; end
176
- else
177
- value
178
- end
179
- end
180
-
181
- def self.to_dt value
182
- if value.class == String
183
- begin; DateTime.strptime(value, '%m/%d/%Y %H:%M').to_time;
184
- rescue; nil; end
185
- else
186
- value
187
- end
188
- end
189
-
190
- def self.to_d value
191
- if value.class == String
192
- begin; DateTime.strptime(value, '%m/%d/%Y');
193
- rescue; nil; end
194
- else
195
- value
196
- end
197
- end
198
-
199
- def self.to_bresson value
200
- begin; Bresson::ImageReference.new JSON.parse(value[1..-2], :symbolize_names => true)
201
- rescue; nil; end
202
- end
203
-
204
107
  end
205
108
 
206
109
  end
data/lib/towsta.rb CHANGED
@@ -11,10 +11,29 @@ require 'bresson'
11
11
  require 'sinatra'
12
12
  require 'compass'
13
13
 
14
+ require File.expand_path('../towsta/kinds/main', __FILE__)
14
15
  require File.expand_path('../towsta/vertical', __FILE__)
15
16
  require File.expand_path('../towsta/synchronizer', __FILE__)
16
17
  require File.expand_path('../towsta/memory', __FILE__)
17
18
  require File.expand_path('../towsta/sinatra_extension', __FILE__)
19
+ require File.expand_path('../towsta/login', __FILE__)
20
+ require File.expand_path('../towsta/kinds/boolean', __FILE__)
21
+ require File.expand_path('../towsta/kinds/date', __FILE__)
22
+ require File.expand_path('../towsta/kinds/datetime', __FILE__)
23
+ require File.expand_path('../towsta/kinds/file', __FILE__)
24
+ require File.expand_path('../towsta/kinds/formated', __FILE__)
25
+ require File.expand_path('../towsta/kinds/gallery', __FILE__)
26
+ require File.expand_path('../towsta/kinds/image', __FILE__)
27
+ require File.expand_path('../towsta/kinds/integer', __FILE__)
28
+ require File.expand_path('../towsta/kinds/link', __FILE__)
29
+ require File.expand_path('../towsta/kinds/list', __FILE__)
30
+ require File.expand_path('../towsta/kinds/money', __FILE__)
31
+ require File.expand_path('../towsta/kinds/password', __FILE__)
32
+ require File.expand_path('../towsta/kinds/text', __FILE__)
33
+ require File.expand_path('../towsta/kinds/user', __FILE__)
34
+ require File.expand_path('../towsta/kinds/vertical', __FILE__)
35
+
36
+ Dir["./controllers/*.rb"].each {|file| require file}
18
37
 
19
38
  module Towsta
20
39
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 1
8
- - 7
9
- version: 1.1.7
7
+ - 2
8
+ - 0
9
+ version: 1.2.0
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-11-21 00:00:00 -02:00
17
+ date: 2011-11-24 00:00:00 -02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -123,6 +123,23 @@ files:
123
123
  - Rakefile
124
124
  - bin/towsta
125
125
  - lib/towsta.rb
126
+ - lib/towsta/kinds/boolean.rb
127
+ - lib/towsta/kinds/date.rb
128
+ - lib/towsta/kinds/datetime.rb
129
+ - lib/towsta/kinds/file.rb
130
+ - lib/towsta/kinds/formated.rb
131
+ - lib/towsta/kinds/gallery.rb
132
+ - lib/towsta/kinds/image.rb
133
+ - lib/towsta/kinds/integer.rb
134
+ - lib/towsta/kinds/link.rb
135
+ - lib/towsta/kinds/list.rb
136
+ - lib/towsta/kinds/main.rb
137
+ - lib/towsta/kinds/money.rb
138
+ - lib/towsta/kinds/password.rb
139
+ - lib/towsta/kinds/text.rb
140
+ - lib/towsta/kinds/user.rb
141
+ - lib/towsta/kinds/vertical.rb
142
+ - lib/towsta/login.rb
126
143
  - lib/towsta/memory.rb
127
144
  - lib/towsta/sinatra_extension.rb
128
145
  - lib/towsta/synchronizer.rb