Module: Slices::HasSlices
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #embeded_slices(&block) ⇒ Object
- #messages_from_errors(errors) ⇒ Object
- #ordered_slices_for(embed_name = nil) ⇒ Object
- #slice_errors_for(embed_name) ⇒ Object
- #slices_for(embed_name) ⇒ Object
- #update_attributes(attributes) ⇒ Object
- #validate_slices ⇒ Object
Instance Method Details
#embeded_slices(&block) ⇒ Object
73 74 75 76 77 |
# File 'lib/slices/has_slices.rb', line 73 def (&block) self.class..each do || yield() end end |
#messages_from_errors(errors) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/slices/has_slices.rb', line 79 def (errors) if errors.respond_to?(:messages) errors. else errors end end |
#ordered_slices_for(embed_name = nil) ⇒ Object
49 50 51 52 |
# File 'lib/slices/has_slices.rb', line 49 def ordered_slices_for(=nil) = self.class..first if .nil? send("ordered_#{}") end |
#slice_errors_for(embed_name) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/slices/has_slices.rb', line 63 def slice_errors_for() Hash.new.tap do || slices_for().each do |slice| if ! slice.valid? && ! slice.to_delete? [slice.id_or_client_id] = (slice.errors) end end end end |
#slices_for(embed_name) ⇒ Object
45 46 47 |
# File 'lib/slices/has_slices.rb', line 45 def slices_for() send() end |
#update_attributes(attributes) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/slices/has_slices.rb', line 29 def update_attributes(attributes) [:slices, :set_slices].each do |type| next if attributes[type].nil? attributes[type] = attributes[type].map { |slice| slice = slice.symbolize_keys next if slice[:_destroy] slice.delete :_new klass = (slice[:type] + '_slice').camelize.constantize klass.new(slice) }.compact end super end |
#validate_slices ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/slices/has_slices.rb', line 54 def validate_slices do || _slice_errors = slice_errors_for() if _slice_errors.any? errors.add(, _slice_errors) end end end |