hobo 1.3.0.RC4 → 1.3.0.pre10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. data/CHANGES.txt +234 -282
  2. data/Rakefile +3 -3
  3. data/VERSION +1 -1
  4. data/app/controllers/dev_controller.rb +2 -2
  5. data/bin/hobo +3 -3
  6. data/config/routes.rb +1 -1
  7. data/doctests/hobo/lifecycles.rdoctest +1 -0
  8. data/doctests/hobo/model.rdoctest +5 -0
  9. data/doctests/hobo/multi_model_forms.rdoctest +5 -4
  10. data/doctests/hobo/scopes.rdoctest +8 -11
  11. data/doctests/prepare_testapp.rb +1 -2
  12. data/hobo.gemspec +2 -2
  13. data/lib/generators/hobo/admin_subsite/admin_subsite_generator.rb +11 -5
  14. data/lib/generators/hobo/admin_subsite/templates/admin.css +2 -20
  15. data/lib/generators/hobo/admin_subsite/templates/admin_tag_injection.erb +1 -3
  16. data/lib/generators/hobo/admin_subsite/templates/controller.rb.erb +5 -5
  17. data/lib/generators/hobo/admin_subsite/templates/users_index.dryml +1 -3
  18. data/lib/generators/hobo/basic/basic_generator.rb +17 -0
  19. data/lib/generators/hobo/{assets → basic}/templates/application.css +0 -0
  20. data/lib/generators/hobo/{assets → basic}/templates/application.dryml.erb +1 -1
  21. data/lib/generators/hobo/{assets → basic}/templates/dryml-support.js +2 -2
  22. data/lib/generators/hobo/{assets → basic}/templates/en_injection.yml +0 -0
  23. data/lib/generators/hobo/{assets → basic}/templates/guest.rb +0 -0
  24. data/lib/generators/hobo/controller.rb +1 -6
  25. data/lib/generators/hobo/front_controller/front_controller_generator.rb +3 -2
  26. data/{app/views/dev → lib/generators/hobo/front_controller/templates}/summary.dryml +10 -7
  27. data/lib/generators/hobo/hints/hints_generator.rb +12 -0
  28. data/lib/generators/hobo/hints/templates/hints.rb.erb +5 -0
  29. data/lib/generators/hobo/hints/templates/model_injection.rb.erb +36 -0
  30. data/lib/generators/hobo/i18n/i18n_generator.rb +9 -1
  31. data/lib/generators/hobo/i18n/templates/app.en.yml +1 -1
  32. data/lib/generators/hobo/i18n/templates/app.es-DO.yml +24 -0
  33. data/lib/generators/hobo/i18n/templates/app.it.yml +1 -5
  34. data/lib/generators/hobo/i18n/templates/app.pt-PT.yml +0 -1
  35. data/lib/generators/hobo/i18n/templates/default_count_injection.rb +10 -0
  36. data/lib/generators/hobo/i18n/templates/hobo.en.yml +10 -26
  37. data/lib/generators/hobo/i18n/templates/{hobo.es.yml → hobo.es-DO.yml} +10 -27
  38. data/lib/generators/hobo/i18n/templates/hobo.it.yml +4 -20
  39. data/lib/generators/hobo/i18n/templates/hobo.pt-PT.yml +9 -25
  40. data/lib/generators/hobo/model.rb +13 -0
  41. data/lib/generators/hobo/model/USAGE +3 -2
  42. data/lib/generators/hobo/model/model_generator.rb +1 -2
  43. data/lib/generators/hobo/rapid/rapid_generator.rb +0 -2
  44. data/lib/generators/hobo/rapid/templates/hobo-rapid.js +93 -78
  45. data/lib/generators/hobo/rapid/templates/ie7-recalc.js +21 -21
  46. data/lib/generators/hobo/rapid/templates/lowpro.js +31 -31
  47. data/lib/generators/hobo/rapid/templates/reset.css +1 -1
  48. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/clean.css +16 -17
  49. data/lib/generators/hobo/rapid/templates/themes/clean/public/stylesheets/rapid-ui.css +3 -3
  50. data/lib/generators/hobo/rapid/templates/themes/clean/views/clean.dryml +1 -1
  51. data/lib/generators/hobo/resource/resource_generator.rb +1 -1
  52. data/lib/generators/hobo/routes/router.rb +4 -4
  53. data/lib/generators/hobo/routes/routes_generator.rb +1 -12
  54. data/lib/generators/hobo/routes/templates/hobo_routes.rb.erb +1 -1
  55. data/lib/generators/hobo/setup_wizard/setup_wizard_generator.rb +43 -88
  56. data/lib/generators/hobo/subsite.rb +5 -18
  57. data/lib/generators/hobo/subsite/subsite_generator.rb +1 -1
  58. data/lib/generators/hobo/subsite/templates/controller.rb.erb +1 -1
  59. data/lib/generators/hobo/subsite_taglib/templates/taglib.dryml.erb +2 -2
  60. data/lib/generators/hobo/test_framework/test_framework_generator.rb +7 -7
  61. data/lib/generators/hobo/user_controller/templates/controller.rb.erb +3 -8
  62. data/lib/generators/hobo/user_mailer/templates/activation.erb +2 -2
  63. data/lib/generators/hobo/user_mailer/templates/forgot_password.erb +2 -2
  64. data/lib/generators/hobo/user_mailer/templates/invite.erb +2 -2
  65. data/lib/generators/hobo/user_mailer/templates/mailer.rb.erb +17 -10
  66. data/lib/generators/hobo/user_mailer/user_mailer_generator.rb +1 -1
  67. data/lib/generators/hobo/user_model/USAGE +9 -2
  68. data/lib/generators/hobo/user_model/user_model_generator.rb +1 -2
  69. data/lib/hobo.rb +7 -13
  70. data/lib/hobo/controller.rb +14 -21
  71. data/lib/hobo/controller/authentication_support.rb +23 -1
  72. data/lib/hobo/controller/model.rb +53 -48
  73. data/lib/hobo/controller/{user_base.rb → user.rb} +36 -47
  74. data/lib/hobo/engine.rb +11 -25
  75. data/lib/hobo/extensions/action_controller/hobo_methods.rb +1 -25
  76. data/lib/hobo/extensions/active_model/translation.rb +1 -1
  77. data/lib/hobo/extensions/active_record/{associations/collection.rb → association_collection.rb} +3 -12
  78. data/lib/hobo/extensions/active_record/{associations/proxy.rb → association_proxy.rb} +7 -6
  79. data/lib/hobo/extensions/active_record/association_reflection.rb +19 -0
  80. data/lib/hobo/extensions/active_record/hobo_methods.rb +1 -1
  81. data/lib/hobo/extensions/active_record/scopes.rb +31 -0
  82. data/lib/hobo/extensions/array.rb +1 -13
  83. data/lib/hobo/helper.rb +6 -27
  84. data/lib/hobo/helper/translations.rb +90 -39
  85. data/lib/hobo/model.rb +20 -72
  86. data/lib/hobo/model/lifecycles.rb +11 -12
  87. data/lib/hobo/model/lifecycles/lifecycle.rb +4 -12
  88. data/lib/hobo/model/lifecycles/transition.rb +0 -1
  89. data/lib/hobo/model/permissions.rb +3 -2
  90. data/lib/hobo/model/scopes/apply_scopes.rb +1 -1
  91. data/lib/hobo/model/scopes/automatic_scopes.rb +80 -78
  92. data/lib/hobo/model/{user_base.rb → user.rb} +7 -9
  93. data/lib/hobo/rapid/generators/rapid/cards.dryml.erb +2 -2
  94. data/lib/hobo/rapid/generators/rapid/forms.dryml.erb +4 -5
  95. data/lib/hobo/rapid/generators/rapid/pages.dryml.erb +27 -26
  96. data/lib/hobo/rapid/helper.rb +5 -10
  97. data/lib/hobo/rapid/taglibs/rapid.dryml +1 -1
  98. data/lib/hobo/rapid/taglibs/rapid_core.dryml +42 -72
  99. data/lib/hobo/rapid/taglibs/rapid_document_tags.dryml +2 -2
  100. data/lib/hobo/rapid/taglibs/rapid_editing.dryml +16 -36
  101. data/lib/hobo/rapid/taglibs/rapid_forms.dryml +49 -87
  102. data/lib/hobo/rapid/taglibs/rapid_generics.dryml +2 -2
  103. data/lib/hobo/rapid/taglibs/rapid_i18n.dryml +75 -50
  104. data/lib/hobo/rapid/taglibs/rapid_lifecycles.dryml +5 -7
  105. data/lib/hobo/rapid/taglibs/rapid_navigation.dryml +2 -2
  106. data/lib/hobo/rapid/taglibs/rapid_pages.dryml +7 -8
  107. data/lib/hobo/rapid/taglibs/rapid_plus.dryml +43 -66
  108. data/lib/hobo/rapid/taglibs/rapid_summary.dryml +45 -16
  109. data/lib/hobo/rapid/taglibs/rapid_translations.dryml +36 -0
  110. data/lib/hobo/rapid/taglibs/rapid_user_pages.dryml +8 -8
  111. data/lib/hobo/routes.rb +23 -22
  112. data/lib/hobo/view_hints.rb +101 -0
  113. data/test/irt/generators/admin_subsite.irt +1 -1
  114. data/test/irt/generators/{assets.irt → basic.irt} +2 -2
  115. data/test/irt/generators/front_controller.irt +4 -2
  116. data/test/irt/generators/partials/_subsite_taglib_variables.rb +1 -1
  117. data/test/irt/generators/subsite.irt +1 -1
  118. data/test/permissions/test_permissions.rb +103 -103
  119. metadata +108 -69
  120. data/lib/generators/hobo/admin_subsite/USAGE +0 -25
  121. data/lib/generators/hobo/admin_subsite/templates/application.dryml +0 -1
  122. data/lib/generators/hobo/assets/USAGE +0 -5
  123. data/lib/generators/hobo/assets/assets_generator.rb +0 -18
  124. data/lib/generators/hobo/assets/templates/dryml_taglibs_initializer.rb +0 -1
  125. data/lib/generators/hobo/controller/USAGE +0 -3
  126. data/lib/generators/hobo/i18n/USAGE +0 -3
  127. data/lib/generators/hobo/i18n/templates/app.de.yml +0 -30
  128. data/lib/generators/hobo/i18n/templates/app.es.yml +0 -31
  129. data/lib/generators/hobo/i18n/templates/app.fr.yml +0 -26
  130. data/lib/generators/hobo/i18n/templates/app.nb.yml +0 -25
  131. data/lib/generators/hobo/i18n/templates/app.ru.yml +0 -24
  132. data/lib/generators/hobo/i18n/templates/hobo.de.yml +0 -204
  133. data/lib/generators/hobo/i18n/templates/hobo.fr.yml +0 -195
  134. data/lib/generators/hobo/i18n/templates/hobo.nb.yml +0 -198
  135. data/lib/generators/hobo/i18n/templates/hobo.ru.yml +0 -200
  136. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-ACD3E6-DBE1E5-H.png +0 -0
  137. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/100-DBE1E5-FCFEF5-H.png +0 -0
  138. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/300-3B5F87-ACD3E6-H.png +0 -0
  139. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/images/spinner.gif +0 -0
  140. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/public/stylesheets/clean-sidemenu.css +0 -81
  141. data/lib/generators/hobo/rapid/templates/themes/clean-sidemenu/views/clean-sidemenu.dryml +0 -30
  142. data/lib/generators/hobo/resource/USAGE +0 -39
  143. data/lib/generators/hobo/subsite/USAGE +0 -24
  144. data/lib/generators/hobo/subsite_taglib/USAGE +0 -4
  145. data/lib/generators/hobo/test_framework/USAGE +0 -2
  146. data/lib/generators/hobo/user_controller/USAGE +0 -3
  147. data/lib/generators/hobo/user_mailer/USAGE +0 -2
  148. data/lib/generators/hobo/user_resource/USAGE +0 -10
  149. data/lib/hobo/extensions/action_view/translation_helper.rb +0 -25
  150. data/lib/hobo/extensions/active_record/associations/reflection.rb +0 -23
  151. data/lib/hobo/extensions/active_record/associations/scope.rb +0 -35
  152. data/lib/hobo/extensions/active_record/relation_with_origin.rb +0 -32
  153. data/lib/hobo/extensions/i18n.rb +0 -17
  154. data/lib/hobo/helper/translations/normalizer.rb +0 -39
  155. data/lib/hobo/model/view_hints.rb +0 -123
@@ -2,52 +2,103 @@ module Hobo
2
2
  module Helper
3
3
  module Translations
4
4
 
5
- include Normalizer
6
-
7
- =begin
8
-
9
- hobo_translate / ht
10
-
11
- Wrapper around the Rails :translate helper with hobo added features.
12
-
13
- It can be used as a regular helper or as a dryml tag.
14
-
15
- Hobo Added Features
16
-
17
- The first part of the key must be a model name (e.g.: user.index.title -> user). This method will add a "model" interpolation variable set to the translated and pluralized Model.model_name.human. Besides, it will add a default 'hobo.' fallback, (e.g.: hobo.index.title) at the beginning of the fallback chain.
18
-
19
- You can also pass any other :translate option like for example :count.
5
+ # --- Translation Helper --- #
6
+ #
7
+ # Uses RoR native I18n.translate.
8
+ #
9
+ # Adds some conventions for easier hobo translation.
10
+ # 1. Assumes the first part of the key to be a model name (e.g.: users.index.title -> user)
11
+ # 2. Tries to translate the model by lookup for: (e.g.: user-> activerecord.models.user)
12
+ # 3. Adds a default fallback to the beginning of the fallback chain
13
+ # by replacing the first part of the key with "hobo" and using the translated model name
14
+ # as additional attribute. This allows us to have default translations
15
+ # (e.g.: hobo.index.title: "{{model}} Index")
16
+ #
17
+ # Is also used as a tag in the dryml-view files. The syntax is:
18
+ # <ht key="my.app">My Application</ht>
19
+ # --> Will lookup the "my.app"-key for your locale and replaces the "My Application" content
20
+ # if found.
21
+ #
22
+ # <ht key="my" app="Program">My Application</ht>
23
+ # --> Will look up both the "my"- and "app"-key for your locale, and replaces the
24
+ # "My Application" with the "my"-key contents (interpolated using the "app"-key.
25
+ # sample.en.yml-file:
26
+ # "no":
27
+ # my: "Mitt {{app}}"
28
+ # The output should be: Mitt Program
29
+ #
30
+ # The "count" option set the integer passed or to the Model.count if : dynamic is passed.
31
+ # The following lines are the same:
32
+ #
33
+ # <ht key="modelname.any.key" count="&:dynamic">
34
+ # <ht key="modelname.any.key" count="&model.count">
35
+ #
36
+ # Otherwise with features as the ht method, step 1, 2 and 3 above.
37
+ def ht(key, options={})
38
+
39
+ # Check if called as a tag, i.e. like this <ht></ht>
40
+ if (key.class == Hash)
41
+ if key.has_key?(:default) && !key[:default].blank?
42
+ Rails.logger.warn "hobo-i18n: 'default' should not be used as an attribute on the ht-tag. If used, then you need to make sure that the tags inner-contents are not used. These are normally treated as defaults automatically, but if there is a default attribute then that inner-content will be hidden from this method - and will not be replaced with the translation found."
43
+ end
44
+ defaults = options[:default];
45
+ # Swap key and options, remove options[:key]
46
+ options = key
47
+ key = options.delete(:key) # returns value for options[:key] as well as deleting it
48
+ # Set options[:default] to complete the tag-argument-conversion process.
49
+ options[:default] = (defaults.class == Proc) ? [defaults.call(options)] : (options[:default].blank? ? [] : [options[:default]])
50
+ else
51
+ # Not called as a tag. Prepare options[:default].
52
+ if options[:default].nil?
53
+ options[:default]=[]
54
+ elsif options[:default].class != Array
55
+ options[:default] = [options[:default]]
56
+ end
57
+ end
20
58
 
21
- Example:
59
+ # assume the first part of the key to be the model
60
+ keys = key.to_s.split(".")
61
+ if keys.length > 1
62
+ model = keys.shift()
63
+ subkey = keys.join(".")
64
+ else
65
+ subkey = key
66
+ end
22
67
 
23
- <%= ht :key=>'user.index.title', :default=>'Index' %>
24
- <ht key="user.index.title">Index</ht>
25
- #=> "Index" # if "user.index.title" or "hobo.index.title" is not found
26
- #=> "User Index" # with the below en.yml file
68
+ # will skip useless code in case the first part of the key is 'hobo'
69
+ model = '' if model.eql?('hobo')
70
+
71
+ unless model.blank?
72
+ klass = begin
73
+ model.singularize.camelize.constantize
74
+ rescue NameError
75
+ end
76
+ # add :"hobo.#{key}" as the first fallback
77
+ options[:default].unshift("hobo.#{subkey}".to_sym)
78
+ # set the count option in order to allow multiple pluralization
79
+ count = options.delete(:count)
80
+ count = default_count if count.blank?
81
+ c = count.try.to_i || count==:dynamic && klass.try.count
82
+ # translate the model
83
+ # the singularize method is used because Hobo does not keep the ActiveRecord convention in its tags
84
+ # no default needed because human_name defaults to the model name
85
+ # try because Hobo class is not an ActiveRecord::Base subclass
86
+ translated_pluralized_model = klass.try.model_name.try.human(:count=>c)
87
+ options[:model] = translated_pluralized_model
88
+ end
89
+ options[:count] = c
27
90
 
28
- === en.yml ===
29
- en:
30
- hobo:
31
- index:
32
- title: %{model} Index
91
+ key_prefix = "<span class='translation-key'>#{key}</span>" if defined?(HOBO_SHOW_LOCALE_KEYS) && HOBO_SHOW_LOCALE_KEYS
33
92
 
34
- =end
93
+ Rails.logger.info "..translate(#{key}, #{options.inspect}) to #{I18n.locale}" if defined?(HOBO_VERBOSE_TRANSLATIONS)
35
94
 
36
- def hobo_translate(*args)
37
- key, options = normalize_args(*args)
38
- keys = key.to_s.split(".")
39
- model_name = keys.shift
40
- model_class = begin model_name.camelize.constantize; rescue; end
41
- unless model_class && model_class < ActiveRecord::Base
42
- raise Hobo::I18nError, %(wrong model name: "#{model_name}" (extracted from translation key: "#{key}"). You might want to use the translate/t tag/method instead.)
95
+ translation = I18n.translate(key.to_sym, options)
96
+ if translation.respond_to? :to_str
97
+ key_prefix ? translation.to_str+key_prefix : translation
98
+ else
99
+ "translation invalid: #{key}"
43
100
  end
44
- options[:default].unshift("hobo.#{keys.join(".")}".to_sym)
45
- options[:model] = model_class.model_name.human(:count=>(options[:count] || 1).to_i)
46
- translate key.to_sym, options
47
101
  end
48
- alias_method :ht, :hobo_translate
49
-
50
-
51
102
 
52
103
  end
53
104
  end
@@ -33,6 +33,14 @@ module Hobo
33
33
  alias_method_chain :attr_accessor, :creator_metadata
34
34
 
35
35
  alias_method_chain :has_one, :new_method
36
+
37
+ def inherited(klass)
38
+ super
39
+ fields(false) do
40
+ Hobo.register_model(klass)
41
+ field(klass.inheritance_column, :string)
42
+ end
43
+ end
36
44
  end
37
45
 
38
46
  base.fields(false) # force hobo_fields to load
@@ -45,45 +53,18 @@ module Hobo
45
53
 
46
54
  WillPaginate::Collection.class_eval do
47
55
  attr_accessor :member_class, :origin, :origin_attribute
48
-
49
- # make paginate_by_sql, etc. carry metadata
50
- def replace_with_hobo_metadata(array)
51
- result = replace_without_hobo_metadata(array)
52
- self.member_class = array.try.member_class
53
- self.origin = array.try.origin
54
- self.origin_attribute = array.try.origin_attribute
55
- result
56
- end
57
- alias_method_chain :replace, :hobo_metadata
58
56
  end
59
57
 
60
- WillPaginate::ActiveRecord::Pagination.class_eval do
61
-
62
- def apply_hobo_metadata(collection)
63
- klass = Object.instance_method(:class).bind(self).call
64
- is_relation = klass <= ActiveRecord::Relation
65
- is_association_proxy = klass <= ActiveRecord::Associations::AssociationProxy
66
- collection.member_class = (is_relation || is_association_proxy) ? member_class : self
58
+ WillPaginate::Finders::Base.class_eval do
59
+ def paginate_with_hobo_metadata(*args, &block)
60
+ collection = paginate_without_hobo_metadata(*args, &block)
61
+ collection.member_class = self
67
62
  collection.origin = try.proxy_owner
68
63
  collection.origin_attribute = try.proxy_reflection._?.name
69
64
  collection
70
65
  end
71
-
72
- # NOTE: as of will_paginate 3.0.0, the standard paginate method calls the page method.
73
- # However, it converts an association proxy into a relation first (via adding a limit clause),
74
- # which causes the proxy_owner and proxy_reflection methods to disappear.
75
- def paginate_with_hobo_metadata(*args, &block)
76
- collection = paginate_without_hobo_metadata(*args, &block)
77
- apply_hobo_metadata(collection)
78
- end
79
66
  alias_method_chain :paginate, :hobo_metadata
80
67
 
81
- def page_with_hobo_metadata(*args, &block)
82
- collection = page_without_hobo_metadata(*args, &block)
83
- apply_hobo_metadata(collection)
84
- end
85
- alias_method_chain :page, :hobo_metadata
86
-
87
68
  end
88
69
 
89
70
  end
@@ -132,6 +113,7 @@ module Hobo
132
113
  end
133
114
  end
134
115
 
116
+
135
117
  module ClassMethods
136
118
 
137
119
  # TODO: should this be an inheriting_cattr_accessor as well? Probably.
@@ -157,22 +139,10 @@ module Hobo
157
139
  self.creator_attribute = name.to_sym if options.delete(:creator)
158
140
  validate = options.delete(:validate) {true}
159
141
 
160
- #FIXME - this should be in Hobo::Model::UserBase
142
+ #FIXME - this should be in Hobo::Model::User
161
143
  send(:login_attribute=, name.to_sym, validate) if options.delete(:login) && respond_to?(:login_attribute=)
162
144
  end
163
145
 
164
- # eval avoids the ruby 1.9.2 "super from singleton method ..." error
165
- eval %(
166
- def inherited(klass)
167
- super
168
- Hobo::Model.register_model(klass)
169
- # TODO: figure out when this is needed, as Hobofields already does this
170
- fields(false) do
171
- field(klass.inheritance_column, :string)
172
- end
173
- end
174
- )
175
-
176
146
  private
177
147
 
178
148
  def attrib_names
@@ -189,27 +159,22 @@ module Hobo
189
159
  def belongs_to_with_test_methods(name, options={}, &block)
190
160
  belongs_to_without_test_methods(name, options, &block)
191
161
  refl = reflections[name]
192
- id_method = refl.options[:primary_key] || refl.klass.primary_key
193
162
  if options[:polymorphic]
194
163
  # TODO: the class lookup in _is? below is incomplete; a polymorphic association to an STI base class
195
164
  # will fail to match an object of a derived type
196
165
  # (ie X belongs_to Y (polymorphic), Z is a subclass of Y; @x.y_is?(some_z) will never pass)
197
166
  class_eval %{
198
167
  def #{name}_is?(target)
199
- target.class.name == self.#{refl.options[:foreign_type]} && target.#{id_method} == self.#{refl.primary_key_name}
168
+ target.class.name == self.#{refl.options[:foreign_type]} && target.id == self.#{refl.primary_key_name}
200
169
  end
201
170
  def #{name}_changed?
202
171
  #{refl.primary_key_name}_changed? || #{refl.options[:foreign_type]}_changed?
203
172
  end
204
173
  }
205
174
  else
206
- id_method = refl.options[:primary_key] || refl.klass.primary_key
207
175
  class_eval %{
208
176
  def #{name}_is?(target)
209
- our_id = self.#{refl.primary_key_name}
210
- # if our_id is nil, only return true if target is nil
211
- return target.nil? unless our_id
212
- target.class <= ::#{refl.klass.name} && target.#{id_method} == our_id
177
+ target.class <= ::#{refl.klass.name} && target.id == self.#{refl.primary_key_name}
213
178
  end
214
179
  def #{name}_changed?
215
180
  #{refl.primary_key_name}_changed?
@@ -365,20 +330,7 @@ module Hobo
365
330
 
366
331
  def view_hints
367
332
  class_name = "#{name}Hints"
368
- class_name.safe_constantize or Object.class_eval("class #{class_name} < Hobo::Model::ViewHints; end; #{class_name}")
369
- end
370
-
371
- def children(*args)
372
- view_hints.children *args
373
- end
374
-
375
- def inline_booleans(*args)
376
- view_hints.inline_booleans *args
377
- end
378
-
379
- def table_exists?
380
- @table_exists_cache = super if @table_exists_cache.nil?
381
- @table_exists_cache
333
+ class_name.safe_constantize or Object.class_eval("class #{class_name} < Hobo::ViewHints; end; #{class_name}")
382
334
  end
383
335
 
384
336
 
@@ -389,7 +341,7 @@ module Hobo
389
341
 
390
342
 
391
343
  def to_url_path
392
- "#{self.class.to_url_path}/#{to_param}"
344
+ "#{self.class.to_url_path}/#{to_param}" unless new_record?
393
345
  end
394
346
 
395
347
 
@@ -470,11 +422,7 @@ module Hobo
470
422
  if parts.include?(0)
471
423
  nil
472
424
  else
473
- begin
474
- Date.new(*parts)
475
- rescue ArgumentError => ex
476
- Time.time_with_datetime_fallback(ActiveRecord::Base.default_timezone, *parts).to_date
477
- end
425
+ Date.new(*parts)
478
426
  end
479
427
  else
480
428
  value
@@ -486,7 +434,7 @@ module Hobo
486
434
  if parts[0..2].include?(0)
487
435
  nil
488
436
  else
489
- field_type <= Time ? Time.utc(*parts) : Time.zone.local(*parts)
437
+ Time.zone ? Time.zone.local(*parts) : Time.local(*parts)
490
438
  end
491
439
  else
492
440
  value
@@ -34,7 +34,7 @@ module Hobo
34
34
 
35
35
  module_eval "class ::#{name}::LifecycleStateField < HoboFields::Types::LifecycleState; end"
36
36
  state_field_class = self::LifecycleStateField
37
- state_field_class.model_name = name
37
+ state_field_class.table_name = name.tableize
38
38
  end
39
39
 
40
40
  dsl = Hobo::Model::Lifecycles::DeclarationDSL.new(lifecycle)
@@ -56,15 +56,14 @@ module Hobo
56
56
 
57
57
  end
58
58
 
59
- # eval avoids the ruby 1.9.2 "super from singleton method ..." error
60
- eval %(
61
- def valid?(context=nil)
62
- if context.nil? && self.class.has_lifecycle? && (step = lifecycle.active_step)
63
- context = step.name
64
- end
65
- super(context)
59
+
60
+ def valid?(context=nil)
61
+ if context.nil? && self.class.has_lifecycle? && (step = lifecycle.active_step)
62
+ context = step.name
66
63
  end
67
- )
64
+ super(context)
65
+ end
66
+
68
67
 
69
68
  def lifecycle
70
69
  @lifecycle ||= if self.class.const_defined?(:Lifecycle)
@@ -103,9 +102,9 @@ module Hobo
103
102
  end
104
103
 
105
104
  def transition(name, change, options={}, &block)
106
- change.each do |k,v|
107
- @lifecycle.def_transition(name, Array(k), v, block, options)
108
- end
105
+ @lifecycle.def_transition(name,
106
+ Array(change.keys.first), change.values.first,
107
+ block, options)
109
108
  end
110
109
 
111
110
  def invariant(&block)
@@ -41,7 +41,7 @@ module Hobo
41
41
  Creator.new(self, name.to_s, on_create, options)
42
42
  end
43
43
 
44
- def self.def_transition(name, start_states, end_state, on_transition, options)
44
+ def self.def_transition(name, start_state, end_states, on_transition, options)
45
45
  class_eval %{
46
46
  def #{name}!(user, attributes=nil)
47
47
  transition(:#{name}, user, attributes)
@@ -50,7 +50,7 @@ module Hobo
50
50
  can_transition?(:#{name}, user)
51
51
  end
52
52
  }
53
- Transition.new(self, name.to_s, start_states, end_state, on_transition, options)
53
+ Transition.new(self, name.to_s, start_state, end_states, on_transition, options)
54
54
  end
55
55
 
56
56
  def self.state_names
@@ -149,11 +149,7 @@ module Hobo
149
149
  end
150
150
 
151
151
  def publishable_transitions_for(user)
152
- record.with_acting_user(user) do
153
- available_transitions_for(user).select do |t|
154
- t.publishable_by(user, t.available_to, record)
155
- end
156
- end
152
+ available_transitions_for(user).select {|t| t.publishable_by(user, t.available_to, record)}
157
153
  end
158
154
 
159
155
 
@@ -202,7 +198,7 @@ module Hobo
202
198
  timestamp = record.read_attribute(key_timestamp_field)
203
199
  if timestamp
204
200
  timestamp = timestamp.getutc
205
- Digest::SHA1.hexdigest("#{record.id}-#{state_name}-#{timestamp}-#{Rails.application.config.secret_token}")
201
+ Digest::SHA1.hexdigest("#{record.id}-#{state_name}-#{timestamp}")
206
202
  end
207
203
  end
208
204
 
@@ -215,10 +211,6 @@ module Hobo
215
211
  provided_key && provided_key == key && !key_expired?
216
212
  end
217
213
 
218
- def clear_key
219
- record.send :write_attribute, key_timestamp_field, nil
220
- end
221
-
222
214
  def invariants_satisfied?
223
215
  self.class.invariants.all? { |i| record.instance_eval(&i) }
224
216
  end
@@ -34,7 +34,6 @@ module Hobo
34
34
 
35
35
 
36
36
  def change_state(record)
37
- record.lifecycle.clear_key unless options[:new_key] || options[:keep_key]
38
37
  record.lifecycle.become(get_state(record, end_state))
39
38
  end
40
39
 
@@ -19,6 +19,8 @@ module Hobo
19
19
  attr_accessor :acting_user, :origin, :origin_attribute
20
20
 
21
21
  bool_attr_accessor :exempt_from_edit_checks
22
+
23
+ define_callbacks :after_user_new
22
24
  end
23
25
  end
24
26
 
@@ -46,7 +48,7 @@ module Hobo
46
48
  r.set_creator user
47
49
  yield r if block_given?
48
50
  r.user_view(user)
49
- r.with_acting_user(user) { r.try.after_user_new }
51
+ r.with_acting_user(user) { r.send :run_callbacks, :after_user_new }
50
52
  end
51
53
  end
52
54
 
@@ -161,7 +163,6 @@ module Hobo
161
163
 
162
164
 
163
165
  def with_acting_user(user)
164
- return yield if user == acting_user
165
166
  old = acting_user
166
167
  self.acting_user = user
167
168
  result = yield
@@ -4,7 +4,7 @@ module Hobo
4
4
  module ApplyScopes
5
5
 
6
6
  def apply_scopes(scopes)
7
- result = scoped
7
+ result = self
8
8
  scopes.each_pair do |scope, arg|
9
9
  if arg.is_a?(Array)
10
10
  result = result.send(scope, *arg) unless arg.first.blank?