source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/formtastic/actions/base.rb
Ruby
mit
5,205
master
4,928
# frozen_string_literal: true module Formtastic module Actions module Base include Formtastic::LocalizedString attr_accessor :builder, :template, :object, :object_name, :method, :options def initialize(builder, template, object, object_name, method, options) @builder = builder ...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/formtastic/actions/buttonish.rb
Ruby
mit
5,205
master
274
# frozen_string_literal: true module Formtastic module Actions module Buttonish def supported_methods [:submit, :reset] end def extra_button_html_options { :type => method } end end end end
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/formtastic/actions/button_action.rb
Ruby
mit
5,205
master
2,540
# frozen_string_literal: true module Formtastic module Actions # Outputs a `<button type="submit">` or `<button type="reset">` wrapped in the standard `<li>` # wrapper. This is an alternative choice for `:submit` and `:reset` actions, which render with # `<input type="submit">` and `<input type="reset">` by de...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/generators/formtastic/install/install_generator.rb
Ruby
mit
5,205
master
700
# frozen_string_literal: true module Formtastic # Copies a config initializer to config/initializers/formtastic.rb # # @example # !!!shell # $ rails generate formtastic:install class InstallGenerator < Rails::Generators::Base source_root File.expand_path('../../../templates', __FILE__) class_opti...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/generators/formtastic/input/input_generator.rb
Ruby
mit
5,205
master
1,434
# frozen_string_literal: true module Formtastic # Modify existing inputs, subclass them, or create your own from scratch. # @example # !!!shell # $ rails generate formtastic:input HatSize # @example Define input name using underscore convention # !!!shell # $ rails generate formtastic:input hat_size...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/generators/formtastic/stylesheets/stylesheets_generator.rb
Ruby
mit
5,205
master
458
module Formtastic # Copies a stylesheet into to app/assets/stylesheets/formtastic.css # # @example # !!!shell # $ rails generate formtastic:stylesheets class StylesheetsGenerator < Rails::Generators::Base source_root File.expand_path("../../../templates", __FILE__) desc "Copies Formtastic example...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/generators/formtastic/form/form_generator.rb
Ruby
mit
5,205
master
3,929
# frozen_string_literal: true module Formtastic # Generates a Formtastic form partial based on an existing model. It will not overwrite existing # files without confirmation. # # @example # !!!shell # $ rails generate formtastic:form Post # @example Copy the partial code to the pasteboard rather than ge...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/generators/templates/formtastic.rb
Ruby
mit
5,205
master
6,745
# frozen_string_literal: true # Set the default text field size when input is a string. Default is nil. # Formtastic::FormBuilder.default_text_field_size = 50 # Set the default text area height when input is a text. Default is 20. # Formtastic::FormBuilder.default_text_area_height = 5 # Set the default text area wid...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
lib/generators/templates/input.rb
Ruby
mit
5,205
master
449
class <%= name.camelize %>Input <%= @extension_sentence %> <%- if !options[:extend] -%> include Formtastic::Inputs::Base <%- end -%> <%- if !options[:extend] || (options[:extend] == "extend") -%> def to_html # Add your custom input definition here. <%- if options[:extend] == "extend" -%> super ...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
script/integration-template.rb
Ruby
mit
5,205
master
2,396
# frozen_string_literal: true gem 'formtastic', path: '..' gem 'bcrypt' gem 'rails-dom-testing', group: :test gem 'minitest', '~> 5.27' # TODO: Remove this line when the Rails version used for integration tests will include rails/rails#56202 # to speed up bundle install, reuse the bundle path def bundle_path File.e...
github
formtastic/formtastic
https://github.com/formtastic/formtastic
sample/config.ru
Ruby
mit
5,205
master
1,453
module Rack module Formtastic class Samples def initialize(app) @app = app end def call(env) @status, @headers, @body = @app.call(env) @env = env @body = '' if favicon? @body = static_file if !favicon? && static_file? @body = styl...
github
aasm/aasm
https://github.com/aasm/aasm
Appraisals
Ruby
mit
5,199
master
621
appraise 'rails_7.1' do gem 'rails', '~> 7.1.0' gem "redis-objects" gem 'mongoid' gem 'sequel' gem 'dynamoid' gem 'aws-sdk-dynamodb' gem 'redis-objects' gem 'after_commit_everywhere' end appraise 'rails_7.2' do gem 'rails', '~> 7.2.0' gem "redis-objects" gem 'mongoid' gem 'sequel' gem 'dynam...
github
aasm/aasm
https://github.com/aasm/aasm
Rakefile
Ruby
mit
5,199
master
686
require 'bundler/gem_tasks' require 'rspec/core' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = FileList['spec/**/*_spec.rb'] end require 'rake/testtask' Rake::TestTask.new(:test) do |test| test.libs << 'lib' << 'test' test.pattern = 'test/**/*_test.rb' test.verbose =...
github
aasm/aasm
https://github.com/aasm/aasm
aasm.gemspec
Ruby
mit
5,199
master
1,428
# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "aasm/version" Gem::Specification.new do |s| s.name = "aasm" s.version = AASM::VERSION s.authors = ["Thorsten Boettger", "Anil Maurya"] s.email = %q{aasm@mt7.de, anilmaurya8dec@gmail.com} s.homepage = %q{ht...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm.rb
Ruby
mit
5,199
master
645
require 'aasm/version' require 'aasm/errors' require 'aasm/configuration' require 'aasm/base' require 'aasm/dsl_helper' require 'aasm/instance_base' require 'aasm/core/transition' require 'aasm/core/event' require 'aasm/core/state' require 'aasm/core/invoker' require 'aasm/core/invokers/base_invoker' require 'aasm/core...
github
aasm/aasm
https://github.com/aasm/aasm
lib/motion-aasm.rb
Ruby
mit
5,199
master
1,331
unless defined?(Motion::Project::App) raise "This must be required from within a RubyMotion Rakefile" end file_dependencies = { 'aasm/aasm.rb' => ['aasm/persistence.rb'], 'aasm/persistence.rb' => ['aasm/persistence/plain_persistence.rb', 'aasm/persistence/core_data_query_persistence.rb'], 'aasm/persistence/bas...
github
aasm/aasm
https://github.com/aasm/aasm
lib/generators/nobrainer/aasm_generator.rb
Ruby
mit
5,199
master
820
require 'rails/generators/named_base' require 'generators/aasm/orm_helpers' module NoBrainer module Generators class AASMGenerator < Rails::Generators::NamedBase include AASM::Generators::OrmHelpers namespace 'nobrainer:aasm' argument :column_name, type: :string, default: 'aasm_state' de...
github
aasm/aasm
https://github.com/aasm/aasm
lib/generators/mongoid/aasm_generator.rb
Ruby
mit
5,199
master
786
require 'rails/generators/named_base' require 'generators/aasm/orm_helpers' module Mongoid module Generators class AASMGenerator < Rails::Generators::NamedBase include AASM::Generators::OrmHelpers namespace "mongoid:aasm" argument :column_name, type: :string, default: 'aasm_state' def ge...
github
aasm/aasm
https://github.com/aasm/aasm
lib/generators/aasm/orm_helpers.rb
Ruby
mit
5,199
master
667
module AASM module Generators module OrmHelpers def model_contents if column_name == 'aasm_state' <<RUBY include AASM aasm do end RUBY else <<RUBY include AASM aasm :column => '#{column_name}' do end RUBY end end private def column_exists? t...
github
aasm/aasm
https://github.com/aasm/aasm
lib/generators/aasm/aasm_generator.rb
Ruby
mit
5,199
master
399
require 'rails/generators/named_base' module AASM module Generators class AASMGenerator < Rails::Generators::NamedBase namespace "aasm" argument :column_name, type: :string, default: 'aasm_state' desc "Generates a model with the given NAME (if one does not exist) with aasm " << "block an...
github
aasm/aasm
https://github.com/aasm/aasm
lib/generators/active_record/aasm_generator.rb
Ruby
mit
5,199
master
1,213
require 'rails/generators/active_record' require 'generators/aasm/orm_helpers' module ActiveRecord module Generators class AASMGenerator < ActiveRecord::Generators::Base include AASM::Generators::OrmHelpers namespace "active_record:aasm" argument :column_name, type: :string, default: 'aasm_stat...
github
aasm/aasm
https://github.com/aasm/aasm
lib/generators/active_record/templates/migration.rb
Ruby
mit
5,199
master
255
class AasmCreate<%= table_name.camelize %> < ActiveRecord::Migration[<%= ActiveRecord::VERSION::STRING.to_f %>] def change create_table(:<%= table_name %>) do |t| t.string :<%= column_name %> t.timestamps null: false end end end
github
aasm/aasm
https://github.com/aasm/aasm
lib/generators/active_record/templates/migration_existing.rb
Ruby
mit
5,199
master
222
class Add<%= column_name.camelize %>To<%= table_name.camelize %> < ActiveRecord::Migration[<%= ActiveRecord::VERSION::STRING.to_f %>] def change add_column :<%= table_name %>, :<%= column_name %>, :string end end
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/configuration.rb
Ruby
mit
5,199
master
1,415
module AASM class Configuration # for all persistence layers: which database column to use? attr_accessor :column # let's cry if the transition is invalid attr_accessor :whiny_transitions # for all persistence layers: create named scopes for each state attr_accessor :create_scopes # for...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/errors.rb
Ruby
mit
5,199
master
802
module AASM class UnknownStateMachineError < RuntimeError; end class InvalidTransition < RuntimeError attr_reader :object, :event_name, :originating_state, :failures, :state_machine_name def initialize(object, event_name, state_machine_name, failures = []) @object, @event_name, @originating_state, ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/minitest_spec.rb
Ruby
mit
5,199
master
756
require 'aasm/minitest' module Minitest::Expectations AASM.infect_an_assertion :assert_transitions_from, :must_transition_from, :do_not_flip AASM.infect_an_assertion :refute_transitions_from, :wont_transition_from, :do_not_flip AASM.infect_an_assertion :assert_transition_to_allowed, :must_allow_transition_to, :...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/state_machine.rb
Ruby
mit
5,199
master
1,554
module AASM class StateMachine # the following four methods provide the storage of all state machines attr_accessor :states, :events, :initial_state, :config, :name, :global_callbacks def initialize(name) @initial_state = nil @states = [] @events = {} @global_callbacks = {} ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/instance_base.rb
Ruby
mit
5,199
master
4,645
module AASM class InstanceBase attr_accessor :from_state, :to_state, :current_event def initialize(instance, name=:default) # instance of the class including AASM, name of the state machine @instance = instance @name = name end def current_state @instance.aasm_read_state(@name) ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/base.rb
Ruby
mit
5,199
master
10,011
require 'logger' module AASM class Base attr_reader :klass, :state_machine def initialize(klass, name, state_machine, options={}, &block) @klass = klass @name = name # @state_machine = klass.aasm(@name).state_machine @state_machine = state_machine @state_machine.config.column ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/minitest.rb
Ruby
mit
5,199
master
223
Minitest = MiniTest unless defined? Minitest # relative-require all minitest_spec files Dir[File.dirname(__FILE__) + '/minitest/*.rb'].each do |file| require 'aasm/minitest/' + File.basename(file, File.extname(file)) end
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/dsl_helper.rb
Ruby
mit
5,199
master
706
module AASM module DslHelper class Proxy attr_accessor :options def initialize(options, valid_keys, source) @valid_keys = valid_keys @source = source @options = options end def method_missing(name, *args, &block) if @valid_keys.include?(name) o...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/state_machine_store.rb
Ruby
mit
5,199
master
2,134
require 'concurrent/map' module AASM class StateMachineStore @stores = Concurrent::Map.new class << self def stores @stores end # do not overwrite existing state machines, which could have been created by # inheritance, see AASM::ClassMethods method inherited def regis...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/aasm.rb
Ruby
mit
5,199
master
7,508
module AASM # this is used internally as an argument default value to represent no value NO_VALUE = :_aasm_no_value # provide a state machine for the including class # make sure to load class methods as well # initialize persistence for the state machine def self.included(base) #:nodoc: base.extend AAS...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/localizer.rb
Ruby
mit
5,199
master
2,153
module AASM class Localizer def human_event_name(klass, event) checklist = ancestors_list(klass).inject([]) do |list, ancestor| list << :"#{i18n_scope(klass)}.events.#{i18n_klass(ancestor)}.#{event}" list end translate_queue(checklist) || I18n.translate(checklist.shift, :default ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence.rb
Ruby
mit
5,199
master
1,818
module AASM module Persistence class << self def load_persistence(base) # Use a fancier auto-loading thingy, perhaps. When there are more persistence engines. hierarchy = base.ancestors.map {|klass| klass.to_s} if hierarchy.include?("ActiveRecord::Base") require_persiste...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/sequel_persistence.rb
Ruby
mit
5,199
master
2,505
require 'aasm/persistence/orm' module AASM module Persistence module SequelPersistence def self.included(base) base.send(:include, AASM::Persistence::Base) base.send(:include, AASM::Persistence::ORM) base.send(:include, AASM::Persistence::SequelPersistence::InstanceMethods) end...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/dynamoid_persistence.rb
Ruby
mit
5,199
master
3,520
module AASM module Persistence module DynamoidPersistence def self.included(base) base.send(:include, AASM::Persistence::Base) base.send(:include, AASM::Persistence::DynamoidPersistence::InstanceMethods) base.after_initialize :aasm_ensure_initial_state # Because Dynamoid on...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/base.rb
Ruby
mit
5,199
master
2,529
module AASM module Persistence module Base def self.included(base) #:nodoc: base.extend ClassMethods end # Returns the value of the aasm.attribute_name - called from <tt>aasm.current_state</tt> # # If it's a new record, and the aasm state column is blank it returns the init...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/no_brainer_persistence.rb
Ruby
mit
5,199
master
2,963
require 'aasm/persistence/orm' module AASM module Persistence module NoBrainerPersistence # This method: # # * extends the model with ClassMethods # * includes InstanceMethods # # Adds # # before_validation :aasm_ensure_initial_state # # As a result, i...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/mongoid_persistence.rb
Ruby
mit
5,199
master
4,058
require 'aasm/persistence/orm' module AASM module Persistence module MongoidPersistence # This method: # # * extends the model with ClassMethods # * includes InstanceMethods # # Adds # # before_validation :aasm_ensure_initial_state # # As a result, it ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/active_record_persistence.rb
Ruby
mit
5,199
master
6,351
require 'aasm/persistence/orm' module AASM module Persistence module ActiveRecordPersistence # This method: # # * extends the model with ClassMethods # * includes InstanceMethods # # Adds # # after_initialize :aasm_ensure_initial_state # # As a result,...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/orm.rb
Ruby
mit
5,199
master
5,366
module AASM module Persistence # This module adds transactional support for any database that supports it. # This includes rollback capability and rollback/commit callbacks. module ORM # Writes <tt>state</tt> to the state column and persists it to the database # # foo = Foo.find(1) ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/redis_persistence.rb
Ruby
mit
5,199
master
3,801
module AASM module Persistence module RedisPersistence def self.included(base) base.send(:include, AASM::Persistence::Base) base.send(:include, AASM::Persistence::RedisPersistence::InstanceMethods) end module InstanceMethods # Initialize with default values # ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/plain_persistence.rb
Ruby
mit
5,199
master
909
module AASM module Persistence module PlainPersistence # may be overwritten by persistence mixins def aasm_read_state(name=:default) # all the following lines behave like @current_state ||= aasm(name).enter_initial_state current = aasm(name).instance_variable_defined?("@current_state_...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/persistence/core_data_query_persistence.rb
Ruby
mit
5,199
master
3,480
module AASM module Persistence module CoreDataQueryPersistence # This method: # # * extends the model with ClassMethods # * includes InstanceMethods # # Adds # # after_initialize :aasm_ensure_initial_state # def self.included(base) base.send(:...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/rspec/transition_from.rb
Ruby
mit
5,199
master
1,049
RSpec::Matchers.define :transition_from do |from_state| match do |obj| @state_machine_name ||= :default obj.aasm(@state_machine_name).current_state = from_state.to_sym begin obj.send(@event, *@args) && obj.aasm(@state_machine_name).current_state == @to_state.to_sym rescue AASM::InvalidTransition...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/rspec/allow_transition_to.rb
Ruby
mit
5,199
master
701
RSpec::Matchers.define :allow_transition_to do |state| match do |obj| @state_machine_name ||= :default obj.aasm(@state_machine_name).states({:permitted => true}, *@args).include?(state) end chain :on do |state_machine_name| @state_machine_name = state_machine_name end chain :with do |*args| ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/rspec/allow_event.rb
Ruby
mit
5,199
master
659
RSpec::Matchers.define :allow_event do |event| match do |obj| @state_machine_name ||= :default obj.aasm(@state_machine_name).may_fire_event?(event, *@args) end chain :on do |state_machine_name| @state_machine_name = state_machine_name end chain :with do |*args| @args = args end descript...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/rspec/have_state.rb
Ruby
mit
5,199
master
667
RSpec::Matchers.define :have_state do |state| match do |obj| @state_machine_name ||= :default obj.aasm(@state_machine_name).current_state == state.to_sym end chain :on do |state_machine_name| @state_machine_name = state_machine_name end description do "have state #{expected} (on :#{@state_ma...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/minitest/have_state.rb
Ruby
mit
5,199
master
636
module Minitest::Assertions def assert_have_state(object, state, options = {}) state_machine_name = options.fetch(:on, :default) assert object.aasm(state_machine_name).current_state == state, "Expected that :#{object.aasm(state_machine_name).current_state} would be :#{state} (on :#{state_machine_name...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/minitest/transition_from.rb
Ruby
mit
5,199
master
957
module Minitest::Assertions def assert_transitions_from(object, from_state, *args) options = args.first options[:on] ||= :default assert _transitions_from?(object, from_state, args, options), "Expected transition state to :#{options[:to]} from :#{from_state} on event :#{options[:on_event]}, (on ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/minitest/allow_event.rb
Ruby
mit
5,199
master
584
module Minitest::Assertions def assert_event_allowed(object, event, options = {}) state_machine_name = options.fetch(:on, :default) assert object.aasm(state_machine_name).may_fire_event?(event), "Expected that the event :#{event} would be allowed (on :#{state_machine_name})" end def refute_even...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/minitest/allow_transition_to.rb
Ruby
mit
5,199
master
655
module Minitest::Assertions def assert_transition_to_allowed(object, to_state, options = {}) state_machine_name = options.fetch(:on, :default) assert object.aasm(state_machine_name).states(permitted: true).include?(to_state), "Expected that the state :#{to_state} would be reachable (on :#{state_mac...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/core/event.rb
Ruby
mit
5,199
master
5,876
# frozen_string_literal: true module AASM::Core class Event include AASM::DslHelper attr_reader :name, :state_machine, :options, :default_display_name def initialize(name, state_machine, options = {}, &block) @name = name @state_machine = state_machine @transitions = [] @valid_t...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/core/transition.rb
Ruby
mit
5,199
master
2,546
# frozen_string_literal: true module AASM::Core class Transition include AASM::DslHelper attr_reader :from, :to, :event, :opts, :failures alias_method :options, :opts def initialize(event, opts, &block) add_options_from_dsl(opts, [:on_transition, :guard, :after, :success], &block) if block ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/core/invoker.rb
Ruby
mit
5,199
master
3,593
# frozen_string_literal: true module AASM module Core ## # main invoker class which encapsulates the logic # for invoking literal-based, proc-based, class-based # and array-based callbacks for different entities. class Invoker DEFAULT_RETURN_VALUE = true ## # Initialize a new i...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/core/state.rb
Ruby
mit
5,199
master
2,003
# frozen_string_literal: true module AASM::Core class State attr_reader :name, :state_machine, :options, :default_display_name def initialize(name, klass, state_machine, options={}) @name = name @klass = klass @state_machine = state_machine @default_display_name = name.to_s.gsub(/_/,...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/core/invokers/base_invoker.rb
Ruby
mit
5,199
master
2,121
# frozen_string_literal: true module AASM module Core module Invokers ## # Base concrete invoker class which contain basic # invoking and logging definitions class BaseInvoker attr_reader :failures, :subject, :record, :args, :result ## # Initialize a new concrete ...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/core/invokers/class_invoker.rb
Ruby
mit
5,199
master
1,962
# frozen_string_literal: true module AASM module Core module Invokers ## # Class invoker which allows to use classes which respond to #call # to be used as state/event/transition callbacks. class ClassInvoker < BaseInvoker def may_invoke? subject.is_a?(Class) && subject....
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/core/invokers/proc_invoker.rb
Ruby
mit
5,199
master
2,706
# frozen_string_literal: true module AASM module Core module Invokers ## # Proc invoker which allows to use Procs as # state/event/transition callbacks. class ProcInvoker < BaseInvoker def may_invoke? subject.is_a?(Proc) end def log_failure ret...
github
aasm/aasm
https://github.com/aasm/aasm
lib/aasm/core/invokers/literal_invoker.rb
Ruby
mit
5,199
master
2,261
# frozen_string_literal: true module AASM module Core module Invokers ## # Literal invoker which allows to use strings or symbols to call # record methods as state/event/transition callbacks. class LiteralInvoker < BaseInvoker def may_invoke? subject.is_a?(String) || sub...
github
aasm/aasm
https://github.com/aasm/aasm
test/minitest_helper.rb
Ruby
mit
5,199
master
1,929
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec', 'models'))) $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))) require 'aasm' require 'minitest/autorun' require 'aasm/minitest_spec' require...
github
aasm/aasm
https://github.com/aasm/aasm
test/unit/minitest_matcher_test.rb
Ruby
mit
5,199
master
2,594
require 'minitest_helper' class StateMachineTest < Minitest::Spec let(:simple) { SimpleExample.new } let(:multiple) { SimpleMultipleExample.new } describe 'transition_from' do it "works for simple state machines" do simple.must_transition_from :initialised, to: :filled_out, on_event: :fill_out ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/spec_helper.rb
Ruby
mit
5,199
master
1,284
require 'simplecov' SimpleCov.start do add_filter '/spec/' end if ENV['CI'] == 'true' require 'simplecov-cobertura' SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter end $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) $LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__)...
github
aasm/aasm
https://github.com/aasm/aasm
spec/database.rb
Ruby
mit
5,199
master
2,338
ActiveRecord::Migration.suppress_messages do %w{gates multiple_gates readers writers transients simples no_scopes multiple_no_scopes no_direct_assignments multiple_no_direct_assignments thieves multiple_thieves localizer_test_models persisted_states provided_and_persisted_states with_enums with_enum_without_columns m...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/state_machine_with_failed_event.rb
Ruby
mit
5,199
master
344
class StateMachineWithFailedEvent include AASM aasm do state :init, :initial => true state :failed state :sent event :failed do transitions :from => :init, :to => :failed end event :send, :before => :callback do transitions :from => :init, :to => :sent end end def call...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/guardian_multiple.rb
Ruby
mit
5,199
master
1,679
class GuardianMultiple include AASM aasm(:left) do state :alpha, :initial => true state :beta event :use_one_guard_that_succeeds do transitions :from => :alpha, :to => :beta, :guard => :succeed end event :use_one_guard_that_fails do transitions :from => :alpha, :to => :beta, :guard...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/super_class.rb
Ruby
mit
5,199
master
607
class SuperClass include AASM aasm do state :read state :ended event :foo do transitions :to => :ended, :from => [:read] end end def update_state if may_foo? foo! end end end class SuperClassMultiple include AASM aasm(:left) do state :read state :ended ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/silencer.rb
Ruby
mit
5,199
master
555
class Silencer include AASM # yes, this line is here on purpose # by this, we test if overriding configuration options works if # the state machine is "re-opened" aasm :whiny_transitions => true aasm :whiny_transitions => false do state :silent, :initial => true state :crying state :smiling ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/sub_class.rb
Ruby
mit
5,199
master
1,243
require_relative 'super_class' class SubClass < SuperClass # Add an after callback that is not defined in the parent aasm.state_machine.events[:foo].options[:after] = [:after_foo_event] # Add global callback that is not defined in the parent aasm.state_machine.global_callbacks[:after_all_transitions] = :after...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/simple_multiple_example.rb
Ruby
mit
5,199
master
961
class SimpleMultipleExample include AASM aasm(:move) do state :standing, :initial => true state :walking state :running event :walk do transitions :from => :standing, :to => :walking end event :run do transitions :from => [:standing, :walking], :to => :running end event ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/simple_custom_example.rb
Ruby
mit
5,199
master
1,271
class CustomAASMBase < AASM::Base # A custom transition that we want available across many AASM models. def count_transitions! klass.class_eval do aasm :with_klass => CustomAASMBase do after_all_transitions :increment_transition_count end end end # A custom annotation that we want a...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/simple_example_with_guard_args.rb
Ruby
mit
5,199
master
364
class SimpleExampleWithGuardArgs include AASM aasm do state :initialised, :initial => true state :filled_out_with_args event :fill_out_with_args do transitions :guard => [:arg_is_valid?], :from => :initialised, :to => :filled_out_with_args end end def ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/process_with_new_dsl.rb
Ruby
mit
5,199
master
519
class ProcessWithNewDsl include AASM def self.state(*args) raise "wrong state method" end attr_accessor :flagged aasm do state :sleeping, :initial => true state :running, :after_enter => :flag state :suspended event :start do transitions :from => :sleeping, :to => :running en...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/basic_two_state_machines_example.rb
Ruby
mit
5,199
master
505
class BasicTwoStateMachinesExample include AASM aasm :search do state :initialised, :initial => true state :queried state :requested event :query do transitions :from => [:initialised, :requested], :to => :queried end event :request do transitions :from => :queried, :to => :req...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/valid_state_name.rb
Ruby
mit
5,199
master
400
class ValidStateName include AASM aasm do state :invalid, :initial => true state :valid event :valid do transitions :to => :valid, :from => [:invalid] end end end class ValidStateNameMultiple include AASM aasm(:left) do state :invalid, :initial => true state :valid event :...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/parametrised_event_multiple.rb
Ruby
mit
5,199
master
725
class ParametrisedEventMultiple include AASM aasm(:left) do state :sleeping, :initial => true state :showering state :working state :dating state :prettying_up event :wakeup do transitions :from => :sleeping, :to => [:showering, :working] end event :dress do transitions...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/default_state.rb
Ruby
mit
5,199
master
286
class DefaultState attr_accessor :transient_store, :persisted_store include AASM aasm do state :alpha, :initial => true, display: 'ALPHA' state :beta state :gamma event :release do transitions :from => [:alpha, :beta, :gamma], :to => :beta end end end
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/guard_with_params_multiple.rb
Ruby
mit
5,199
master
352
class GuardWithParamsMultiple include AASM aasm(:left) do state :new, :reviewed, :finalized event :mark_as_reviewed do transitions :from => :new, :to => :reviewed, :guards => [:user_is_manager?] end end def user_is_manager?(user) ok = false if user.has_role? :manager ok = true ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/double_definer.rb
Ruby
mit
5,199
master
415
class DoubleDefiner include AASM aasm do state :started state :finished event :finish do transitions :from => :started, :to => :finished end # simulating a reload state :finished, :before_enter => :do_enter event :finish do transitions :from => :started, :to => :finished, ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/sub_class_with_more_states.rb
Ruby
mit
5,199
master
284
require_relative 'super_class' class SubClassWithMoreStates < SuperClass include AASM aasm do state :foo end end class SubClassWithMoreStatesMultiple < SuperClassMultiple include AASM aasm(:left) do state :foo end aasm(:right) do state :archived end end
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/complex_example.rb
Ruby
mit
5,199
master
5,480
class ComplexExample include AASM attr_accessor :activation_code, :activated_at, :deleted_at aasm do state :passive state :pending, :initial => true, :before_enter => :make_activation_code state :active, :before_enter => :do_activate state :suspended state :deleted, :before_enter => :do_del...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/guardian.rb
Ruby
mit
5,199
master
2,012
class Guardian include AASM def inner_guard(options={}) end aasm do state :alpha, :initial => true state :beta event :use_one_guard_that_succeeds do transitions :from => :alpha, :to => :beta, :guard => :succeed end event :use_one_guard_that_fails do transitions :from => :alpha...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/provided_state.rb
Ruby
mit
5,199
master
497
class ProvidedState attr_accessor :transient_store, :persisted_store include AASM aasm do state :alpha, :initial => true state :beta state :gamma event :release do transitions :from => [:alpha, :beta, :gamma], :to => :beta end end def aasm_read_state(*args) :beta end def aa...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/event_with_keyword_arguments.rb
Ruby
mit
5,199
master
439
class EventWithKeywordArguments include AASM aasm do state :open, :initial => true, :column => :status state :closed event :close do before :_before_close transitions from: :open, to: :closed end event :another_close do before :_before_another_close transitions from: :...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/conversation.rb
Ruby
mit
5,199
master
1,490
class Conversation include AASM aasm do state :needs_attention, :initial => true state :read state :closed state :awaiting_response state :junk event :new_message do end event :view do transitions :to => :read, :from => [:needs_attention] end event :reply do end...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/guardian_without_from_specified.rb
Ruby
mit
5,199
master
346
class GuardianWithoutFromSpecified include AASM aasm do state :alpha, :initial => true state :beta state :gamma event :use_guards_where_the_first_fails do transitions :to => :beta, :guard => :fail transitions :to => :gamma, :guard => :succeed end end def fail; false; end d...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/namespaced_multiple_example.rb
Ruby
mit
5,199
master
942
class NamespacedMultipleExample include AASM aasm(:status) do state :unapproved, :initial => true state :approved event :approve do transitions :from => :unapproved, :to => :approved end event :unapprove do transitions :from => :approved, :to => :unapproved end end aasm(:r...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/initial_state_proc.rb
Ruby
mit
5,199
master
704
class InitialStateProc RICH = 1_000_000 attr_accessor :balance include AASM aasm do state :retired state :selling_bad_mortgages initial_state Proc.new { |banker| banker.rich? ? :retired : :selling_bad_mortgages } end def initialize(balance = 0); self.balance = balance; end def rich?; self.b...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/no_initial_state.rb
Ruby
mit
5,199
master
350
class NoInitialState include AASM aasm do state :read state :ended event :foo do transitions :to => :ended, :from => [:read] end end end class NoInitialStateMultiple include AASM aasm(:left) do state :read state :ended event :foo do transitions :to => :ended, :from...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/simple_example.rb
Ruby
mit
5,199
master
422
class SimpleExample include AASM aasm do state :initialised, :initial => true state :filled_out state :denied state :authorised event :fill_out do transitions :from => :initialised, :to => :filled_out end event :deny do transitions from: :initialised, to: :denied end ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/multi_transitioner.rb
Ruby
mit
5,199
master
574
class MultiTransitioner include AASM attr_accessor :can_run def initialize @can_run = false end aasm do state :sleeping, :initial => true state :running state :dancing state :dead event :start do transitions :from => :sleeping, :to => :running, guard: :runnable? transit...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/guard_arguments_check.rb
Ruby
mit
5,199
master
333
class GuardArgumentsCheck include AASM aasm do state :new, :reviewed, :finalized event :mark_as_reviewed, :guard => proc { |*args| arguments_list(*args) } do transitions :from => :new, :to => :reviewed end end def arguments_list(arg1, arg2) return false unless arg1.nil? tr...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/foo_callback_multiple.rb
Ruby
mit
5,199
master
899
class FooCallbackMultiple include AASM aasm(:left) do state :open, :initial => true, :before_exit => :before_exit state :closed, :before_enter => :before_enter state :final event :close, :success => :success_callback do transitions :from => [:open], :to => [:closed] end event :null ...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/parametrised_event.rb
Ruby
mit
5,199
master
1,051
class ParametrisedEvent include AASM aasm do state :sleeping, :initial => true state :showering state :working state :dating state :prettying_up event :wakeup do transitions :from => :sleeping, :to => [:showering, :working] end event :shower do transitions :from => :sle...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/class_with_keyword_arguments.rb
Ruby
mit
5,199
master
1,359
# frozen_string_literal: true class CallbackWithOptionalKeywordArguments def initialize(state_machine, my_optional_arg: nil, **_args) @state_machine = state_machine @my_optional_arg = my_optional_arg end def call @state_machine.my_attribute = @my_optional_arg if @my_optional_arg end end class Cal...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/timestamps_example.rb
Ruby
mit
5,199
master
283
class TimestampsExample include AASM attr_accessor :opened_at attr_reader :closed_at aasm timestamps: true do state :opened state :closed event :open do transitions to: :opened end event :close do transitions to: :closed end end end
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/timestamps_with_named_machine_example.rb
Ruby
mit
5,199
master
208
class TimestampsWithNamedMachineExample include AASM attr_accessor :opened_at aasm :my_state, timestamps: true do state :opened event :open do transitions to: :opened end end end
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/guard_with_params.rb
Ruby
mit
5,199
master
411
class GuardWithParams include AASM aasm do state :new, :reviewed, :finalized event :mark_as_reviewed do transitions :from => :new, :to => :reviewed, :guards => [:user_is_manager?] end end def user_is_manager?(user) ok = false if user && user.has_role?(:manager) ok = true en...
github
aasm/aasm
https://github.com/aasm/aasm
spec/models/foo.rb
Ruby
mit
5,199
master
1,814
module Fooable def self.included(base) base.class_eval do aasm do state :open, :initial => true, :before_exit => :before_exit state :closed, :before_enter => :before_enter state :final event :close, :success => :success_callback do transitions :from => [:open], :to...