Sha256: af68a6e52c596c0c68ce0853fc9e6608bc9bcd9645bc2d222b070306a39e3644
Contents?: true
Size: 754 Bytes
Versions: 6
Compression:
Stored size: 754 Bytes
Contents
module ActsAsRegionable extend ActiveSupport::Concern module Base def acts_as_regionable(*options) @acts_as_regionable_opts = options || [] include ::ActsAsRegionable end end included do has_many :regions, as: :regionable, class_name: 'Effective::Region', dependent: :delete_all, autosave: true end module ClassMethods end def acts_as_regionable true end def region(title) title = title.to_s regions.to_a.find { |region| region.title == title } || regions.build(title: title) end def snippet_objects(klass = nil) objs = regions.map { |region| region.snippet_objects }.flatten if klass objs = objs.select { |obj| obj.class == klass } else objs end end end
Version data entries
6 entries across 6 versions & 1 rubygems