hobo 1.1.0 → 1.3.0.RC
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.txt +238 -287
- data/Rakefile +14 -31
- data/VERSION +1 -0
- data/{lib/hobo → app/controllers}/dev_controller.rb +6 -6
- data/app/controllers/dryml_support_controller.rb +13 -0
- data/{rails_generators/hobo_front_controller/templates → app/views/dev}/summary.dryml +7 -10
- data/bin/hobo +12 -144
- data/config/initializers/inflections.rb +3 -0
- data/config/routes.rb +6 -0
- data/{doctest → doctests}/hobo/lifecycles.rdoctest +40 -59
- data/{doctest → doctests/hobo}/model.rdoctest +33 -40
- data/{doctest → doctests/hobo}/multi_model_forms.rdoctest +15 -19
- data/{doctest → doctests/hobo}/scopes.rdoctest +27 -41
- data/doctests/prepare_testapp.rb +8 -0
- data/hobo.gemspec +26 -199
- data/lib/generators/hobo/activation_email.rb +11 -0
- data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +35 -0
- data/lib/generators/hobo/admin_subsite/templates/admin.css +20 -0
- data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +10 -0
- data/{rails_generators/hobo_admin_site → lib/generators/hobo/admin_subsite}/templates/application.dryml +0 -0
- data/{rails_generators/hobo_admin_site/templates/controller.rb → lib/generators/hobo/admin_subsite/templates/controller.rb.erb} +5 -5
- data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +7 -0
- data/lib/generators/hobo/assets/assets_generator.rb +18 -0
- data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/application.css +0 -0
- data/lib/generators/hobo/assets/templates/application.dryml.erb +9 -0
- data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/dryml-support.js +2 -2
- data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +1 -0
- data/lib/generators/hobo/assets/templates/en_injection.yml +19 -0
- data/{rails_generators/hobo → lib/generators/hobo/assets}/templates/guest.rb +1 -1
- data/lib/generators/hobo/controller.rb +35 -0
- data/lib/generators/hobo/controller/controller_generator.rb +6 -0
- data/lib/generators/hobo/controller/templates/controller.rb.erb +7 -0
- data/{rails_generators/hobo_front_controller → lib/generators/hobo/front_controller}/USAGE +0 -0
- data/lib/generators/hobo/front_controller/front_controller_generator.rb +55 -0
- data/{rails_generators/hobo_front_controller/templates/controller.rb → lib/generators/hobo/front_controller/templates/controller.rb.erb} +0 -0
- data/{rails_generators/hobo_front_controller → lib/generators/hobo/front_controller}/templates/index.dryml +6 -12
- data/lib/generators/hobo/i18n/i18n_generator.rb +35 -0
- data/lib/generators/hobo/i18n/templates/app.de.yml +30 -0
- data/lib/generators/hobo/i18n/templates/app.en.yml +25 -0
- data/lib/generators/hobo/i18n/templates/app.es.yml +31 -0
- data/lib/generators/hobo/i18n/templates/app.fr.yml +26 -0
- data/lib/generators/hobo/i18n/templates/app.it.yml +28 -0
- data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +25 -0
- data/lib/generators/hobo/i18n/templates/app.ru.yml +24 -0
- data/lib/generators/hobo/i18n/templates/hobo.de.yml +204 -0
- data/lib/generators/hobo/i18n/templates/hobo.en.yml +195 -0
- data/lib/generators/hobo/i18n/templates/hobo.es.yml +202 -0
- data/lib/generators/hobo/i18n/templates/hobo.fr.yml +195 -0
- data/lib/generators/hobo/i18n/templates/hobo.it.yml +202 -0
- data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +196 -0
- data/lib/generators/hobo/i18n/templates/hobo.ru.yml +200 -0
- data/lib/generators/hobo/invite_only.rb +18 -0
- data/lib/generators/hobo/model/USAGE +19 -0
- data/lib/generators/hobo/model/model_generator.rb +11 -0
- data/{rails_generators/hobo_model/templates/model.rb → lib/generators/hobo/model/templates/model_injection.rb.erb} +0 -2
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/USAGE +0 -0
- data/lib/generators/hobo/rapid/rapid_generator.rb +24 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/IE7.js +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/blank.gif +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/hobo-rapid.css +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/hobo-rapid.js +65 -65
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/ie7-recalc.js +21 -21
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/lowpro.js +31 -31
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/reset.css +1 -1
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
- data/{rails_generators/hobo_rapid/templates/themes/clean → lib/generators/hobo/rapid/templates/themes/clean-sidemenu}/public/images/spinner.gif +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +81 -0
- data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +30 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/101-3B5F87-ACD3E6.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/30-3E547A-242E42.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/30-DBE1E5-FCFEF5.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/300-ACD3E6-fff.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/50-ACD3E6-fff.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/fieldbg.gif +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/pencil.png +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/images/small_close.png +0 -0
- data/lib/generators/hobo/rapid/templates/themes/clean/public/images/spinner.gif +0 -0
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/stylesheets/clean.css +16 -16
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
- data/{rails_generators/hobo_rapid → lib/generators/hobo/rapid}/templates/themes/clean/views/clean.dryml +1 -1
- data/lib/generators/hobo/resource/resource_generator.rb +23 -0
- data/lib/generators/hobo/routes/USAGE +9 -0
- data/lib/generators/hobo/routes/router.rb +115 -0
- data/lib/generators/hobo/routes/routes_generator.rb +40 -0
- data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +33 -0
- data/lib/generators/hobo/setup_wizard/USAGE +4 -0
- data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +274 -0
- data/lib/generators/hobo/subsite.rb +48 -0
- data/lib/generators/hobo/subsite/subsite_generator.rb +16 -0
- data/{rails_generators/hobo_subsite → lib/generators/hobo/subsite}/templates/application.dryml +0 -0
- data/{rails_generators/hobo_subsite/templates/controller.rb → lib/generators/hobo/subsite/templates/controller.rb.erb} +1 -1
- data/lib/generators/hobo/subsite_taglib/subsite_taglib_generator.rb +16 -0
- data/{rails_generators/hobo_admin_site/templates/site_taglib.dryml → lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb} +9 -10
- data/lib/generators/hobo/taglib.rb +12 -0
- data/lib/generators/hobo/test_framework/test_framework_generator.rb +72 -0
- data/lib/generators/hobo/test_options.rb +19 -0
- data/{rails_generators/hobo_user_controller → lib/generators/hobo/user_controller}/templates/accept_invitation.dryml +0 -0
- data/lib/generators/hobo/user_controller/templates/controller.rb.erb +31 -0
- data/lib/generators/hobo/user_controller/user_controller_generator.rb +25 -0
- data/lib/generators/hobo/user_mailer/templates/activation.erb +9 -0
- data/{rails_generators/hobo_user_model → lib/generators/hobo/user_mailer}/templates/forgot_password.erb +2 -2
- data/{rails_generators/hobo_user_model → lib/generators/hobo/user_mailer}/templates/invite.erb +2 -2
- data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +25 -0
- data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +33 -0
- data/lib/generators/hobo/user_model/USAGE +12 -0
- data/{rails_generators/hobo_user_model/templates/model.rb → lib/generators/hobo/user_model/templates/model_injection.rb.erb} +40 -20
- data/lib/generators/hobo/user_model/user_model_generator.rb +23 -0
- data/lib/generators/hobo/user_resource/user_resource_generator.rb +27 -0
- data/lib/hobo.rb +29 -129
- data/lib/hobo/controller.rb +37 -47
- data/lib/hobo/controller/authentication_support.rb +109 -0
- data/lib/hobo/{model_controller.rb → controller/model.rb} +71 -79
- data/lib/hobo/{user_controller.rb → controller/user.rb} +59 -49
- data/lib/hobo/engine.rb +80 -0
- data/lib/hobo/extensions/action_controller/hobo_methods.rb +44 -0
- data/lib/hobo/extensions/action_mailer/helper.rb +38 -0
- data/lib/{action_view_extensions/helpers → hobo/extensions/action_view}/tag_helper.rb +5 -2
- data/lib/hobo/extensions/action_view/translation_helper.rb +25 -0
- data/lib/hobo/extensions/active_model/name.rb +16 -0
- data/lib/hobo/extensions/active_model/translation.rb +35 -0
- data/lib/{active_record/association_collection.rb → hobo/extensions/active_record/associations/collection.rb} +8 -17
- data/lib/{active_record/association_proxy.rb → hobo/extensions/active_record/associations/proxy.rb} +6 -7
- data/lib/hobo/extensions/active_record/associations/reflection.rb +23 -0
- data/lib/hobo/extensions/active_record/associations/scope.rb +35 -0
- data/lib/hobo/extensions/active_record/hobo_methods.rb +11 -0
- data/lib/hobo/extensions/active_record/permissions.rb +159 -0
- data/lib/hobo/extensions/active_record/relation_with_origin.rb +28 -0
- data/lib/hobo/extensions/array.rb +27 -0
- data/lib/hobo/extensions/enumerable.rb +12 -0
- data/lib/hobo/extensions/i18n.rb +17 -0
- data/lib/hobo/{hobo_helper.rb → helper.rb} +58 -31
- data/lib/hobo/helper/translations.rb +54 -0
- data/lib/hobo/helper/translations/normalizer.rb +39 -0
- data/lib/hobo/model.rb +61 -95
- data/lib/hobo/model/accessible_associations.rb +178 -0
- data/lib/hobo/{find_for.rb → model/find_for.rb} +17 -17
- data/lib/hobo/model/guest.rb +25 -0
- data/lib/hobo/model/include_in_save.rb +55 -0
- data/lib/hobo/model/lifecycles.rb +119 -0
- data/lib/hobo/model/lifecycles/actions.rb +146 -0
- data/lib/hobo/model/lifecycles/creator.rb +74 -0
- data/lib/hobo/model/lifecycles/lifecycle.rb +243 -0
- data/lib/hobo/model/lifecycles/state.rb +22 -0
- data/lib/hobo/model/lifecycles/transition.rb +70 -0
- data/lib/hobo/model/permissions.rb +448 -0
- data/lib/hobo/model/scopes.rb +38 -0
- data/lib/hobo/model/scopes/apply_scopes.rb +21 -0
- data/lib/hobo/model/scopes/automatic_scopes.rb +428 -0
- data/lib/hobo/model/user_base.rb +184 -0
- data/lib/hobo/model/view_hints.rb +123 -0
- data/{rapid_generators → lib/hobo/rapid/generators}/rapid/cards.dryml.erb +2 -2
- data/{rapid_generators → lib/hobo/rapid/generators}/rapid/forms.dryml.erb +3 -3
- data/{rapid_generators → lib/hobo/rapid/generators}/rapid/pages.dryml.erb +38 -51
- data/lib/hobo/rapid/helper.rb +166 -0
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid.dryml +6 -5
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_core.dryml +286 -118
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_document_tags.dryml +2 -2
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_editing.dryml +45 -45
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_forms.dryml +190 -158
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_generics.dryml +12 -9
- data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +107 -0
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_lifecycles.dryml +7 -7
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_navigation.dryml +15 -15
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_pages.dryml +37 -36
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_plus.dryml +107 -43
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_summary.dryml +28 -57
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_support.dryml +9 -9
- data/{taglibs → lib/hobo/rapid/taglibs}/rapid_user_pages.dryml +41 -40
- data/lib/hobo/routes.rb +31 -0
- data/{doctest → test/doctest}/hobo/hobo_helper.rdoctest +11 -11
- data/test/irt/generators/admin_subsite.irt +27 -0
- data/test/irt/generators/assets.irt +16 -0
- data/test/irt/generators/controller.irt +6 -0
- data/test/irt/generators/front_controller.irt +30 -0
- data/test/irt/generators/helper.rb +31 -0
- data/test/irt/generators/model.irt +28 -0
- data/test/irt/generators/partials/_account_user_model_tests.rb +21 -0
- data/test/irt/generators/partials/_accounts_users_controller_tests.rb +15 -0
- data/test/irt/generators/partials/_default_user_model_tests.rb +21 -0
- data/test/irt/generators/partials/_default_users_controller_tests.rb +16 -0
- data/test/irt/generators/partials/_house_controller_tests.rb +15 -0
- data/test/irt/generators/partials/_house_model_tests.rb +18 -0
- data/test/irt/generators/partials/_subsite_taglib_admin.rb +4 -0
- data/test/irt/generators/partials/_subsite_taglib_admin_invite_only.rb +3 -0
- data/test/irt/generators/partials/_subsite_taglib_noopt.rb +4 -0
- data/test/irt/generators/partials/_subsite_taglib_variables.rb +27 -0
- data/test/irt/generators/partials/_user_mailer_tests.rb +19 -0
- data/test/irt/generators/rapid.irt +29 -0
- data/test/irt/generators/resource.irt +8 -0
- data/test/irt/generators/subsite.irt +52 -0
- data/test/irt/generators/subsite_taglib.irt +23 -0
- data/test/irt/generators/test_framework.irt +62 -0
- data/test/irt/generators/user_controller.irt +10 -0
- data/test/irt/generators/user_mailer.irt +20 -0
- data/test/irt/generators/user_model.irt +10 -0
- data/test/irt/generators/user_resource.irt +14 -0
- data/test/irt/readme.txt +7 -0
- data/test/permissions/models/models.rb +27 -24
- data/test/permissions/test_permissions.rb +104 -104
- metadata +239 -217
- data/lib/active_record/association_reflection.rb +0 -20
- data/lib/active_record/viewhints_validations_interceptor.rb +0 -9
- data/lib/hobo/accessible_associations.rb +0 -183
- data/lib/hobo/authentication_support.rb +0 -131
- data/lib/hobo/generator.rb +0 -26
- data/lib/hobo/guest.rb +0 -25
- data/lib/hobo/include_in_save.rb +0 -55
- data/lib/hobo/lifecycles.rb +0 -137
- data/lib/hobo/lifecycles/actions.rb +0 -142
- data/lib/hobo/lifecycles/creator.rb +0 -72
- data/lib/hobo/lifecycles/lifecycle.rb +0 -249
- data/lib/hobo/lifecycles/state.rb +0 -22
- data/lib/hobo/lifecycles/transition.rb +0 -70
- data/lib/hobo/model_router.rb +0 -290
- data/lib/hobo/permissions.rb +0 -451
- data/lib/hobo/permissions/associations.rb +0 -175
- data/lib/hobo/rapid_helper.rb +0 -157
- data/lib/hobo/scopes.rb +0 -43
- data/lib/hobo/scopes/apply_scopes.rb +0 -23
- data/lib/hobo/scopes/association_proxy_extensions.rb +0 -62
- data/lib/hobo/scopes/automatic_scopes.rb +0 -421
- data/lib/hobo/scopes/named_scope_extensions.rb +0 -39
- data/lib/hobo/tasks/rails.rb +0 -4
- data/lib/hobo/translations.rb +0 -93
- data/lib/hobo/undefined_access_error.rb +0 -5
- data/lib/hobo/user.rb +0 -182
- data/lib/hobo/view_hints.rb +0 -115
- data/rails/init.rb +0 -10
- data/rails_generators/hobo/USAGE +0 -4
- data/rails_generators/hobo/hobo_generator.rb +0 -53
- data/rails_generators/hobo/templates/application.dryml +0 -1
- data/rails_generators/hobo/templates/initializer.rb +0 -2
- data/rails_generators/hobo_admin_site/USAGE +0 -16
- data/rails_generators/hobo_admin_site/hobo_admin_site_generator.rb +0 -45
- data/rails_generators/hobo_admin_site/templates/admin.css +0 -2
- data/rails_generators/hobo_admin_site/templates/users_index.dryml +0 -5
- data/rails_generators/hobo_front_controller/hobo_front_controller_generator.rb +0 -95
- data/rails_generators/hobo_front_controller/templates/functional_test.rb +0 -8
- data/rails_generators/hobo_front_controller/templates/helper.rb +0 -2
- data/rails_generators/hobo_model/USAGE +0 -25
- data/rails_generators/hobo_model/hobo_model_generator.rb +0 -43
- data/rails_generators/hobo_model/templates/fixtures.yml +0 -6
- data/rails_generators/hobo_model/templates/hints.rb +0 -7
- data/rails_generators/hobo_model/templates/unit_test.rb +0 -8
- data/rails_generators/hobo_model_controller/USAGE +0 -30
- data/rails_generators/hobo_model_controller/hobo_model_controller_generator.rb +0 -46
- data/rails_generators/hobo_model_controller/templates/controller.rb +0 -7
- data/rails_generators/hobo_model_controller/templates/functional_test.rb +0 -8
- data/rails_generators/hobo_model_controller/templates/helper.rb +0 -2
- data/rails_generators/hobo_model_resource/USAGE +0 -38
- data/rails_generators/hobo_model_resource/hobo_model_resource_generator.rb +0 -73
- data/rails_generators/hobo_model_resource/templates/controller.rb +0 -7
- data/rails_generators/hobo_model_resource/templates/functional_test.rb +0 -8
- data/rails_generators/hobo_model_resource/templates/helper.rb +0 -2
- data/rails_generators/hobo_rapid/hobo_rapid_generator.rb +0 -94
- data/rails_generators/hobo_subsite/USAGE +0 -16
- data/rails_generators/hobo_subsite/hobo_subsite_generator.rb +0 -73
- data/rails_generators/hobo_subsite/templates/site_taglib.dryml +0 -13
- data/rails_generators/hobo_user_controller/USAGE +0 -34
- data/rails_generators/hobo_user_controller/hobo_user_controller_generator.rb +0 -65
- data/rails_generators/hobo_user_controller/templates/controller.rb +0 -29
- data/rails_generators/hobo_user_controller/templates/functional_test.rb +0 -8
- data/rails_generators/hobo_user_controller/templates/helper.rb +0 -2
- data/rails_generators/hobo_user_model/USAGE +0 -16
- data/rails_generators/hobo_user_model/hobo_user_model_generator.rb +0 -46
- data/rails_generators/hobo_user_model/templates/fixtures.yml +0 -19
- data/rails_generators/hobo_user_model/templates/mailer.rb +0 -29
- data/rails_generators/hobo_user_model/templates/unit_test.rb +0 -8
- data/script/destroy +0 -14
- data/script/generate +0 -14
- data/taglibs/rapid_translations.dryml +0 -36
- data/tasks/environments.rake +0 -19
- data/tasks/hobo_tasks.rake +0 -58
- data/test/generators/test_generator_helper.rb +0 -29
- data/test/generators/test_helper.rb +0 -1
- data/test/generators/test_hobo_model_controller_generator.rb +0 -56
data/lib/hobo/lifecycles.rb
DELETED
@@ -1,137 +0,0 @@
|
|
1
|
-
module Hobo
|
2
|
-
|
3
|
-
module Lifecycles
|
4
|
-
|
5
|
-
class LifecycleError < RuntimeError; end
|
6
|
-
|
7
|
-
class LifecycleKeyError < LifecycleError; end
|
8
|
-
|
9
|
-
ModelExtensions = classy_module do
|
10
|
-
|
11
|
-
attr_writer :lifecycle
|
12
|
-
|
13
|
-
def self.has_lifecycle?
|
14
|
-
defined?(self::Lifecycle)
|
15
|
-
end
|
16
|
-
|
17
|
-
def self.lifecycle(*args, &block)
|
18
|
-
options = args.extract_options!
|
19
|
-
options = options.reverse_merge(:state_field => :state,
|
20
|
-
:key_timestamp_field => :key_timestamp,
|
21
|
-
:key_timeout => 999.years)
|
22
|
-
|
23
|
-
# use const_defined so that subclasses can define lifecycles
|
24
|
-
# TODO: figure out how to merge with parent, if desired
|
25
|
-
if self.const_defined?(:Lifecycle)
|
26
|
-
lifecycle = self::Lifecycle
|
27
|
-
state_field_class = self::LifecycleStateField
|
28
|
-
else
|
29
|
-
# First call
|
30
|
-
|
31
|
-
module_eval "class ::#{name}::Lifecycle < Hobo::Lifecycles::Lifecycle; end"
|
32
|
-
lifecycle = self::Lifecycle
|
33
|
-
lifecycle.init(self, options)
|
34
|
-
|
35
|
-
module_eval "class ::#{name}::LifecycleStateField < HoboFields::LifecycleState; end"
|
36
|
-
state_field_class = self::LifecycleStateField
|
37
|
-
state_field_class.table_name = name.tableize
|
38
|
-
end
|
39
|
-
|
40
|
-
dsl = Hobo::Lifecycles::DeclarationDSL.new(lifecycle)
|
41
|
-
dsl.instance_eval(&block)
|
42
|
-
|
43
|
-
default = lifecycle.default_state ? { :default => lifecycle.default_state.name.to_s } : {}
|
44
|
-
declare_field(options[:state_field], state_field_class, default)
|
45
|
-
unless options[:index] == false
|
46
|
-
index_options = { :name => options[:index] } unless options[:index] == true
|
47
|
-
index(options[:state_field], index_options || {})
|
48
|
-
end
|
49
|
-
attr_protected options[:state_field]
|
50
|
-
|
51
|
-
unless options[:key_timestamp_field] == false
|
52
|
-
declare_field(options[:key_timestamp_field], :datetime)
|
53
|
-
never_show options[:key_timestamp_field]
|
54
|
-
attr_protected options[:key_timestamp_field]
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
def self.validation_method_with_lifecycles(on)
|
61
|
-
if has_lifecycle? && self::Lifecycle.step_names.include?(on)
|
62
|
-
callback = :"validate_on_#{on}"
|
63
|
-
|
64
|
-
# define these lifecycle validation callbacks on demand
|
65
|
-
define_callbacks callback unless respond_to? :callback
|
66
|
-
define_method(callback) {}
|
67
|
-
|
68
|
-
callback
|
69
|
-
else
|
70
|
-
validation_method_without_lifecycles(on)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
metaclass.alias_method_chain :validation_method, :lifecycles
|
74
|
-
|
75
|
-
|
76
|
-
def valid_with_lifecycles?
|
77
|
-
valid_without_lifecycles?
|
78
|
-
|
79
|
-
if self.class.has_lifecycle? && (step = lifecycle.active_step) && respond_to?(cb = "validate_on_#{step.name}")
|
80
|
-
run_callbacks cb
|
81
|
-
end
|
82
|
-
|
83
|
-
errors.empty?
|
84
|
-
end
|
85
|
-
alias_method_chain :valid?, :lifecycles
|
86
|
-
|
87
|
-
|
88
|
-
def lifecycle
|
89
|
-
@lifecycle ||= if self.class.const_defined?(:Lifecycle)
|
90
|
-
self.class::Lifecycle.new(self)
|
91
|
-
else
|
92
|
-
# search through superclasses
|
93
|
-
current = self.class.superclass
|
94
|
-
until (current.const_defined?(:Lifecycle) || current.nil? || !current.respond_to?(:lifecycle)) do
|
95
|
-
current = current.superclass
|
96
|
-
end
|
97
|
-
current::Lifecycle.new(self) if current.const_defined?(:Lifecycle)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
|
104
|
-
class DeclarationDSL
|
105
|
-
|
106
|
-
def initialize(lifecycle)
|
107
|
-
@lifecycle = lifecycle
|
108
|
-
end
|
109
|
-
|
110
|
-
def state(*args, &block)
|
111
|
-
options = args.extract_options!
|
112
|
-
names = args
|
113
|
-
states = names.map {|name| @lifecycle.def_state(name, block) }
|
114
|
-
if options[:default]
|
115
|
-
raise ArgumentError, "you must define one state if you give the :default option" unless states.length == 1
|
116
|
-
@lifecycle.default_state = states.first
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
def create(name, options={}, &block)
|
121
|
-
@lifecycle.def_creator(name, block, options)
|
122
|
-
end
|
123
|
-
|
124
|
-
def transition(name, change, options={}, &block)
|
125
|
-
@lifecycle.def_transition(name,
|
126
|
-
Array(change.keys.first), change.values.first,
|
127
|
-
block, options)
|
128
|
-
end
|
129
|
-
|
130
|
-
def invariant(&block)
|
131
|
-
@lifecycle.invariants << block
|
132
|
-
end
|
133
|
-
|
134
|
-
end
|
135
|
-
|
136
|
-
end
|
137
|
-
end
|
@@ -1,142 +0,0 @@
|
|
1
|
-
# We need to be able to eval an expression outside of the Hobo module
|
2
|
-
# so that, e.g. "User" doesn't eval to "Hobo::User"
|
3
|
-
# (Ruby determines this constant lookup scope lexically)
|
4
|
-
def __top_level_eval__(obj, expr)
|
5
|
-
obj.instance_eval(expr)
|
6
|
-
end
|
7
|
-
|
8
|
-
module Hobo
|
9
|
-
|
10
|
-
module Lifecycles
|
11
|
-
|
12
|
-
module Actions
|
13
|
-
|
14
|
-
def available_to_acting_user?(record)
|
15
|
-
return true if available_to.nil? # available_to not specified (these steps are not published)
|
16
|
-
acting_user_is?(available_to, record)
|
17
|
-
end
|
18
|
-
|
19
|
-
def publishable_by(user, who, record)
|
20
|
-
case who
|
21
|
-
when :all
|
22
|
-
true
|
23
|
-
|
24
|
-
when :key_holder
|
25
|
-
record.lifecycle.valid_key?
|
26
|
-
|
27
|
-
when :self
|
28
|
-
record == user
|
29
|
-
|
30
|
-
when Array
|
31
|
-
# recursively apply the same test to every item in the array
|
32
|
-
who.detect { |w| publishable_by(user, w, record) }
|
33
|
-
|
34
|
-
else
|
35
|
-
refl = record.class.reflections[who]
|
36
|
-
if refl && refl.macro == :has_many
|
37
|
-
record.send(who).include?(user)
|
38
|
-
elsif refl && refl.macro == :belongs_to
|
39
|
-
record.send("#{who}_is?", user)
|
40
|
-
else
|
41
|
-
value = run_hook(record, who)
|
42
|
-
if value.is_a?(Class)
|
43
|
-
user.is_a?(value)
|
44
|
-
elsif value.respond_to?(:include?)
|
45
|
-
value.include?(user)
|
46
|
-
else
|
47
|
-
value == user
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def acting_user_is?(who, record)
|
54
|
-
publishable_by(record.acting_user, who, record)
|
55
|
-
end
|
56
|
-
|
57
|
-
def run_hook(record, hook, *args)
|
58
|
-
case hook
|
59
|
-
when Symbol
|
60
|
-
record.send(hook, *args)
|
61
|
-
when String
|
62
|
-
__top_level_eval__(record, hook)
|
63
|
-
when Proc
|
64
|
-
if hook.arity == 1
|
65
|
-
hook.call(record)
|
66
|
-
else
|
67
|
-
record.instance_eval(&hook)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
def fire_event(record, event)
|
74
|
-
if event
|
75
|
-
if event.arity == 1
|
76
|
-
event.call(record)
|
77
|
-
else
|
78
|
-
record.instance_eval(&event)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
def guard_ok?(record)
|
85
|
-
if options[:if]
|
86
|
-
raise ArgumentError, "do not provide both :if and :unless to lifecycle steps" if options[:unless]
|
87
|
-
run_hook(record, options[:if])
|
88
|
-
elsif options[:unless]
|
89
|
-
!run_hook(record, options[:unless])
|
90
|
-
else
|
91
|
-
true
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
|
96
|
-
def prepare!(record, attributes)
|
97
|
-
record.attributes = extract_attributes(attributes) if attributes
|
98
|
-
record.lifecycle.generate_key if options[:new_key]
|
99
|
-
apply_user_becomes!(record)
|
100
|
-
end
|
101
|
-
|
102
|
-
|
103
|
-
def can_run?(record)
|
104
|
-
available_to_acting_user?(record) && guard_ok?(record) && record.lifecycle.invariants_satisfied?
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
def available_to
|
109
|
-
options[:available_to]
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
def publishable?
|
114
|
-
available_to
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
def apply_user_becomes!(record)
|
119
|
-
if (assoc = options[:user_becomes])
|
120
|
-
record.send("#{assoc}=", record.acting_user)
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
def get_state(record, state)
|
125
|
-
case state
|
126
|
-
when Proc
|
127
|
-
if state.arity == 1
|
128
|
-
state.call(record)
|
129
|
-
else
|
130
|
-
record.instance_eval(&state)
|
131
|
-
end
|
132
|
-
when String
|
133
|
-
eval(state, record.instance_eval { binding })
|
134
|
-
else
|
135
|
-
state
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
end
|
140
|
-
|
141
|
-
end
|
142
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
module Hobo
|
2
|
-
module Lifecycles
|
3
|
-
|
4
|
-
class Creator < Struct.new(:lifecycle, :name, :on_create, :options)
|
5
|
-
|
6
|
-
def initialize(*args)
|
7
|
-
super
|
8
|
-
self.name = name.to_sym
|
9
|
-
lifecycle.creators[name] = self
|
10
|
-
end
|
11
|
-
|
12
|
-
include Actions
|
13
|
-
|
14
|
-
def allowed?(user)
|
15
|
-
record = lifecycle.model.new
|
16
|
-
record.with_acting_user(user) { can_run?(record) }
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
def candidate(user, attributes=nil)
|
21
|
-
record = lifecycle.model.new
|
22
|
-
record.with_acting_user(user) { prepare!(record, attributes) }
|
23
|
-
record.exempt_from_edit_checks = true
|
24
|
-
record
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
def extract_attributes(attributes)
|
29
|
-
model = lifecycle.model
|
30
|
-
params = options.fetch(:params, [])
|
31
|
-
allowed = params.dup
|
32
|
-
params.each do |p|
|
33
|
-
if (refl = model.reflections[p]) && refl.macro == :belongs_to
|
34
|
-
allowed << refl.primary_key_name.to_s
|
35
|
-
allowed << refl.options[:foreign_type] if refl.options[:polymorphic]
|
36
|
-
end
|
37
|
-
end
|
38
|
-
attributes & allowed
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def change_state(record)
|
43
|
-
state = get_state(record, options[:become])
|
44
|
-
record.lifecycle.become state if state
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
def run!(user, attributes)
|
49
|
-
record = lifecycle.model.new
|
50
|
-
record.lifecycle.active_step = self
|
51
|
-
record.with_acting_user(user) do
|
52
|
-
prepare!(record, attributes)
|
53
|
-
if can_run?(record)
|
54
|
-
if change_state(record)
|
55
|
-
fire_event(record, on_create)
|
56
|
-
end
|
57
|
-
record
|
58
|
-
else
|
59
|
-
raise Hobo::PermissionDeniedError
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def parameters
|
66
|
-
options[:params] || []
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
@@ -1,249 +0,0 @@
|
|
1
|
-
module Hobo
|
2
|
-
|
3
|
-
module Lifecycles
|
4
|
-
|
5
|
-
class Lifecycle
|
6
|
-
|
7
|
-
def self.init(model, options)
|
8
|
-
@model = model
|
9
|
-
@options = options
|
10
|
-
reset
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.reset
|
14
|
-
@states = {}
|
15
|
-
@creators = {}
|
16
|
-
@transitions = []
|
17
|
-
@invariants = []
|
18
|
-
end
|
19
|
-
|
20
|
-
class << self
|
21
|
-
attr_accessor :model, :options, :states, :default_state,
|
22
|
-
:creators, :transitions, :invariants
|
23
|
-
end
|
24
|
-
|
25
|
-
def self.def_state(name, on_enter)
|
26
|
-
name = name.to_sym
|
27
|
-
class_eval "def #{name}_state?; state_name == :#{name} end"
|
28
|
-
states[name] = Lifecycles::State.new(name, on_enter)
|
29
|
-
end
|
30
|
-
|
31
|
-
|
32
|
-
def self.def_creator(name, on_create, options)
|
33
|
-
class_eval %{
|
34
|
-
def self.#{name}(user, attributes=nil)
|
35
|
-
create(:#{name}, user, attributes)
|
36
|
-
end
|
37
|
-
def self.can_#{name}?(user, attributes=nil)
|
38
|
-
can_create?(:#{name}, user)
|
39
|
-
end
|
40
|
-
}
|
41
|
-
Creator.new(self, name.to_s, on_create, options)
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.def_transition(name, start_state, end_states, on_transition, options)
|
45
|
-
class_eval %{
|
46
|
-
def #{name}!(user, attributes=nil)
|
47
|
-
transition(:#{name}, user, attributes)
|
48
|
-
end
|
49
|
-
def can_#{name}?(user, attributes=nil)
|
50
|
-
can_transition?(:#{name}, user)
|
51
|
-
end
|
52
|
-
def valid_for_#{name}?
|
53
|
-
valid_for_transition?(:#{name})
|
54
|
-
end
|
55
|
-
}
|
56
|
-
Transition.new(self, name.to_s, start_state, end_states, on_transition, options)
|
57
|
-
end
|
58
|
-
|
59
|
-
def self.state_names
|
60
|
-
states.keys
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.publishable_creators
|
64
|
-
creators.values.where.publishable?
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.publishable_transitions
|
68
|
-
transitions.where.publishable?
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.step_names
|
72
|
-
(creators.keys | transitions.*.name).uniq
|
73
|
-
end
|
74
|
-
|
75
|
-
|
76
|
-
def self.creator(name)
|
77
|
-
creators[name.to_sym] or raise ArgumentError, "No such creator in lifecycle: #{name}"
|
78
|
-
end
|
79
|
-
|
80
|
-
|
81
|
-
def self.can_create?(name, user)
|
82
|
-
creators[name.to_sym].allowed?(user)
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
def self.create(name, user, attributes=nil)
|
87
|
-
creator = creators[name.to_sym] or raise LifecycleError, "No creator #{name} available"
|
88
|
-
creator.run!(user, attributes)
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
def self.state_field
|
93
|
-
options[:state_field]
|
94
|
-
end
|
95
|
-
|
96
|
-
def self.key_timeout
|
97
|
-
options[:key_timeout]
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
# --- Instance Features --- #
|
102
|
-
|
103
|
-
attr_reader :record
|
104
|
-
|
105
|
-
attr_accessor :provided_key, :active_step
|
106
|
-
|
107
|
-
|
108
|
-
def initialize(record)
|
109
|
-
@record = record
|
110
|
-
end
|
111
|
-
|
112
|
-
|
113
|
-
def can_transition?(name, user)
|
114
|
-
available_transitions_for(user, name).any?
|
115
|
-
end
|
116
|
-
|
117
|
-
|
118
|
-
def transition(name, user, attributes)
|
119
|
-
transition = find_transition(name, user) or raise LifecycleError, "No transition #{name} available"
|
120
|
-
transition.run!(record, user, attributes)
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
def find_transition(name, user)
|
125
|
-
available_transitions_for(user, name).first
|
126
|
-
end
|
127
|
-
|
128
|
-
|
129
|
-
def valid_for_transition?(name)
|
130
|
-
record.valid?
|
131
|
-
callback = :"validate_on_#{name}"
|
132
|
-
record.run_callbacks callback
|
133
|
-
record.send callback
|
134
|
-
record.errors.empty?
|
135
|
-
end
|
136
|
-
|
137
|
-
|
138
|
-
def state_name
|
139
|
-
name = record.read_attribute(self.class.state_field)
|
140
|
-
name.to_sym if name
|
141
|
-
end
|
142
|
-
|
143
|
-
|
144
|
-
def state
|
145
|
-
self.class.states[state_name]
|
146
|
-
end
|
147
|
-
|
148
|
-
|
149
|
-
def available_transitions
|
150
|
-
state ? state.transitions_out : []
|
151
|
-
end
|
152
|
-
|
153
|
-
# see also publishable_transitions_for
|
154
|
-
def available_transitions_for(user, name=nil)
|
155
|
-
name = name.to_sym if name
|
156
|
-
matches = available_transitions
|
157
|
-
matches = matches.select { |t| t.name == name } if name
|
158
|
-
record.with_acting_user(user) do
|
159
|
-
matches.select { |t| t.can_run?(record) }
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def publishable_transitions_for(user)
|
164
|
-
available_transitions_for(user).select {|t| t.publishable_by(user, t.available_to, record)}
|
165
|
-
end
|
166
|
-
|
167
|
-
|
168
|
-
def become(state_name, validate=true)
|
169
|
-
state_name = state_name.to_sym
|
170
|
-
record.write_attribute self.class.state_field, state_name.to_s
|
171
|
-
if state_name == :destroy
|
172
|
-
record.destroy
|
173
|
-
true
|
174
|
-
else
|
175
|
-
s = self.class.states[state_name]
|
176
|
-
raise ArgumentError, "No such state '#{state_name}' for #{record.class.name}" unless s
|
177
|
-
|
178
|
-
if record.save(validate)
|
179
|
-
s.activate! record
|
180
|
-
self.active_step = nil # That's the end of this step
|
181
|
-
true
|
182
|
-
else
|
183
|
-
false
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
|
189
|
-
def key_timestamp_field
|
190
|
-
record.class::Lifecycle.options[:key_timestamp_field]
|
191
|
-
end
|
192
|
-
|
193
|
-
def key_timeout
|
194
|
-
record.class::Lifecycle.options[:key_timeout]
|
195
|
-
end
|
196
|
-
|
197
|
-
def generate_key
|
198
|
-
if Time.zone.nil?
|
199
|
-
raise RuntimeError, "Cannot generate lifecycle key timestamp if the time-zone is not configured. Please add, e.g. config.time_zone = 'UTC' to environment.rb"
|
200
|
-
end
|
201
|
-
key_timestamp = Time.now.utc
|
202
|
-
record.write_attribute key_timestamp_field, key_timestamp
|
203
|
-
key
|
204
|
-
end
|
205
|
-
|
206
|
-
|
207
|
-
def key
|
208
|
-
require 'digest/sha1'
|
209
|
-
timestamp = record.read_attribute(key_timestamp_field)
|
210
|
-
if timestamp
|
211
|
-
timestamp = timestamp.getutc
|
212
|
-
Digest::SHA1.hexdigest("#{record.id}-#{state_name}-#{timestamp}-#{ActionController::Base.session_options[:secret]}")
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
def key_expired?
|
217
|
-
timestamp = record.read_attribute(key_timestamp_field)
|
218
|
-
timestamp.nil? || (timestamp.getutc + key_timeout < Time.now.utc)
|
219
|
-
end
|
220
|
-
|
221
|
-
def valid_key?
|
222
|
-
provided_key && provided_key == key && !key_expired?
|
223
|
-
end
|
224
|
-
|
225
|
-
def clear_key
|
226
|
-
record.write_attribute key_timestamp_field, nil
|
227
|
-
end
|
228
|
-
|
229
|
-
def invariants_satisfied?
|
230
|
-
self.class.invariants.all? { |i| record.instance_eval(&i) }
|
231
|
-
end
|
232
|
-
|
233
|
-
|
234
|
-
def active_step_is?(name)
|
235
|
-
active_step && active_step.name == name.to_sym
|
236
|
-
end
|
237
|
-
|
238
|
-
def method_missing(name, *args)
|
239
|
-
if name.to_s =~ /^(.*)_in_progress\?$/
|
240
|
-
active_step_is?($1)
|
241
|
-
else
|
242
|
-
super
|
243
|
-
end
|
244
|
-
end
|
245
|
-
|
246
|
-
end
|
247
|
-
|
248
|
-
end
|
249
|
-
end
|