Class: AasmRbs::Output
- Inherits:
-
Object
- Object
- AasmRbs::Output
- Defined in:
- lib/aasm_rbs/output.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
- #add_active_record_relation ⇒ Object
- #add_events(events) ⇒ Object
- #add_states(states, opts = {}) ⇒ Object
- #finalize ⇒ Object
-
#initialize(klass) ⇒ Output
constructor
A new instance of Output.
- #new_line ⇒ Object
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
#data ⇒ Object
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_relation ⇒ Object
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 |
#finalize ⇒ Object
42 43 44 |
# File 'lib/aasm_rbs/output.rb', line 42 def finalize self.data += "end\n" end |
#new_line ⇒ Object
38 39 40 |
# File 'lib/aasm_rbs/output.rb', line 38 def new_line self.data += "\n" end |