Sha256: 809191f85dcf0101d6e8581ef83eb1fdfbc2f437ee082047fd6f369a2020e000
Contents?: true
Size: 1.01 KB
Versions: 1
Compression:
Stored size: 1.01 KB
Contents
require 'active_support/concern' require 'active_support/core_ext/module/aliasing' module StatelyScopes extend ActiveSupport::Concern included do class_eval do class << self alias_method_chain :scope, :state if StatelyScopes.configuration.alias_scope_method end end end def has_scoped_state?(name) self.class.send(name.to_sym).exists?(self.id) end module ClassMethods def scope_with_state(name, body, &block) if StatelyScopes.configuration.alias_scope_method scope_without_state name, body, &block else scope name, body, &block end class_eval "def #{name}?() self.has_scoped_state?(#{name}) end" end end class << self def configure(&block) yield(StatelyScopes::Configuration.configuration) end def configuration StatelyScopes::Configuration.configuration end end class Configuration def self.configuration @@configuration ||= OpenStruct.new(:alias_scope_method => true) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stately_scopes-0.0.1 | lib/stately_scopes.rb |