Class: Objectify::Config::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/objectify/config/context.rb

Constant Summary collapse

DONT_RELOAD =
[:@objectify_controller,
:@policies_factory,
:@action_factory].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(policies_factory = Policies, action_factory = Action) ⇒ Context

Returns a new instance of Context.



19
20
21
22
# File 'lib/objectify/config/context.rb', line 19

def initialize(policies_factory = Policies, action_factory = Action)
  @policies_factory = policies_factory
  @action_factory   = action_factory
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



15
16
17
# File 'lib/objectify/config/context.rb', line 15

def actions
  @actions
end

#defaultsObject (readonly)

Returns the value of attribute defaults.



15
16
17
# File 'lib/objectify/config/context.rb', line 15

def defaults
  @defaults
end

#executorObject



99
100
101
# File 'lib/objectify/config/context.rb', line 99

def executor
  @executor ||= Executor.new(injector, instantiator)
end

#injectablesObject



67
68
69
# File 'lib/objectify/config/context.rb', line 67

def injectables
  @injectables ||= Injectables.new
end

#injectorObject



63
64
65
# File 'lib/objectify/config/context.rb', line 63

def injector
  @injector ||= Injector.new(injectables)
end

#instantiatorObject



95
96
97
# File 'lib/objectify/config/context.rb', line 95

def instantiator
  @instantiator ||= Instantiator.new(injector)
end

#objectify_controllerObject



103
104
105
# File 'lib/objectify/config/context.rb', line 103

def objectify_controller
  @objectify_controller ||= "objectify/rails/objectify"
end

#policiesObject (readonly)

Returns the value of attribute policies.



15
16
17
# File 'lib/objectify/config/context.rb', line 15

def policies
  @policies
end

#policy_respondersObject (readonly)

Returns the value of attribute policy_responders.



15
16
17
# File 'lib/objectify/config/context.rb', line 15

def policy_responders
  @policy_responders
end

Instance Method Details

#action(route) ⇒ Object



53
54
55
56
# File 'lib/objectify/config/context.rb', line 53

def action(route)
  actions[route] ||
    raise(ArgumentError, "No action matching #{route} was found.")
end

#append_action(action) ⇒ Object



49
50
51
# File 'lib/objectify/config/context.rb', line 49

def append_action(action)
  actions[action.route] = action
end

#append_decorators(opts) ⇒ Object



89
90
91
92
93
# File 'lib/objectify/config/context.rb', line 89

def append_decorators(opts)
  opts.each do |k,v|
    injectables.add_decorators(k, v)
  end
end

#append_defaults(defaults) ⇒ Object



41
42
43
# File 'lib/objectify/config/context.rb', line 41

def append_defaults(defaults)
  @policies = @policies_factory.new(defaults)
end

#append_implementations(opts) ⇒ Object



77
78
79
80
81
# File 'lib/objectify/config/context.rb', line 77

def append_implementations(opts)
  opts.each do |k,v|
    injectables.add_implementation(k, v)
  end
end

#append_policy_responders(responders) ⇒ Object



28
29
30
# File 'lib/objectify/config/context.rb', line 28

def append_policy_responders(responders)
  policy_responders.merge!(responders)
end

#append_resolvers(opts) ⇒ Object



83
84
85
86
87
# File 'lib/objectify/config/context.rb', line 83

def append_resolvers(opts)
  opts.each do |k,v|
    injectables.add_resolver(k, v)
  end
end

#append_values(opts) ⇒ Object



71
72
73
74
75
# File 'lib/objectify/config/context.rb', line 71

def append_values(opts)
  opts.each do |k,v|
    injectables.add_value(k, v)
  end
end

#legacy_action(route) ⇒ Object



58
59
60
61
# File 'lib/objectify/config/context.rb', line 58

def legacy_action(route)
  actions[route] ||
    @action_factory.new(route.opts, route.opts[:controller], route.opts[:action], {}, policies)
end

#policy_responder(policy) ⇒ Object



32
33
34
35
# File 'lib/objectify/config/context.rb', line 32

def policy_responder(policy)
  policy_responders[policy] ||
    raise(ArgumentError, "Can't find a responder for #{policy}.")
end

#reloadObject



107
108
109
110
111
# File 'lib/objectify/config/context.rb', line 107

def reload
  instance_variables.each do |name|
    instance_variable_set(name, nil) unless DONT_RELOAD.include?(name)
  end
end