Class: Logux::ClassFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/logux/class_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action:, meta:) ⇒ ClassFinder

Returns a new instance of ClassFinder.



9
10
11
12
# File 'lib/logux/class_finder.rb', line 9

def initialize(action:, meta:)
  @action = action
  @meta = meta
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/logux/class_finder.rb', line 5

def action
  @action
end

#metaObject (readonly)

Returns the value of attribute meta.



5
6
7
# File 'lib/logux/class_finder.rb', line 5

def meta
  @meta
end

Instance Method Details

#class_nameObject



32
33
34
35
36
37
38
# File 'lib/logux/class_finder.rb', line 32

def class_name
  if subscribe?
    action.channel_name.camelize
  else
    action.type.split('/')[0..-2].map(&:camelize).join('::')
  end
end

#find_action_classObject



14
15
16
17
18
19
20
21
# File 'lib/logux/class_finder.rb', line 14

def find_action_class
  "#{class_namespace}::#{class_name}".constantize
rescue NameError
  message =
    "Unable to find action #{class_name.camelize}.\n" \
    "Should be in app/logux/#{class_namespace.downcase}/#{class_path}.rb"
  raise_error_for_failed_find(message)
end

#find_policy_classObject



23
24
25
26
27
28
29
30
# File 'lib/logux/class_finder.rb', line 23

def find_policy_class
  "Policies::#{class_namespace}::#{class_name}".constantize
rescue NameError
  message =
    "Unable to find action policy #{class_name.camelize}.\n" \
    "Should be in app/logux/#{class_namespace.downcase}/#{class_path}.rb"
  raise_error_for_failed_find(message)
end