Module: Lifestreamable::LifestreamableInstanceMethods

Defined in:
lib/lifestreamable/lifestreamable.rb

Instance Method Summary collapse

Instance Method Details

#get_action_instead_of(action) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/lifestreamable/lifestreamable.rb', line 228

def get_action_instead_of(action)
  case action
    when :create
      :create
    when :update
      if test_instead_option(lifestream_options[:create_instead_of_update])
        :create
      elsif test_instead_option(lifestream_options[:destroy_instead_of_update]) 
      :destroy 
      else
        :update
      end
    when :destroy
      if test_instead_option(lifestream_options[:create_instead_of_destroy])
        :create 
      elsif test_instead_option(lifestream_options[:destroy_instead_of_destroy])
        :update 
      else  
        :destroy
      end
    else
      raise LifestreamableException.new("The action #{action.to_s} is not a valid type of action")
  end
end

#get_payloadObject



220
221
222
223
224
225
226
# File 'lib/lifestreamable/lifestreamable.rb', line 220

def get_payload
  reference_type, reference_id = get_reference
  owner_type, owner_id = get_owner
  stream_type = get_stream_type
  data = get_lifestream_data.to_yaml
  Struct::LifestreamData.new reference_type, reference_id, owner_type, owner_id, stream_type, data   
end

#lifestream_optionsObject



203
204
205
# File 'lib/lifestreamable/lifestreamable.rb', line 203

def lifestream_options
  self.class.lifestream_options
end

#lifestreamable?(action) ⇒ Boolean

Returns:

  • (Boolean)


207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/lifestreamable/lifestreamable.rb', line 207

def lifestreamable?(action)
  case self.lifestream_options[:when]
    when NilClass, TrueClass, :true, TRUE_REGEX
      true
    when FalseClass, :false, FALSE_REGEX
      false
    when Proc
      self.lifestream_options[:when].call(self, action)
    when String, Symbol
      send(self.lifestream_options[:when].to_s, action)
  end 
end