garden 0.0.5.pre → 0.0.6.pre
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/lib/garden/mediators.rb +46 -9
- data/lib/garden/version.rb +1 -1
- metadata +4 -4
data/lib/garden/mediators.rb
CHANGED
@@ -2,22 +2,50 @@ module Garden
|
|
2
2
|
module Mediators
|
3
3
|
class Table
|
4
4
|
|
5
|
-
def self.parse_table_name namish
|
6
|
-
|
5
|
+
# def self.parse_table_name namish
|
6
|
+
# namish.parameterize.underscore
|
7
|
+
# end
|
8
|
+
|
9
|
+
def self.find_model_class namish
|
10
|
+
clazz = nil
|
11
|
+
namish = namish.singularize
|
12
|
+
|
13
|
+
begin
|
14
|
+
# try the format as it should be. Camelcase, and with :: or / for modules
|
15
|
+
# Module::Classname
|
16
|
+
clazz = namish.underscore.classify.constantize
|
17
|
+
rescue
|
18
|
+
begin
|
19
|
+
# try the format "Class Name" by turning spaced words into camelcase
|
20
|
+
clazz = namish.parameterize.underscore.classify.constantize
|
21
|
+
rescue
|
22
|
+
begin
|
23
|
+
# try the format "Class Name" by turning spaced words into module separators
|
24
|
+
clazz = namish.gsub(/ /, "/").underscore.classify.constantize
|
25
|
+
rescue
|
26
|
+
puts "Nope"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
clazz
|
7
31
|
end
|
8
32
|
|
9
33
|
def initialize namish
|
10
34
|
|
11
|
-
@
|
35
|
+
@clazz = Table.find_model_class namish
|
12
36
|
|
13
|
-
|
14
|
-
|
15
|
-
@clazz = @name.classify.constantize
|
16
|
-
raise "Class #{@clazz.to_s} is not an ActiveRecord subclass." unless @clazz.new.is_a?(ActiveRecord::Base)
|
17
|
-
rescue Exception => e
|
18
|
-
puts " ** Could not derive ActiveRecord model from the provided name: #{namish}. Exception: #{e.message}"
|
37
|
+
if @clazz.nil? || !@clazz.new.is_a?(ActiveRecord::Base)
|
38
|
+
raise "Class '#{namish}' could not be parsed to an ActiveRecord subclass."
|
19
39
|
end
|
20
40
|
|
41
|
+
# Get the ActiveRecord model from the tablename.
|
42
|
+
# begin
|
43
|
+
# @clazz = @name.classify.constantize
|
44
|
+
# raise "Class #{@clazz.to_s} is not an ActiveRecord subclass." unless @clazz.new.is_a?(ActiveRecord::Base)
|
45
|
+
# rescue Exception => e
|
46
|
+
# puts " ** Could not derive ActiveRecord model from the provided name: #{namish}. Exception: #{e.message}"
|
47
|
+
# end
|
48
|
+
|
21
49
|
@instance = @clazz.new
|
22
50
|
|
23
51
|
end
|
@@ -43,6 +71,15 @@ module Garden
|
|
43
71
|
Instance.new @clazz, attributes
|
44
72
|
end
|
45
73
|
|
74
|
+
|
75
|
+
def class_exists?(name)
|
76
|
+
begin
|
77
|
+
true if Kernel.const_get(name)
|
78
|
+
rescue NameError
|
79
|
+
false
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
46
83
|
end
|
47
84
|
end
|
48
85
|
end
|
data/lib/garden/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: garden
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6.pre
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-29 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: spreadsheet
|
16
|
-
requirement: &
|
16
|
+
requirement: &70113378924860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70113378924860
|
25
25
|
description: ! 'Allows you to organize your seeds in different formats. Typical seeds.rb,
|
26
26
|
yaml fixtures, and a variety of spreadsheet formats. '
|
27
27
|
email:
|