Module: Encore::Entity

Extended by:
ActiveSupport::Concern
Defined in:
lib/encore/entity.rb,
lib/encore/entity/input.rb,
lib/encore/entity/output.rb,
lib/encore/entity/output/json.rb,
lib/encore/entity/input/errors.rb,
lib/encore/entity/input/associations.rb,
lib/encore/entity/input/exposed_attributes.rb

Defined Under Namespace

Modules: ClassMethods, Input, Output

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &blk) ⇒ Object

Delegate everything to the object



28
29
30
31
32
33
34
# File 'lib/encore/entity.rb', line 28

def method_missing(method, *args, &blk)
  if @object.respond_to?(method)
    @object.send(method, *args, &blk)
  else
    super
  end
end

Instance Method Details

#initialize(object = nil) ⇒ Object

Initialize a new entity, linked to an ActiveRecord object If no object is passed, let’s try to build a new one



18
19
20
# File 'lib/encore/entity.rb', line 18

def initialize(object = nil)
  @object = object || self.class.linked_class.new
end

#saveObject

Save the object



23
24
25
# File 'lib/encore/entity.rb', line 23

def save
  run_callbacks(:save) { @object.save }
end