app/models/concerns/spina/partable.rb in spina-0.11.1 vs app/models/concerns/spina/partable.rb in spina-0.12.0
- old
+ new
@@ -1,9 +1,24 @@
module Spina
module Partable
- def part(part)
- part = parts.where(name: part[:name]).first || parts.build(part)
- part.partable = part.partable_type.constantize.new unless part.partable.present?
- part
+ extend ActiveSupport::Concern
+
+ included do
+ def part(attributes)
+ part = parts.where(name: attributes[:name]).first_or_initialize(attributes)
+ part.partable = part.partable_type.constantize.new if part.partable.blank?
+ part.options = attributes[:options]
+ part
+ end
+
+ def has_content?(name)
+ content(name).present?
+ end
+
+ def content(name)
+ part = parts.find_by(name: name)
+ part.try(:content)
+ end
+
end
end
-end
\ No newline at end of file
+end