class Permittribute::Attrs

Public Class Methods

all() click to toggle source
# File lib/permittribute/attrs.rb, line 7
def all
  @@defined_meth_names.values.flatten
end
configure_with_role(role) { |attributes_group_by_roles| ... } click to toggle source
# File lib/permittribute/attrs.rb, line 15
def configure_with_role(role, &block)
  @@attributes_group_by_roles[role] ||= OpenStruct.new

  yield @@attributes_group_by_roles[role]

  define_role_attribute_methods(role)
  @@defined_meth_names[role].uniq!
end
define_role_attribute_method(role, attribute, params) click to toggle source
# File lib/permittribute/attrs.rb, line 30
      def define_role_attribute_method(role, attribute, params)
        meth_name = (role == :default ? attribute : "#{role}_#{attribute}").to_sym
        unless respond_to? meth_name
          instance_eval <<-eometh
            def #{meth_name}
              @@attributes_group_by_roles['#{role}'.to_sym].send('#{attribute}'.to_sym)
            end
          eometh

          @@defined_meth_names[role] << meth_name
        end
      end
define_role_attribute_methods(role) click to toggle source
# File lib/permittribute/attrs.rb, line 24
def define_role_attribute_methods(role)
  @@attributes_group_by_roles[role].each_pair do |attribute, params|
    define_role_attribute_method(role, attribute, params)
  end
end
defined_meth_names_for_role(role) click to toggle source
# File lib/permittribute/attrs.rb, line 11
def defined_meth_names_for_role(role)
  @@defined_meth_names[role] || []
end