Class: GraphqlRails::Router::EventRoute

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql_rails/router/event_route.rb

Overview

stores subscription type graphql action info

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, subscription_class: nil, groups: nil, scope_names: [], **options) ⇒ EventRoute

Returns a new instance of EventRoute.



11
12
13
14
15
16
17
# File 'lib/graphql_rails/router/event_route.rb', line 11

def initialize(name, subscription_class: nil, groups: nil, scope_names: [], **options)
  @name = name.to_s.camelize(:lower)
  @module_name = options[:module].to_s
  @groups = groups
  @subscription_class = subscription_class
  @scope_names = scope_names
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



9
10
11
# File 'lib/graphql_rails/router/event_route.rb', line 9

def groups
  @groups
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



9
10
11
# File 'lib/graphql_rails/router/event_route.rb', line 9

def module_name
  @module_name
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/graphql_rails/router/event_route.rb', line 9

def name
  @name
end

#scope_namesObject (readonly)

Returns the value of attribute scope_names.



9
10
11
# File 'lib/graphql_rails/router/event_route.rb', line 9

def scope_names
  @scope_names
end

#subscription_classObject (readonly)

Returns the value of attribute subscription_class.



9
10
11
# File 'lib/graphql_rails/router/event_route.rb', line 9

def subscription_class
  @subscription_class
end

Instance Method Details

#event?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/graphql_rails/router/event_route.rb', line 47

def event?
  true
end

#field_optionsObject



25
26
27
# File 'lib/graphql_rails/router/event_route.rb', line 25

def field_options
  { subscription: subscription }
end

#mutation?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/graphql_rails/router/event_route.rb', line 39

def mutation?
  false
end

#query?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/graphql_rails/router/event_route.rb', line 43

def query?
  false
end

#show_in_group?(group_name) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/graphql_rails/router/event_route.rb', line 19

def show_in_group?(group_name)
  return true if groups.nil? || groups.empty?

  groups.include?(group_name&.to_sym)
end

#subscriptionObject



29
30
31
32
33
34
35
36
37
# File 'lib/graphql_rails/router/event_route.rb', line 29

def subscription
  if subscription_class.present?
    subscription_class.is_a?(String) ? Object.const_get(subscription_class) : subscription_class
  else
    klass_name = ['subscriptions/', name.underscore, 'subscription'].join('_').camelize

    Object.const_get(klass_name)
  end
end