lockdown 0.5.14 → 0.5.16
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/History.txt +5 -1
- data/lib/lockdown/classy-inheritance.rb +43 -6
- data/lib/lockdown/version.rb +1 -1
- data/website/index.html +1 -1
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
== 0.5.
|
1
|
+
== 0.5.15 2008-07-18
|
2
|
+
* Updated included classy inheritance library.
|
3
|
+
|
4
|
+
== 0.5.14 2008-07-18
|
2
5
|
* Change: option no_migration to skip-migrations to mimick other generator options
|
6
|
+
* Fixed: errant creation of sessions directory in app/controllers
|
3
7
|
|
4
8
|
== 0.5.13 2008-07-10
|
5
9
|
* Add: Support for --namespace option on generator. Use as ./script generate lockdown --all --namespace=admin
|
@@ -26,8 +26,22 @@ module Stonean
|
|
26
26
|
def depends_on(model_sym, options = {})
|
27
27
|
define_relationship(model_sym,options)
|
28
28
|
|
29
|
-
|
30
|
-
|
29
|
+
# Optional presence of handling
|
30
|
+
if options.has_key?(:validates_presence_if) && options[:validates_presence_if] != true
|
31
|
+
if [Symbol, String, Proc].include?(options[:validates_presence_if].class)
|
32
|
+
validates_presence_of model_sym, :if => options[:validates_presence_if]
|
33
|
+
end
|
34
|
+
else
|
35
|
+
validates_presence_of model_sym
|
36
|
+
end
|
37
|
+
|
38
|
+
if options.has_key?(:validates_associated_if) && options[:validates_associated_if] != true
|
39
|
+
if [Symbol, String, Proc].include?(options[:validates_assoicated_if].class)
|
40
|
+
validates_associated model_sym, :if => options[:validates_associated_if]
|
41
|
+
end
|
42
|
+
else
|
43
|
+
validates_associated model_sym
|
44
|
+
end
|
31
45
|
|
32
46
|
# Before save functionality to create/update the requisite object
|
33
47
|
define_save_method(model_sym, options[:as])
|
@@ -36,7 +50,7 @@ module Stonean
|
|
36
50
|
define_find_with_method(model_sym)
|
37
51
|
|
38
52
|
if options[:as]
|
39
|
-
define_can_be_method_on_requisite_class(model_sym, options[:as])
|
53
|
+
define_can_be_method_on_requisite_class(options[:class_name] || model_sym, options[:as])
|
40
54
|
end
|
41
55
|
|
42
56
|
options[:attrs].each{|attr| define_accessors(model_sym, attr, options)}
|
@@ -63,9 +77,19 @@ module Stonean
|
|
63
77
|
|
64
78
|
private
|
65
79
|
|
80
|
+
def classy_options
|
81
|
+
[:as, :attrs, :prefix, :postfix, :validates_presence_if, :validates_associated_if]
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete_classy_options(options, *keepers)
|
85
|
+
options.delete_if do |key,value|
|
86
|
+
classy_options.include?(key) && !keepers.include?(key)
|
87
|
+
end
|
88
|
+
options
|
89
|
+
end
|
90
|
+
|
66
91
|
def define_relationship(model_sym, options)
|
67
|
-
opts = options.dup
|
68
|
-
[:attrs, :prefix].each{|key| opts.delete(key)}
|
92
|
+
opts = delete_classy_options(options.dup, :as)
|
69
93
|
if opts[:as]
|
70
94
|
as_opt = opts.delete(:as)
|
71
95
|
opts = polymorphic_constraints(as_opt).merge(opts)
|
@@ -77,12 +101,17 @@ module Stonean
|
|
77
101
|
|
78
102
|
def define_save_method(model_sym, polymorphic_name = nil)
|
79
103
|
define_method "save_requisite_#{model_sym}" do
|
104
|
+
# Return unless the association exists
|
105
|
+
eval("return unless self.#{model_sym}")
|
106
|
+
|
107
|
+
# Set the polymorphic type and id before saving
|
80
108
|
if polymorphic_name
|
81
109
|
eval("self.#{model_sym}.#{polymorphic_name}_type = self.class.name")
|
82
110
|
eval("self.#{model_sym}.#{polymorphic_name}_id = self.id")
|
83
111
|
end
|
84
112
|
|
85
113
|
if polymorphic_name
|
114
|
+
# Save only if it's an update, has_one creates automatically
|
86
115
|
eval <<-SAVEIT
|
87
116
|
unless self.#{model_sym}.new_record?
|
88
117
|
self.#{model_sym}.save
|
@@ -116,7 +145,15 @@ module Stonean
|
|
116
145
|
end
|
117
146
|
|
118
147
|
def define_accessors(model_sym, attr, options)
|
119
|
-
accessor_method_name =
|
148
|
+
accessor_method_name = attr
|
149
|
+
|
150
|
+
if options[:prefix]
|
151
|
+
accessor_method_name = (options[:prefix] == true) ? "#{model_sym}_#{accessor_method_name}" : "#{options[:prefix]}_#{accessor_method_name}"
|
152
|
+
end
|
153
|
+
|
154
|
+
if options[:postfix]
|
155
|
+
accessor_method_name = (options[:postfix] == true) ? "#{accessor_method_name}_#{model_sym}" : "#{accessor_method_name}_#{options[:postfix]}"
|
156
|
+
end
|
120
157
|
|
121
158
|
define_method accessor_method_name do
|
122
159
|
eval("self.#{model_sym} ? self.#{model_sym}.#{attr} : nil")
|
data/lib/lockdown/version.rb
CHANGED
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Lockdown</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/lockdown"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/lockdown" class="numbers">0.5.
|
36
|
+
<a href="http://rubyforge.org/projects/lockdown" class="numbers">0.5.16</a>
|
37
37
|
</div>
|
38
38
|
<h2>What</h2>
|
39
39
|
|