Sha256: dcdda9e1a50d2a95a788d7a9342e5c62bad0ae9577708d863d74798fd3a9b591
Contents?: true
Size: 775 Bytes
Versions: 18
Compression:
Stored size: 775 Bytes
Contents
module ActsAsRegionable extend ActiveSupport::Concern module ActiveRecord 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
18 entries across 18 versions & 1 rubygems