Class: Zuul::Context

Inherits:
Struct
  • Object
show all
Defined in:
lib/zuul/context.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name

Returns:

  • (Object)

    the current value of class_name



2
3
4
# File 'lib/zuul/context.rb', line 2

def class_name
  @class_name
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



2
3
4
# File 'lib/zuul/context.rb', line 2

def id
  @id
end

Class Method Details

.parse(*args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/zuul/context.rb', line 4

def self.parse(*args)
  if args.length >= 2
    new(*args)
  elsif args[0].is_a?(self)
    return args[0]
  elsif args[0].is_a?(Class)
    new(args[0].name)
  elsif args[0].class.ancestors.include?(::ActiveRecord::Base) && args[0].respond_to?(:id)
    new(args[0].class.name, args[0].id)
  else
    new
  end
end

Instance Method Details

#class?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/zuul/context.rb', line 23

def class?
  !class_name.nil? && id.nil?
end

#instance?Boolean Also known as: object?

Returns:

  • (Boolean)


18
19
20
# File 'lib/zuul/context.rb', line 18

def instance?
  !class_name.nil? && !id.nil?
end

#nil?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/zuul/context.rb', line 27

def nil?
  class_name.nil? && id.nil?
end

#to_contextObject Also known as: context



43
44
45
46
47
# File 'lib/zuul/context.rb', line 43

def to_context
  return nil if class_name.nil?
  return class_name.constantize if id.nil?
  class_name.constantize.find(id)
end

#typeObject



31
32
33
34
35
# File 'lib/zuul/context.rb', line 31

def type
  return :nil if class_name.nil?
  return :class if id.nil?
  :instance
end

#type_sObject



37
38
39
40
41
# File 'lib/zuul/context.rb', line 37

def type_s
  return 'global' if class_name.nil?
  return class_name if id.nil?
  "#{class_name}(#{id})"
end