module DatashiftJourney

Helper class for constructing back links for navigating backward through the journey

Decorate a state machine enabled class with a set of extensions to :

https://github.com/state-machines/state_machines
https://github.com/state-machines/state_machines-activerecord

Constants

VERSION

Public Class Methods

journey_plan_class() click to toggle source
# File lib/datashift_journey.rb, line 48
def self.journey_plan_class
  @journey_plan_class = @journey_plan_class.to_s.constantize if @journey_plan_class.is_a?(String) || @journey_plan_class.is_a?(Symbol)
  @journey_plan_class
end
journey_plan_class=(x) click to toggle source

Set the main model class that contains the plan and associated state engine

# File lib/datashift_journey.rb, line 30
def self.journey_plan_class=(x)
  raise 'DSJ - journey_plan_class MUST be String or Symbol, not a Class.' if x.is_a?(Class)

  @journey_plan_class = x

  class << self
    define_method :"concern_file" do
      "#{@journey_plan_class.underscore}_journey.rb"
    end
  end

  # This is called from an initializer, we dont want to trigger the machine building till
  # the model class itself is loaded so do NOT do this here
  # @journey_plan_class = x.to_s.constantize if x.is_a?(String) || x.is_a?(Symbol)

  @journey_plan_class
end
library_path() click to toggle source
# File lib/datashift_journey.rb, line 13
def self.library_path
  File.expand_path("#{File.dirname(__FILE__)}/../lib")
end
load_commands() click to toggle source

Load all the datashift Thor commands and make them available throughout app

# File lib/datashift_journey.rb, line 19
def self.load_commands
  base = File.join(library_path, 'tasks', '**')

  Dir["#{base}/*.thor"].each do |f|
    next unless File.file?(f)
    load(f)
  end
end
state_names(machine: :state) click to toggle source
# File lib/datashift_journey.rb, line 53
def self.state_names(machine: :state)
  DatashiftJourney.journey_plan_class.state_machine(machine).states.map(&:name)
end