Module: AasmRbs
- Defined in:
- lib/aasm_rbs.rb,
lib/aasm_rbs/output.rb,
lib/aasm_rbs/version.rb
Defined Under Namespace
Classes: Output
Constant Summary collapse
- VERSION =
'0.2.1'
Class Method Summary collapse
Class Method Details
.load_constants(klass_name) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/aasm_rbs.rb', line 6 def self.load_constants(klass_name) load('./Rakefile') if File.exist?('./Rakefile') begin Rake::Task[:environment].invoke rescue StandardError nil end return if defined?(Rails) # not in a Rails project, load the file manually file = Dir.pwd + "/lib/#{klass_name.split('::').join('/').downcase}" begin require file rescue LoadError abort('There was a problem loading the class file.') end end |
.run(klass_name, opts = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/aasm_rbs.rb', line 24 def self.run(klass_name, opts = {}) klass = Object.const_get(klass_name) output = Output.new(klass) states = klass.aasm.states.map(&:name) events = klass.aasm.events.map(&:name) create_scopes = klass.aasm.state_machine.config.create_scopes active_record_model = klass.respond_to?(:aasm_create_scope) opts[:scopes] = true if create_scopes && active_record_model output.add_states(states, opts) output.add_events(events) output.new_line && output.add_active_record_relation if opts[:scopes] output.finalize rescue StandardError abort('aasm_rbs received an invalid class name.') end |