tworgy-rails 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ class LocalRecord < Struct.new :id, :name
2
+ @@all_children = {}
3
+
4
+ def self.inherited(klass)
5
+ @@all_children[klass] = []
6
+ end
7
+
8
+ def initialize(id, name)
9
+ self.id = id
10
+ self.name = name
11
+ self.class.const_set(name.titleize.gsub(/ /, ''), self)
12
+ LocalRecord.append_to_all(self.class, self)
13
+ end
14
+
15
+ def self.all
16
+ @@all_children[self]
17
+ end
18
+
19
+ def self.append_to_all(klass, record)
20
+ @@all_children[klass] << record
21
+ end
22
+
23
+ def self.selections
24
+ all.collect {|c| [c.name, c.id]}
25
+ end
26
+
27
+ def self.find(*args)
28
+ if args.length == 1
29
+ id = args[0]
30
+ all.find { |c| c.id == id }
31
+ elsif args.length == 2
32
+ if args[0].is_a?(Fixnum)
33
+ find(args[0])
34
+ else
35
+ DBC.assert(false, "No code written to handle args => #{args.inspect}")
36
+ end
37
+ else
38
+ DBC.assert(false, "No code written to handle args => #{args.inspect}")
39
+ end
40
+ end
41
+
42
+ def self.pick_random
43
+ all[rand(all.length)]
44
+ end
45
+
46
+ def to_s
47
+ name
48
+ end
49
+
50
+ def <=>(b)
51
+ self.name <=> b.name
52
+ end
53
+
54
+ def new_record?
55
+ false
56
+ end
57
+ end
data/lib/tworgy-rails.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'tworgy/active_record'
2
2
  require 'tworgy/routing'
3
3
  require 'tworgy/iphoneification'
4
+ require 'tworgy/local_record'
4
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tworgy-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mat Holroyd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-02-26 00:00:00 +11:00
12
+ date: 2010-03-17 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -38,6 +38,7 @@ files:
38
38
  - lib/tworgy-rails.rb
39
39
  - lib/tworgy/active_record.rb
40
40
  - lib/tworgy/iphoneification.rb
41
+ - lib/tworgy/local_record.rb
41
42
  - lib/tworgy/routing.rb
42
43
  - spec/spec.opts
43
44
  - spec/spec_helper.rb