hobo 0.7.5 → 0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/{hobo_files/plugin/CHANGES.txt → CHANGES.txt} +391 -0
- data/Manifest +146 -0
- data/{hobo_files/plugin/README → README} +0 -0
- data/bin/hobo +13 -26
- data/dryml_generators/rapid/cards.dryml.erb +55 -0
- data/dryml_generators/rapid/forms.dryml.erb +43 -0
- data/dryml_generators/rapid/pages.dryml.erb +284 -0
- data/hobo.gemspec +168 -0
- data/init.rb +9 -0
- data/lib/action_view_extensions/helpers/tag_helper.rb +7 -0
- data/lib/active_record/association_collection.rb +54 -0
- data/{hobo_files/plugin/lib → lib}/active_record/association_proxy.rb +12 -4
- data/{hobo_files/plugin/lib → lib}/active_record/association_reflection.rb +7 -1
- data/{hobo_files/plugin/lib → lib}/extensions/test_case.rb +17 -17
- data/{hobo_files/plugin/lib → lib}/hobo.rb +193 -100
- data/{hobo_files/plugin/lib → lib}/hobo/authentication_support.rb +8 -8
- data/{hobo_files/plugin/lib → lib}/hobo/bundle.rb +90 -89
- data/{hobo_files/plugin/lib → lib}/hobo/composite_model.rb +21 -21
- data/{hobo_files/plugin/lib → lib}/hobo/controller.rb +38 -25
- data/{hobo_files/plugin/lib → lib}/hobo/dev_controller.rb +10 -6
- data/lib/hobo/dryml.rb +167 -0
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/dryml_builder.rb +28 -25
- data/lib/hobo/dryml/dryml_generator.rb +210 -0
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/dryml_support_controller.rb +1 -1
- data/lib/hobo/dryml/parser.rb +3 -0
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/attribute.rb +6 -6
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/base_parser.rb +16 -16
- data/lib/hobo/dryml/parser/document.rb +57 -0
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/element.rb +7 -7
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/elements.rb +9 -9
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/source.rb +3 -3
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/text.rb +3 -3
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/parser/tree_parser.rb +3 -3
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/part_context.rb +26 -26
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/scoped_variables.rb +15 -15
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/tag_parameters.rb +10 -10
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/taglib.rb +43 -37
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/template.rb +290 -208
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/template_environment.rb +173 -115
- data/{hobo_files/plugin/lib → lib}/hobo/dryml/template_handler.rb +19 -24
- data/lib/hobo/find_for.rb +95 -0
- data/{hobo_files/plugin/lib → lib}/hobo/generator.rb +2 -1
- data/{hobo_files/plugin/lib → lib}/hobo/guest.rb +12 -4
- data/{hobo_files/plugin/lib → lib}/hobo/hobo_helper.rb +146 -117
- data/lib/hobo/include_in_save.rb +43 -0
- data/lib/hobo/lifecycles.rb +94 -0
- data/lib/hobo/lifecycles/actions.rb +73 -0
- data/lib/hobo/lifecycles/creator.rb +76 -0
- data/lib/hobo/lifecycles/lifecycle.rb +205 -0
- data/lib/hobo/lifecycles/state.rb +23 -0
- data/lib/hobo/lifecycles/transition.rb +66 -0
- data/{hobo_files/plugin/lib → lib}/hobo/model.rb +306 -217
- data/{hobo_files/plugin/lib → lib}/hobo/model_controller.rb +342 -213
- data/{hobo_files/plugin/lib → lib}/hobo/model_router.rb +151 -120
- data/{hobo_files/plugin/lib → lib}/hobo/model_support.rb +9 -9
- data/{hobo_files/plugin/lib → lib}/hobo/rapid_helper.rb +30 -23
- data/{hobo_files/plugin/lib → lib}/hobo/scopes.rb +22 -68
- data/{hobo_files/plugin/lib → lib}/hobo/scopes/apply_scopes.rb +5 -5
- data/lib/hobo/scopes/association_proxy_extensions.rb +47 -0
- data/{hobo_files/plugin/lib → lib}/hobo/scopes/automatic_scopes.rb +104 -79
- data/lib/hobo/scopes/named_scope_extensions.rb +27 -0
- data/{hobo_files/plugin/lib → lib}/hobo/static_tags +1 -11
- data/{hobo_files/plugin/lib → lib}/hobo/undefined.rb +1 -1
- data/{hobo_files/plugin/lib → lib}/hobo/undefined_access_error.rb +0 -0
- data/{hobo_files/plugin/lib → lib}/hobo/user.rb +27 -25
- data/{hobo_files/plugin/lib → lib}/hobo/user_controller.rb +80 -34
- data/{hobo_files/plugin/generators → rails_generators}/hobo/hobo_generator.rb +7 -7
- data/rails_generators/hobo/templates/application.css +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/application.dryml +0 -2
- data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/dryml-support.js +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo/templates/guest.rb +0 -0
- data/rails_generators/hobo/templates/initializer.rb +9 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/USAGE +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/hobo_front_controller_generator.rb +1 -3
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/controller.rb +1 -1
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/functional_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_front_controller/templates/helper.rb +0 -0
- data/rails_generators/hobo_front_controller/templates/index.dryml +25 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/USAGE +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/hobo_model_generator.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/fixtures.yml +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/model.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model/templates/unit_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/USAGE +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/hobo_model_controller_generator.rb +0 -7
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/controller.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/functional_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_controller/templates/helper.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/hobo_model_resource_generator.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/controller.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/functional_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_model_resource/templates/helper.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/hobo_rapid_generator.rb +21 -11
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/IE7.js +1 -1
- data/rails_generators/hobo_rapid/templates/blank.gif +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/hobo-rapid.css +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/hobo-rapid.js +175 -104
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/lowpro.js +0 -0
- data/rails_generators/hobo_rapid/templates/nicEditorIcons.gif +0 -0
- data/rails_generators/hobo_rapid/templates/nicedit.js +91 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/reset.css +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/fieldbg.gif +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/pencil.png +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/small_close.png +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/images/spinner.gif +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/stylesheets/clean.css +80 -71
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +6 -1
- data/{hobo_files/plugin/generators → rails_generators}/hobo_rapid/templates/themes/clean/views/clean.dryml +4 -4
- data/rails_generators/hobo_subsite/hobo_subsite_generator.rb +73 -0
- data/rails_generators/hobo_subsite/templates/application.dryml +1 -0
- data/rails_generators/hobo_subsite/templates/controller.rb +5 -0
- data/rails_generators/hobo_subsite/templates/site_taglib.dryml +13 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/USAGE +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/hobo_user_controller_generator.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/controller.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/functional_test.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_controller/templates/helper.rb +0 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/USAGE +0 -0
- data/rails_generators/hobo_user_model/hobo_user_model_generator.rb +30 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/templates/fixtures.yml +0 -0
- data/rails_generators/hobo_user_model/templates/forgot_password.erb +10 -0
- data/rails_generators/hobo_user_model/templates/mailer.rb +14 -0
- data/rails_generators/hobo_user_model/templates/model.rb +55 -0
- data/{hobo_files/plugin/generators → rails_generators}/hobo_user_model/templates/unit_test.rb +0 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/{hobo_files/plugin/taglibs → taglibs}/core.dryml +6 -7
- data/{hobo_files/plugin/taglibs → taglibs}/rapid.dryml +36 -67
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_document_tags.dryml +7 -24
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_editing.dryml +51 -50
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_forms.dryml +62 -56
- data/taglibs/rapid_generics.dryml +33 -0
- data/taglibs/rapid_lifecycles.dryml +43 -0
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_navigation.dryml +23 -23
- data/taglibs/rapid_pages.dryml +183 -0
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_plus.dryml +30 -5
- data/{hobo_files/plugin/taglibs → taglibs}/rapid_support.dryml +3 -4
- data/taglibs/rapid_user_pages.dryml +179 -0
- data/{hobo_files/plugin/tasks → tasks}/environments.rake +0 -0
- data/{hobo_files/plugin/tasks → tasks}/fix_dryml.rake +0 -0
- data/{hobo_files/plugin/tasks → tasks}/generate_tag_reference.rb +21 -22
- data/tasks/hobo_tasks.rake +32 -0
- data/test/test_generator_helper.rb +29 -0
- data/test/test_helper.rb +1 -0
- data/test/test_hobo_model_controller_generator.rb +56 -0
- data/{hobo_files/plugin/uninstall.rb → uninstall.rb} +0 -0
- metadata +240 -225
- data/README.txt +0 -18
- data/hobo_files/plugin/LICENSE.txt +0 -22
- data/hobo_files/plugin/Rakefile +0 -96
- data/hobo_files/plugin/generators/hobo_front_controller/templates/index.dryml +0 -24
- data/hobo_files/plugin/generators/hobo_front_controller/templates/search.dryml +0 -19
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/banner.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-bodytop.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-01.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-02.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-03.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-corner-04.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-bottom.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-left.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-right.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/bkg-shadow-top.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-blue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-dblue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-green.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-purple.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/header-red.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/logo.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/plus.png +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/spinner.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-dblue.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-green.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-purple.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/txt-list-img-red.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-01.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-02.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-03.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-corner-04.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-bottom.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-left.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-right.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/images/window-shadow-top.gif +0 -0
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/public/stylesheets/application.css +0 -400
- data/hobo_files/plugin/generators/hobo_rapid/templates/themes/default/views/application.dryml +0 -96
- data/hobo_files/plugin/generators/hobo_user_model/hobo_user_model_generator.rb +0 -25
- data/hobo_files/plugin/generators/hobo_user_model/templates/model.rb +0 -56
- data/hobo_files/plugin/init.rb +0 -101
- data/hobo_files/plugin/lib/action_view_extensions/base.rb +0 -15
- data/hobo_files/plugin/lib/active_record/has_many_association.rb +0 -55
- data/hobo_files/plugin/lib/active_record/has_many_through_association.rb +0 -20
- data/hobo_files/plugin/lib/hobo/dryml.rb +0 -165
- data/hobo_files/plugin/lib/hobo/dryml/parser/document.rb +0 -53
- data/hobo_files/plugin/lib/hobo/scopes/association_proxy_extensions.rb +0 -33
- data/hobo_files/plugin/lib/hobo/scopes/defined_scope_proxy_extender.rb +0 -90
- data/hobo_files/plugin/lib/hobo/scopes/scope_reflection.rb +0 -18
- data/hobo_files/plugin/lib/hobo/scopes/scoped_proxy.rb +0 -55
- data/hobo_files/plugin/taglib-docs/core.markdown +0 -165
- data/hobo_files/plugin/taglib-docs/rapid.markdown +0 -677
- data/hobo_files/plugin/taglib-docs/rapid_document_tags.markdown +0 -240
- data/hobo_files/plugin/taglib-docs/rapid_editing.markdown +0 -418
- data/hobo_files/plugin/taglib-docs/rapid_forms.markdown +0 -562
- data/hobo_files/plugin/taglib-docs/rapid_generics.markdown +0 -187
- data/hobo_files/plugin/taglib-docs/rapid_navigation.markdown +0 -214
- data/hobo_files/plugin/taglib-docs/rapid_pages.markdown +0 -530
- data/hobo_files/plugin/taglib-docs/rapid_plus.markdown +0 -65
- data/hobo_files/plugin/taglib-docs/rapid_support.markdown +0 -50
- data/hobo_files/plugin/taglib-docs/rapid_user_pages.markdown +0 -129
- data/hobo_files/plugin/taglibs/rapid_generics.dryml +0 -117
- data/hobo_files/plugin/taglibs/rapid_pages.dryml +0 -359
- data/hobo_files/plugin/taglibs/rapid_user_pages.dryml +0 -104
- data/hobo_files/plugin/tasks/dump_fixtures.rake +0 -70
- data/hobo_files/plugin/tasks/hobo_tasks.rake +0 -17
@@ -14,7 +14,7 @@ module Hobo::RapidHelper
|
|
14
14
|
|
15
15
|
def options_for_hobo_ajax(options)
|
16
16
|
js_options = rapid_build_callbacks(options)
|
17
|
-
|
17
|
+
|
18
18
|
js_options['asynchronous'] = false if options[:type] == :synchronous
|
19
19
|
js_options['method'] = method_option_to_s(options[:method]) if options[:method]
|
20
20
|
js_options['evalScripts'] = false if options[:script] == false
|
@@ -25,11 +25,11 @@ module Hobo::RapidHelper
|
|
25
25
|
js_options['refocusForm'] = options[:refocus_form] if options.has_key?(:refocus_form)
|
26
26
|
js_options['spinnerNextTo'] = js_str(options[:spinner_next_to]) if options.has_key?(:spinner_next_to)
|
27
27
|
js_options['message'] = js_str(options[:message]) if options[:message]
|
28
|
-
|
28
|
+
|
29
29
|
js_options.empty? ? nil : options_for_javascript(js_options)
|
30
30
|
end
|
31
31
|
|
32
|
-
|
32
|
+
|
33
33
|
def js_updates(updates)
|
34
34
|
return '[]' unless updates
|
35
35
|
updates = [updates] unless updates.is_a? Array
|
@@ -42,8 +42,8 @@ module Hobo::RapidHelper
|
|
42
42
|
end
|
43
43
|
"[#{updates * ', '}]"
|
44
44
|
end
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
|
47
47
|
def js_result_updates(updates)
|
48
48
|
return '[]' unless updates
|
49
49
|
updates = [updates] unless updates.is_a? Array
|
@@ -55,7 +55,7 @@ module Hobo::RapidHelper
|
|
55
55
|
def ajax_updater(url_or_form, update, options={})
|
56
56
|
options ||= {}
|
57
57
|
options.symbolize_keys!
|
58
|
-
|
58
|
+
|
59
59
|
target = if url_or_form == :post_form
|
60
60
|
target = "this"
|
61
61
|
else
|
@@ -63,9 +63,9 @@ module Hobo::RapidHelper
|
|
63
63
|
end
|
64
64
|
js_options = options_for_hobo_ajax(options)
|
65
65
|
args = [target, js_updates(update), js_options].compact
|
66
|
-
|
66
|
+
|
67
67
|
confirm = options.delete(:confirm)
|
68
|
-
|
68
|
+
|
69
69
|
func = "Hobo.ajaxRequest(#{args * ', '})"
|
70
70
|
if confirm
|
71
71
|
"if (confirm(#{js_str(confirm)})) { #{func} }"
|
@@ -91,26 +91,25 @@ module Hobo::RapidHelper
|
|
91
91
|
|
92
92
|
|
93
93
|
|
94
|
-
|
95
|
-
def in_place_editor(
|
94
|
+
|
95
|
+
def in_place_editor(attributes)
|
96
96
|
blank_message = attributes.delete(:blank_message) || "(click to edit)"
|
97
97
|
|
98
|
-
attributes = add_classes(attributes, behaviour_class)
|
99
|
-
attributes.update(:
|
100
|
-
:hobo_blank_message => blank_message,
|
98
|
+
attributes = add_classes(attributes, behaviour_class, model_id_class(this_parent, this_field))
|
99
|
+
attributes.update(:hobo_blank_message => blank_message,
|
101
100
|
:if_blank => blank_message,
|
102
101
|
:no_wrapper => false)
|
103
102
|
|
104
103
|
update = attributes.delete(:update)
|
105
|
-
attributes[:hobo_update] = update if update
|
106
|
-
|
104
|
+
attributes[:hobo_update] = update if update
|
105
|
+
|
107
106
|
view(attributes)
|
108
107
|
end
|
109
|
-
|
110
|
-
|
108
|
+
|
109
|
+
|
111
110
|
|
112
111
|
AJAX_CALLBACKS = [ :before, :success, :failure, :complete ]
|
113
|
-
|
112
|
+
|
114
113
|
AJAX_ATTRS = AJAX_CALLBACKS + [ :type, :method,
|
115
114
|
:script, :form, :params, :confirm, :message,
|
116
115
|
:reset_form, :refocus_form, :result_update, :spinner_next_to ]
|
@@ -121,27 +120,35 @@ module Hobo::RapidHelper
|
|
121
120
|
|
122
121
|
|
123
122
|
def through_collection_names(object=this)
|
124
|
-
object.class.reflections.values.select do |refl|
|
123
|
+
object.class.reflections.values.select do |refl|
|
125
124
|
refl.macro == :has_many && refl.options[:through]
|
126
125
|
end.map {|x| x.options[:through]}
|
127
126
|
end
|
128
127
|
|
129
128
|
|
130
129
|
def primary_collection_name(object=this)
|
131
|
-
dependent_collection_names = object.class.reflections.values.select do |refl|
|
130
|
+
dependent_collection_names = object.class.reflections.values.select do |refl|
|
132
131
|
refl.macro == :has_many && refl.options[:dependent]
|
133
132
|
end.*.name
|
134
|
-
|
133
|
+
|
135
134
|
(dependent_collection_names - through_collection_names(object)).first
|
136
135
|
end
|
137
136
|
|
138
137
|
|
139
138
|
def non_through_collections(object=this)
|
140
|
-
names = object.class.reflections.values.select do |refl|
|
139
|
+
names = object.class.reflections.values.select do |refl|
|
141
140
|
refl.macro == :has_many
|
142
141
|
end.*.name
|
143
|
-
|
142
|
+
|
144
143
|
names - through_collection_names
|
145
144
|
end
|
146
145
|
|
146
|
+
def standard_fields(model, include_timestamps=false)
|
147
|
+
fields = model.attr_order.*.to_s & model.content_columns.*.name
|
148
|
+
fields -= %w{created_at updated_at created_on updated_on deleted_at} unless include_timestamps
|
149
|
+
debugger if model == User
|
150
|
+
fields.reject! { |f| model.never_show? f }
|
151
|
+
fields
|
152
|
+
end
|
153
|
+
|
147
154
|
end
|
@@ -1,67 +1,19 @@
|
|
1
1
|
module Hobo
|
2
|
-
|
2
|
+
|
3
3
|
module Scopes
|
4
|
-
|
4
|
+
|
5
5
|
def self.included_in_class(base)
|
6
6
|
base.extend(ClassMethods)
|
7
|
-
|
8
|
-
class << base
|
9
|
-
alias_method_chain :has_many, :defined_scopes
|
10
|
-
end
|
11
7
|
end
|
12
|
-
|
8
|
+
|
13
9
|
module ClassMethods
|
14
|
-
|
10
|
+
|
15
11
|
include AutomaticScopes
|
16
|
-
|
17
|
-
include ApplyScopes
|
18
|
-
|
19
|
-
def defined_scopes
|
20
|
-
@defined_scopes ||= {}
|
21
|
-
end
|
22
|
-
|
23
|
-
|
24
|
-
def def_scope(name, scope=nil, &block)
|
25
|
-
defined_scopes[name.to_sym] = block || scope
|
26
|
-
|
27
|
-
meta_def(name) do |*args|
|
28
|
-
ScopedProxy.new(self, block ? block.call(*args) : scope)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
|
33
|
-
def apply_scopes(scopes)
|
34
|
-
result = self
|
35
|
-
scopes.each_pair do |scope, arg|
|
36
|
-
if arg.is_a?(Array)
|
37
|
-
result = result.send(scope, *arg) unless arg.first.blank?
|
38
|
-
else
|
39
|
-
result = result.send(scope, arg) unless arg.blank?
|
40
|
-
end
|
41
|
-
end
|
42
|
-
result
|
43
|
-
end
|
44
12
|
|
45
|
-
|
46
|
-
def alias_scope(new_name, old_name)
|
47
|
-
metaclass.send(:alias_method, new_name, old_name)
|
48
|
-
defined_scopes[new_name] = defined_scopes[old_name]
|
49
|
-
end
|
50
|
-
|
51
|
-
|
52
|
-
def has_many_with_defined_scopes(name, options={}, &block)
|
53
|
-
if options.has_key?(:extend) || block
|
54
|
-
# Normal has_many
|
55
|
-
has_many_without_defined_scopes(name, options, &block)
|
56
|
-
else
|
57
|
-
options[:extend] = Hobo::Scopes::DefinedScopeProxyExtender
|
58
|
-
has_many_without_defined_scopes(name, options, &block)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
13
|
+
include ApplyScopes
|
62
14
|
|
63
15
|
# --- monkey-patches to allow :scope key on has_many, has_one and belongs_to ---
|
64
|
-
|
16
|
+
|
65
17
|
def create_has_many_reflection(association_id, options, &extension)
|
66
18
|
options.assert_valid_keys(
|
67
19
|
:class_name, :table_name, :foreign_key,
|
@@ -69,44 +21,46 @@ module Hobo
|
|
69
21
|
:select, :conditions, :include, :order, :group, :limit, :offset,
|
70
22
|
:as, :through, :source, :source_type,
|
71
23
|
:uniq,
|
72
|
-
:finder_sql, :counter_sql,
|
73
|
-
:before_add, :after_add, :before_remove, :after_remove,
|
24
|
+
:finder_sql, :counter_sql,
|
25
|
+
:before_add, :after_add, :before_remove, :after_remove,
|
74
26
|
:extend,
|
75
27
|
:scope
|
76
|
-
)
|
77
|
-
|
28
|
+
)
|
29
|
+
|
78
30
|
options[:extend] = create_extension_modules(association_id, extension, options[:extend]) if block_given?
|
79
|
-
|
31
|
+
|
80
32
|
create_reflection(:has_many, association_id, options, self)
|
81
33
|
end
|
82
|
-
|
34
|
+
|
83
35
|
def create_has_one_reflection(association_id, options)
|
84
36
|
options.assert_valid_keys(
|
85
37
|
:class_name, :foreign_key, :remote, :conditions, :order, :include, :dependent, :counter_cache, :extend, :as, :scope
|
86
38
|
)
|
87
|
-
|
39
|
+
|
88
40
|
create_reflection(:has_one, association_id, options, self)
|
89
41
|
end
|
90
|
-
|
42
|
+
|
91
43
|
def create_belongs_to_reflection(association_id, options)
|
92
44
|
options.assert_valid_keys(
|
93
|
-
:class_name, :foreign_key, :foreign_type, :remote, :conditions, :order, :include, :dependent,
|
45
|
+
:class_name, :foreign_key, :foreign_type, :remote, :conditions, :order, :include, :dependent,
|
94
46
|
:counter_cache, :extend, :polymorphic, :scope
|
95
47
|
)
|
96
|
-
|
48
|
+
|
97
49
|
reflection = create_reflection(:belongs_to, association_id, options, self)
|
98
|
-
|
50
|
+
|
99
51
|
if options[:polymorphic]
|
100
52
|
reflection.options[:foreign_type] ||= reflection.class_name.underscore + "_type"
|
101
53
|
end
|
102
|
-
|
54
|
+
|
103
55
|
reflection
|
104
56
|
end
|
105
57
|
|
106
58
|
end
|
107
|
-
|
59
|
+
|
108
60
|
end
|
109
|
-
|
61
|
+
|
110
62
|
end
|
111
63
|
|
112
64
|
ActiveRecord::Associations::AssociationProxy.send(:include, Hobo::Scopes::AssociationProxyExtensions)
|
65
|
+
ActiveRecord::Associations::HasManyThroughAssociation.send(:include, Hobo::Scopes::HasManyThroughAssociationExtensions)
|
66
|
+
require "hobo/scopes/named_scope_extensions"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Add support for :scope => :my_scope to has_many and belongs_to
|
2
|
+
|
3
|
+
module Hobo
|
4
|
+
|
5
|
+
module Scopes
|
6
|
+
|
7
|
+
AssociationProxyExtensions = classy_module do
|
8
|
+
|
9
|
+
def scope_conditions(reflection)
|
10
|
+
scope_name = reflection.options[:scope] and
|
11
|
+
target_class = reflection.klass and
|
12
|
+
target_class.send(scope_name).scope(:find)[:conditions]
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
def combine_conditions(*conditions)
|
17
|
+
parts = conditions.compact.map { |c| "(#{sanitize_sql c})" }
|
18
|
+
parts.empty? ? nil : parts.join(" AND ")
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def conditions_with_hobo_scopes
|
23
|
+
scope_conditions = self.scope_conditions(@reflection)
|
24
|
+
unscoped_conditions = conditions_without_hobo_scopes
|
25
|
+
combine_conditions(scope_conditions, unscoped_conditions)
|
26
|
+
end
|
27
|
+
|
28
|
+
alias_method_chain :conditions, :hobo_scopes
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
HasManyThroughAssociationExtensions = classy_module do
|
33
|
+
|
34
|
+
def sql_conditions_with_hobo_scopes
|
35
|
+
scope_conditions = self.scope_conditions(@reflection)
|
36
|
+
through_scope_conditions = self.scope_conditions(@reflection.through_reflection)
|
37
|
+
unscoped_conditions = sql_conditions_without_hobo_scopes
|
38
|
+
combine_conditions(scope_conditions, through_scope_conditions, unscoped_conditions)
|
39
|
+
end
|
40
|
+
|
41
|
+
alias_method_chain :sql_conditions, :hobo_scopes
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -1,37 +1,39 @@
|
|
1
1
|
module Hobo
|
2
|
-
|
2
|
+
|
3
3
|
module Scopes
|
4
|
-
|
4
|
+
|
5
5
|
module AutomaticScopes
|
6
|
-
|
6
|
+
|
7
7
|
def create_automatic_scope(name)
|
8
8
|
ScopeBuilder.new(self, name).create_scope
|
9
|
-
rescue ActiveRecord::StatementInvalid
|
9
|
+
rescue ActiveRecord::StatementInvalid => e
|
10
10
|
# Problem with the database? Don't try to create automatic scopes
|
11
|
+
ActiveRecord::Base.logger.warn "!! Database exception during hobo auto-scope creation -- continuing automatic scopes"
|
12
|
+
ActiveRecord::Base.logger.warn "!! #{e.to_s}"
|
11
13
|
false
|
12
14
|
end
|
13
|
-
|
15
|
+
|
14
16
|
end
|
15
|
-
|
17
|
+
|
16
18
|
# The methods on this module add scopes to the given class
|
17
19
|
class ScopeBuilder
|
18
|
-
|
20
|
+
|
19
21
|
def initialize(klass, name)
|
20
22
|
@klass = klass
|
21
23
|
@name = name.to_s
|
22
24
|
end
|
23
|
-
|
25
|
+
|
24
26
|
attr_reader :name
|
25
|
-
|
27
|
+
|
26
28
|
def create_scope
|
27
29
|
matched_scope = true
|
28
|
-
|
29
|
-
|
30
|
+
|
31
|
+
|
30
32
|
# --- Association Queries --- #
|
31
|
-
|
33
|
+
|
32
34
|
# with_players(player1, player2)
|
33
35
|
if name =~ /^with_(.*)/ && (refl = reflection($1))
|
34
|
-
|
36
|
+
|
35
37
|
def_scope do |*records|
|
36
38
|
records = records.flatten.compact.map {|r| find_if_named(refl, r) }
|
37
39
|
exists_sql = ([exists_sql_condition(refl)] * records.length).join(" AND ")
|
@@ -40,16 +42,16 @@ module Hobo
|
|
40
42
|
|
41
43
|
# with_player(a_player)
|
42
44
|
elsif name =~ /^with_(.*)/ && (refl = reflection($1.pluralize))
|
43
|
-
|
45
|
+
|
44
46
|
exists_sql = exists_sql_condition(refl)
|
45
47
|
def_scope do |record|
|
46
48
|
record = find_if_named(refl, record)
|
47
49
|
{ :conditions => [exists_sql, record] }
|
48
50
|
end
|
49
|
-
|
51
|
+
|
50
52
|
# without_players(player1, player2)
|
51
53
|
elsif name =~ /^without_(.*)/ && (refl = reflection($1))
|
52
|
-
|
54
|
+
|
53
55
|
def_scope do |*records|
|
54
56
|
records = records.flatten.compact.map {|r| find_if_named(refl, r) }
|
55
57
|
exists_sql = ([exists_sql_condition(refl)] * records.length).join(" AND ")
|
@@ -58,7 +60,7 @@ module Hobo
|
|
58
60
|
|
59
61
|
# without_player(a_player)
|
60
62
|
elsif name =~ /^without_(.*)/ && (refl = reflection($1.pluralize))
|
61
|
-
|
63
|
+
|
62
64
|
exists_sql = exists_sql_condition(refl)
|
63
65
|
def_scope do |record|
|
64
66
|
record = find_if_named(refl, record)
|
@@ -67,7 +69,7 @@ module Hobo
|
|
67
69
|
|
68
70
|
# team_is(a_team)
|
69
71
|
elsif name =~ /^(.*)_is$/ && (refl = reflection($1)) && refl.macro.in?([:has_one, :belongs_to])
|
70
|
-
|
72
|
+
|
71
73
|
if refl.options[:polymorphic]
|
72
74
|
def_scope do |record|
|
73
75
|
record = find_if_named(refl, record)
|
@@ -79,10 +81,10 @@ module Hobo
|
|
79
81
|
{ :conditions => ["#{foreign_key_column refl} = ?", record] }
|
80
82
|
end
|
81
83
|
end
|
82
|
-
|
83
|
-
#
|
84
|
+
|
85
|
+
# team_is_not(a_team)
|
84
86
|
elsif name =~ /^(.*)_is_not$/ && (refl = reflection($1)) && refl.macro.in?([:has_one, :belongs_to])
|
85
|
-
|
87
|
+
|
86
88
|
if refl.options[:polymorphic]
|
87
89
|
def_scope do |record|
|
88
90
|
record = find_if_named(refl, record)
|
@@ -94,87 +96,83 @@ module Hobo
|
|
94
96
|
{ :conditions => ["#{foreign_key_column refl} <> ?", record] }
|
95
97
|
end
|
96
98
|
end
|
97
|
-
|
98
|
-
|
99
|
+
|
100
|
+
|
99
101
|
# --- Column Queries --- #
|
100
|
-
|
102
|
+
|
101
103
|
# name_is(str)
|
102
104
|
elsif name =~ /^(.*)_is$/ && (col = column($1))
|
103
105
|
|
104
106
|
def_scope do |str|
|
105
107
|
{ :conditions => ["#{column_sql(col)} = ?", str] }
|
106
108
|
end
|
107
|
-
|
109
|
+
|
108
110
|
# name_is_not(str)
|
109
111
|
elsif name =~ /^(.*)_is_not$/ && (col = column($1))
|
110
112
|
|
111
113
|
def_scope do |str|
|
112
114
|
{ :conditions => ["#{column_sql(col)} <> ?", str] }
|
113
115
|
end
|
114
|
-
|
116
|
+
|
115
117
|
# name_contains(str)
|
116
118
|
elsif name =~ /^(.*)_contains$/ && (col = column($1))
|
117
119
|
|
118
120
|
def_scope do |str|
|
119
121
|
{ :conditions => ["#{column_sql(col)} LIKE ?", "%#{str}%"] }
|
120
122
|
end
|
121
|
-
|
123
|
+
|
122
124
|
# name_does_not_contain
|
123
125
|
elsif name =~ /^(.*)_does_not_contain$/ && (col = column($1))
|
124
126
|
|
125
127
|
def_scope do |str|
|
126
128
|
{ :conditions => ["#{column_sql(col)} NOT LIKE ?", "%#{str}%"] }
|
127
129
|
end
|
128
|
-
|
130
|
+
|
129
131
|
# name_starts(str)
|
130
|
-
elsif name =~ /^(.*)
|
132
|
+
elsif name =~ /^(.*)_starts$/ && (col = column($1))
|
131
133
|
|
132
134
|
def_scope do |str|
|
133
135
|
{ :conditions => ["#{column_sql(col)} LIKE ?", "#{str}%"] }
|
134
136
|
end
|
135
|
-
|
137
|
+
|
136
138
|
# name_does_not_start
|
137
|
-
elsif name =~ /^(.*)
|
139
|
+
elsif name =~ /^(.*)_does_not_start$/ && (col = column($1))
|
138
140
|
|
139
141
|
def_scope do |str|
|
140
142
|
{ :conditions => ["#{column_sql(col)} NOT LIKE ?", "#{str}%"] }
|
141
143
|
end
|
142
|
-
|
144
|
+
|
143
145
|
# name_ends(str)
|
144
|
-
elsif name =~ /^(.*)
|
146
|
+
elsif name =~ /^(.*)_ends$/ && (col = column($1))
|
145
147
|
|
146
148
|
def_scope do |str|
|
147
149
|
{ :conditions => ["#{column_sql(col)} LIKE ?", "%#{str}"] }
|
148
150
|
end
|
149
|
-
|
151
|
+
|
150
152
|
# name_does_not_end(str)
|
151
|
-
elsif name =~ /^(.*)
|
153
|
+
elsif name =~ /^(.*)_does_not_end$/ && (col = column($1))
|
152
154
|
|
153
155
|
def_scope do |str|
|
154
156
|
{ :conditions => ["#{column_sql(col)} NOT LIKE ?", "%#{str}"] }
|
155
157
|
end
|
156
|
-
|
157
|
-
# published
|
158
|
+
|
159
|
+
# published (a boolean column)
|
158
160
|
elsif (col = column(name)) && (col.type == :boolean)
|
159
161
|
|
160
|
-
def_scope
|
161
|
-
|
162
|
-
end
|
163
|
-
|
162
|
+
def_scope :conditions => ["#{column_sql(col)} = ?", true]
|
163
|
+
|
164
164
|
# not_published
|
165
165
|
elsif name =~ /^not_(.*)$/ && (col = column($1)) && (col.type == :boolean)
|
166
166
|
|
167
|
-
def_scope
|
168
|
-
|
169
|
-
end
|
170
|
-
|
167
|
+
def_scope :conditions => ["#{column_sql(col)} <> ?", true]
|
168
|
+
|
171
169
|
# published_before(time)
|
172
170
|
elsif name =~ /^(.*)_before$/ && (col = column("#{$1}_at")) && col.type.in?([:date, :datetime, :time, :timestamp])
|
173
171
|
|
174
172
|
def_scope do |time|
|
175
173
|
{ :conditions => ["#{column_sql(col)} < ?", time] }
|
176
174
|
end
|
177
|
-
|
175
|
+
|
178
176
|
# published_after(time)
|
179
177
|
elsif name =~ /^(.*)_after$/ && (col = column("#{$1}_at")) && col.type.in?([:date, :datetime, :time, :timestamp])
|
180
178
|
|
@@ -186,19 +184,46 @@ module Hobo
|
|
186
184
|
elsif name =~ /^(.*)_between$/ && (col = column("#{$1}_at")) && col.type.in?([:date, :datetime, :time, :timestamp])
|
187
185
|
|
188
186
|
def_scope do |time1, time2|
|
189
|
-
{ :conditions => ["#{column_sql(col)} >= ? AND #{column_sql(col)}
|
187
|
+
{ :conditions => ["#{column_sql(col)} >= ? AND #{column_sql(col)} <= ?", time1, time2] }
|
188
|
+
end
|
189
|
+
|
190
|
+
# active (a lifecycle state)
|
191
|
+
elsif @klass.has_lifecycle? && name.in?(@klass::Lifecycle.state_names)
|
192
|
+
|
193
|
+
if @klass::Lifecycle.state_names.length == 1
|
194
|
+
# nothing to check for - create a dummy scope
|
195
|
+
def_scope :conditions => ""
|
196
|
+
true
|
197
|
+
else
|
198
|
+
def_scope :conditions => ["#{@klass.table_name}.#{@klass::Lifecycle.state_field} = ?", name]
|
199
|
+
end
|
200
|
+
|
201
|
+
# self is / is not
|
202
|
+
elsif name == "is"
|
203
|
+
|
204
|
+
def_scope do |record|
|
205
|
+
{ :conditions => ["#{@klass.table_name}.#{@klass.primary_key} = ?", record] }
|
206
|
+
end
|
207
|
+
|
208
|
+
elsif name == "is_not"
|
209
|
+
|
210
|
+
def_scope do |record|
|
211
|
+
{ :conditions => ["#{@klass.table_name}.#{@klass.primary_key} <> ?", record] }
|
190
212
|
end
|
191
213
|
|
192
214
|
else
|
193
|
-
|
215
|
+
|
194
216
|
case name
|
195
217
|
|
218
|
+
when "by_most_recent"
|
219
|
+
def_scope :order => "#{@klass.table_name}.created_at DESC"
|
220
|
+
|
196
221
|
when "recent"
|
197
222
|
def_scope do |*args|
|
198
223
|
count = args.first || 3
|
199
224
|
{ :limit => count, :order => "#{@klass.table_name}.created_at DESC" }
|
200
225
|
end
|
201
|
-
|
226
|
+
|
202
227
|
when "limit"
|
203
228
|
def_scope do |count|
|
204
229
|
{ :limit => count }
|
@@ -217,40 +242,40 @@ module Hobo
|
|
217
242
|
end
|
218
243
|
{ :order => "#{colspec} #{asc._?.upcase}", :include => include }
|
219
244
|
end
|
220
|
-
|
245
|
+
|
221
246
|
|
222
247
|
when "include"
|
223
248
|
def_scope do |inclusions|
|
224
249
|
{ :include => inclusions }
|
225
250
|
end
|
226
|
-
|
251
|
+
|
227
252
|
when "search"
|
228
253
|
def_scope do |query, *fields|
|
229
254
|
words = query.split
|
230
|
-
args = []
|
255
|
+
args = []
|
231
256
|
word_queries = words.map do |word|
|
232
257
|
field_query = '(' + fields.map { |field| "(#{@klass.table_name}.#{field} like ?)" }.join(" OR ") + ')'
|
233
258
|
args += ["%#{word}%"] * fields.length
|
234
259
|
field_query
|
235
260
|
end
|
236
|
-
|
237
|
-
{ :conditions => [word_queries.join("
|
261
|
+
|
262
|
+
{ :conditions => [word_queries.join(" AND ")] + args }
|
238
263
|
end
|
239
|
-
|
264
|
+
|
240
265
|
else
|
241
266
|
matched_scope = false
|
242
267
|
end
|
243
|
-
|
268
|
+
|
244
269
|
end
|
245
270
|
matched_scope
|
246
271
|
end
|
247
|
-
|
248
|
-
|
272
|
+
|
273
|
+
|
249
274
|
def column_sql(column)
|
250
275
|
"#{@klass.table_name}.#{column.name}"
|
251
276
|
end
|
252
|
-
|
253
|
-
|
277
|
+
|
278
|
+
|
254
279
|
def exists_sql_condition(reflection)
|
255
280
|
owner = @klass
|
256
281
|
owner_primary_key = "#{owner.table_name}.#{owner.primary_key}"
|
@@ -258,55 +283,55 @@ module Hobo
|
|
258
283
|
join_table = reflection.through_reflection.klass.table_name
|
259
284
|
source_fkey = reflection.source_reflection.primary_key_name
|
260
285
|
owner_fkey = reflection.through_reflection.primary_key_name
|
261
|
-
"EXISTS (SELECT * FROM #{join_table} " +
|
286
|
+
"EXISTS (SELECT * FROM #{join_table} " +
|
262
287
|
"WHERE #{join_table}.#{source_fkey} = ? AND #{join_table}.#{owner_fkey} = #{owner_primary_key})"
|
263
288
|
else
|
264
289
|
related = reflection.klass
|
265
290
|
foreign_key = reflection.primary_key_name
|
266
|
-
|
267
|
-
"EXISTS (SELECT * FROM #{related.table_name} " +
|
291
|
+
|
292
|
+
"EXISTS (SELECT * FROM #{related.table_name} " +
|
268
293
|
"WHERE #{related.table_name}.#{foreign_key} = #{owner_primary_key} AND " +
|
269
294
|
"#{related.table_name}.#{related.primary_key} = ?)"
|
270
295
|
end
|
271
296
|
end
|
272
|
-
|
273
|
-
|
297
|
+
|
298
|
+
|
274
299
|
def find_if_named(reflection, string_or_record)
|
275
300
|
if string_or_record.is_a?(String)
|
276
301
|
name = string_or_record
|
277
302
|
reflection.klass.named(name)
|
278
303
|
else
|
279
|
-
string_or_record
|
304
|
+
string_or_record # a record
|
280
305
|
end
|
281
306
|
end
|
282
|
-
|
283
|
-
|
307
|
+
|
308
|
+
|
284
309
|
def column(name)
|
285
310
|
@klass.column(name)
|
286
311
|
end
|
287
|
-
|
288
|
-
|
312
|
+
|
313
|
+
|
289
314
|
def reflection(name)
|
290
315
|
@klass.reflections[name.to_sym]
|
291
316
|
end
|
292
|
-
|
293
|
-
|
317
|
+
|
318
|
+
|
294
319
|
def def_scope(options={}, &block)
|
295
|
-
@klass.
|
320
|
+
@klass.named_scope(name.to_sym, block || options)
|
296
321
|
end
|
297
322
|
|
298
|
-
|
323
|
+
|
299
324
|
def primary_key_column(refl)
|
300
325
|
"#{refl.klass.table_name}.#{refl.klass.primary_key}"
|
301
326
|
end
|
302
|
-
|
303
|
-
|
327
|
+
|
328
|
+
|
304
329
|
def foreign_key_column(refl)
|
305
330
|
"#{@klass.table_name}.#{refl.primary_key_name}"
|
306
331
|
end
|
307
|
-
|
332
|
+
|
308
333
|
end
|
309
|
-
|
334
|
+
|
310
335
|
end
|
311
|
-
|
336
|
+
|
312
337
|
end
|