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

Version Path
effective_regions-1.8.5 app/models/concerns/acts_as_regionable.rb
effective_regions-1.8.4 app/models/concerns/acts_as_regionable.rb
effective_regions-1.7.6 app/models/concerns/acts_as_regionable.rb
effective_regions-1.8.3 app/models/concerns/acts_as_regionable.rb
effective_regions-1.8.2 app/models/concerns/acts_as_regionable.rb
effective_regions-1.8.1 app/models/concerns/acts_as_regionable.rb
effective_regions-1.8.0 app/models/concerns/acts_as_regionable.rb
effective_regions-1.7.5 app/models/concerns/acts_as_regionable.rb
effective_regions-1.7.4 app/models/concerns/acts_as_regionable.rb
effective_regions-1.7.3 app/models/concerns/acts_as_regionable.rb
effective_regions-1.7.2 app/models/concerns/acts_as_regionable.rb
effective_regions-1.7.1 app/models/concerns/acts_as_regionable.rb
effective_regions-1.7.0 app/models/concerns/acts_as_regionable.rb
effective_regions-1.6.14 app/models/concerns/acts_as_regionable.rb
effective_regions-1.6.12 app/models/concerns/acts_as_regionable.rb
effective_regions-1.6.11 app/models/concerns/acts_as_regionable.rb
effective_regions-1.6.10 app/models/concerns/acts_as_regionable.rb
effective_regions-1.6.9 app/models/concerns/acts_as_regionable.rb