Class: Evil::Client::Policy

Inherits:
Tram::Policy
  • Object
show all
Defined in:
lib/evil/client/policy.rb

Overview

Base class for policies that validate settings

Class Attribute Summary collapse

Class Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object (private)



52
53
54
# File 'lib/evil/client/policy.rb', line 52

def method_missing(*args)
  respond_to_missing?(*args) ? model.__send__(*args) : super
end

Class Attribute Details

.modelClass? (readonly)

Reference to the model whose instances are validated by the policy

Returns:

  • (Class, nil)


22
23
24
# File 'lib/evil/client/policy.rb', line 22

def model
  @model
end

Class Method Details

.for(model) ⇒ Class

Subclasses itself for a model class

Parameters:

  • model (Class)

    Settings class to validate

Returns:

  • (Class)


12
13
14
15
16
# File 'lib/evil/client/policy.rb', line 12

def for(model)
  Class.new(self).tap do |klass|
    klass.send :instance_variable_set, :@model, model
  end
end

.nameString? Also known as: to_s, to_sym, inspect

Delegates the name of the policy to the name of checked model

Returns:

  • (String, nil)


28
29
30
# File 'lib/evil/client/policy.rb', line 28

def name
  "#{model}.policy"
end