Sha256: 47a2cdd32af2053a16a86939b1347ce0b61ca8fe267d209ad8480e24cf0df88d

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 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,
                        :params)
      end

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


Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
impressionist-1.6.0 lib/impressionist/setup_association.rb
impressionist-1.5.2 lib/impressionist/setup_association.rb
impressionist2-1.5.5 lib/impressionist/setup_association.rb
impressionist2-1.5.4 lib/impressionist/setup_association.rb
impressionist2-1.5.3 lib/impressionist/setup_association.rb
impressionist2-1.5.1 lib/impressionist/setup_association.rb