towsta 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,6 +68,11 @@ module Towsta
68
68
  Vertical.all << eval(structure[:name])
69
69
  hash[:verticals][i][:horizontals].each {|horizontal| Vertical.all.last.new horizontal}
70
70
  puts "vertical #{structure[:name]} was created with #{hash[:verticals][i][:horizontals].size} horizontals"
71
+ if hash[:verticals][i][:occurrences].any?
72
+ hash[:verticals][i][:occurrences].each do |occurrence|
73
+ Vertical.all.last.add_occurrence occurrence
74
+ end
75
+ end
71
76
  end
72
77
  true
73
78
  end
@@ -1,3 +1,3 @@
1
1
  module Towsta
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -20,8 +20,8 @@ module Towsta
20
20
  args[:slices].each do |attr, kind|
21
21
  eval "def #{attr}= value; #{Vertical.parse_set attr, kind}; end;"
22
22
  eval "def #{attr}; #{Vertical.parse_get attr, kind}; end;"
23
- eval "def self.find_by_#{attr} value; self.all.each {|e| return e if e.#{attr} == value}; nil; end;"
24
- eval "def self.find_all_by_#{attr} value; found = []; self.all.each {|e| found << e if e.#{attr} == value}; found; end;"
23
+ eval "def self.find_by_#{attr} value; #{Vertical.parse_find attr, kind}; nil; end;"
24
+ eval "def self.find_all_by_#{attr} value; #{Vertical.parse_find_all attr, kind}; end;"
25
25
  end
26
26
 
27
27
  def self.count
@@ -114,6 +114,12 @@ module Towsta
114
114
  nil
115
115
  end
116
116
 
117
+ def self.add_occurrence occurrence
118
+ self.send(:define_singleton_method, "occurrences_of_#{occurrence[:name].downcase}") do
119
+ eval occurrence[:items].inspect
120
+ end
121
+ end
122
+
117
123
  end
118
124
  klass.all = []
119
125
  klass.attributes = args[:slices].keys
@@ -134,9 +140,20 @@ module Towsta
134
140
  return "@#{attr} = Vertical.to_dt(value);" if kind == 'datetime'
135
141
  return "@#{attr} = Vertical.to_d(value);" if kind == 'date'
136
142
  return "@#{attr} = User.find value.to_i;" if kind == 'user'
143
+ return "@#{attr} = value.split(', ');" if kind == 'list'
137
144
  "@#{attr} = value;"
138
145
  end
139
146
 
147
+ def self.parse_find attr, kind
148
+ return "self.all.each {|e| return e if e.#{attr} == value};" unless kind == 'list'
149
+ "self.all.each {|e| return e if e.#{attr}.include?(value)};"
150
+ end
151
+
152
+ def self.parse_find_all attr, kind
153
+ return "found =[]; self.all.each {|e| found << e if e.#{attr} == value}; found;" unless kind == 'list'
154
+ "found =[]; self.all.each {|e| found << e if e.#{attr}.include?(value)}; found;"
155
+ end
156
+
140
157
  def self.to_dt value
141
158
  begin; DateTime.strptime(value, '%m/%d/%Y %H:%M').to_time;
142
159
  rescue; nil; end;
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 3
8
- - 4
9
- version: 0.3.4
8
+ - 5
9
+ version: 0.3.5
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-04-26 00:00:00 -03:00
17
+ date: 2011-04-28 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency