Class: AasmRbs::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/aasm_rbs/output.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Output

Returns a new instance of Output.



7
8
9
10
11
# File 'lib/aasm_rbs/output.rb', line 7

def initialize(klass)
  @klass = klass
  superclass = klass.superclass == Object ? nil : " < #{klass.superclass}"
  self.data = "class #{klass}#{superclass}\n"
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/aasm_rbs/output.rb', line 5

def data
  @data
end

Instance Method Details

#add_active_record_relationObject



28
29
30
31
32
33
34
35
36
# File 'lib/aasm_rbs/output.rb', line 28

def add_active_record_relation
  self.data += <<-RBS
  class ActiveRecord_Relation < ::ActiveRecord::Relation
include GeneratedRelationMethods
include _ActiveRecord_Relation[#{klass}, Integer]
include Enumerable[#{klass}]
  end
  RBS
end

#add_events(events) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/aasm_rbs/output.rb', line 19

def add_events(events)
  events.each do |event|
    self.data += "  def #{event}: (*untyped) -> bool\n"
    self.data += "  def #{event}!: (*untyped) -> bool\n"
    self.data += "  def #{event}_without_validation!: (*untyped) -> bool\n"
    self.data += "  def may_#{event}?: (*untyped) -> bool\n"
  end
end

#add_states(states, opts = {}) ⇒ Object



13
14
15
16
17
# File 'lib/aasm_rbs/output.rb', line 13

def add_states(states, opts = {})
  add_state_constants(states)
  add_state_scopes(states) if opts[:scopes]
  add_predicate_states_methods(states)
end

#finalizeObject



42
43
44
# File 'lib/aasm_rbs/output.rb', line 42

def finalize
  self.data += "end\n"
end

#new_lineObject



38
39
40
# File 'lib/aasm_rbs/output.rb', line 38

def new_line
  self.data += "\n"
end