Sha256: b754b797787dccc4078d573e1511ed606f580e90ddb96ba7af7f216cebb9c4f0

Contents?: true

Size: 707 Bytes

Versions: 2

Compression:

Stored size: 707 Bytes

Contents

module IAmICan
  module Reflection
    extend ActiveSupport::Concern

    class_methods do
      # User._roles => 'stored_roles'
      %w[ subjects roles role_groups permissions ].each do |k|
        define_method "_#{k}" do
          v = instance_variable_get("@_#{k}")
          return v if v.present?
          instance_variable_set("@_#{k}", _reflect_of(k.singularize))
        end
      end
    end

    included do
      # user._roles => Association CollectionProxy, same as: `user.stored_roles`
      %w[ subjects roles role_groups permissions ].each do |k|
        define_method "_#{k}" do
          send(self.class.send("_#{k}")) if self.class.send("_#{k}")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
i_am_i_can-3.0.1 lib/i_am_i_can/reflection.rb
i_am_i_can-3.0.0 lib/i_am_i_can/reflection.rb