Class: Spoom::Deadcode::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/spoom/deadcode/definition.rb

Overview

A definition is a class, module, method, constant, etc. being defined in the code

Defined Under Namespace

Classes: Kind, Status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind:, name:, full_name:, location:, status: Status::DEAD) ⇒ Definition

: (kind: Kind, name: String, full_name: String, location: Location, ?status: Status) -> void



53
54
55
56
57
58
59
# File 'lib/spoom/deadcode/definition.rb', line 53

def initialize(kind:, name:, full_name:, location:, status: Status::DEAD)
  @kind = kind
  @name = name
  @full_name = full_name
  @location = location
  @status = status
end

Instance Attribute Details

#full_name ⇒ Object (readonly)

: String



44
45
46
# File 'lib/spoom/deadcode/definition.rb', line 44

def full_name
  @full_name
end

#kind ⇒ Object (readonly)

: Kind



38
39
40
# File 'lib/spoom/deadcode/definition.rb', line 38

def kind
  @kind
end

#location ⇒ Object (readonly)

: Location



47
48
49
# File 'lib/spoom/deadcode/definition.rb', line 47

def location
  @location
end

#name ⇒ Object (readonly)

: String



41
42
43
# File 'lib/spoom/deadcode/definition.rb', line 41

def name
  @name
end

#status ⇒ Object (readonly)

: Status



50
51
52
# File 'lib/spoom/deadcode/definition.rb', line 50

def status
  @status
end

Instance Method Details

#alive! ⇒ Object

: -> void



101
102
103
# File 'lib/spoom/deadcode/definition.rb', line 101

def alive!
  @status = Status::ALIVE
end

#alive? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


96
97
98
# File 'lib/spoom/deadcode/definition.rb', line 96

def alive?
  status == Status::ALIVE
end

#attr_reader? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


64
65
66
# File 'lib/spoom/deadcode/definition.rb', line 64

def attr_reader?
  kind == Kind::AttrReader
end

#attr_writer? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


69
70
71
# File 'lib/spoom/deadcode/definition.rb', line 69

def attr_writer?
  kind == Kind::AttrWriter
end

#class? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


74
75
76
# File 'lib/spoom/deadcode/definition.rb', line 74

def class?
  kind == Kind::Class
end

#constant? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


79
80
81
# File 'lib/spoom/deadcode/definition.rb', line 79

def constant?
  kind == Kind::Constant
end

#dead? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


106
107
108
# File 'lib/spoom/deadcode/definition.rb', line 106

def dead?
  status == Status::DEAD
end

#ignored! ⇒ Object

: -> void



116
117
118
# File 'lib/spoom/deadcode/definition.rb', line 116

def ignored!
  @status = Status::IGNORED
end

#ignored? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


111
112
113
# File 'lib/spoom/deadcode/definition.rb', line 111

def ignored?
  status == Status::IGNORED
end

#method? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


84
85
86
# File 'lib/spoom/deadcode/definition.rb', line 84

def method?
  kind == Kind::Method
end

#module? ⇒ Boolean

: -> bool

Returns:

  • (Boolean)


89
90
91
# File 'lib/spoom/deadcode/definition.rb', line 89

def module?
  kind == Kind::Module
end

#to_json(*args) ⇒ Object

: (*untyped args) -> String



123
124
125
126
127
128
129
# File 'lib/spoom/deadcode/definition.rb', line 123

def to_json(*args)
  {
    kind: kind,
    name: name,
    location: location.to_s,
  }.to_json
end