dynamic_models 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/dynamic_models.gemspec +2 -2
- data/lib/dynamic_models.rb +4 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/dynamic_models.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dynamic_models}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Craig Ulliott"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-07-01}
|
13
13
|
s.description = %q{Methods to get and build models directly from parameters. Useful for DRYing up code, specifically very dynamic code for things like admin tools.}
|
14
14
|
s.email = %q{craigulliott@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/dynamic_models.rb
CHANGED
@@ -4,7 +4,7 @@ module DynamicModels
|
|
4
4
|
def parent_model
|
5
5
|
params.each do |name, value|
|
6
6
|
if name =~ /(.+)_id$/
|
7
|
-
return @parent_model ||= $1.
|
7
|
+
return @parent_model ||= $1.camelize.constantize.find(value)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
nil
|
@@ -17,14 +17,14 @@ module DynamicModels
|
|
17
17
|
|
18
18
|
# returns a new model, it can be set with an optional hash
|
19
19
|
def new_model(defaults = {})
|
20
|
-
new_model = model_name.
|
20
|
+
new_model = model_name.camelize.constantize.new(defaults)
|
21
21
|
new_model.send("#{parent_model.class.name.downcase}=", parent_model) if parent_model
|
22
22
|
return new_model
|
23
23
|
end
|
24
24
|
|
25
25
|
# returns a model using the id from the params
|
26
26
|
def fetch_model
|
27
|
-
model_name.
|
27
|
+
model_name.camelize.constantize.find( params[:id] )
|
28
28
|
end
|
29
29
|
|
30
30
|
# returns an array of models (using the name of this controller)
|
@@ -32,7 +32,7 @@ module DynamicModels
|
|
32
32
|
if parent_model
|
33
33
|
return parent_model.send("#{model_name.pluralize.downcase}")
|
34
34
|
else
|
35
|
-
return model_name.
|
35
|
+
return model_name.camelize.constantize.find(:all)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: dynamic_models
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Craig Ulliott
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-01 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements:
|
93
93
|
- - ">="
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
hash:
|
95
|
+
hash: -1251577544687932411
|
96
96
|
segments:
|
97
97
|
- 0
|
98
98
|
version: "0"
|