Sha256: 7411c3ca4a3e8b48b7c1f1f0742b7e4ee381f258c627b8d85aadf596fd4b5bc9

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

module Impressionist
  # Impressionist::SetupAssociation.new(entity).set
  class SetupAssociation
    def initialize(receiver)
      @receiver = receiver
    end

    # True or False
    # Note toggle returns false if rails >= 4
    def include_attr_acc?
      toggle && make_accessible
    end

    def define_belongs_to
      receiver.belongs_to(:impressionable, :polymorphic => true)
    end

    def set
      define_belongs_to
      include_attr_acc?
    end

    private
      attr_reader :receiver, :toggle

      def make_accessible
       receiver.
        attr_accessible(:impressionable_type,
                        :impressionable_id,
                        :controller_name,
                        :request_hash,
                        :session_hash,
                        :action_name,
                        :ip_address,
                        :view_name,
                        :referrer,
                        :message,
                        :user_id)
      end

      def toggle
        t = RailsToggle.new
        t.should_include?
      end
  end
end


Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
impressionist-1.5.1 lib/impressionist/setup_association.rb
impressionist-1.4.13 lib/impressionist/setup_association.rb
impressionist-1.4.12 lib/impressionist/setup_association.rb
impressionist-1.4.11 lib/impressionist/setup_association.rb
impressionist-1.4.10 lib/impressionist/setup_association.rb
impressionist-1.4.9 lib/impressionist/setup_association.rb
impressionist-1.4.8 lib/impressionist/setup_association.rb