Module: Redis::Actions::Creating

Defined in:
lib/redis/actions/creating.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



2
3
4
5
6
# File 'lib/redis/actions/creating.rb', line 2

def self.included(base)
  base.send :extend, Redis::Actions::Creating::ClassMethods
  base.define_model_callbacks :create
  base.around_save :create_if_new
end

Instance Method Details

#create_if_newObject



8
9
10
11
12
13
14
15
16
# File 'lib/redis/actions/creating.rb', line 8

def create_if_new
  if new_record?
    run_callbacks(:create) do
      yield
    end
  else
    yield
  end
end