Class: Realm::ROM::ReadOnlyRelationWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/realm/rom/read_only_relation_wrapper.rb

Constant Summary collapse

FORBIDDEN_METHODS =
(::ROM::SQL::Relation::Writing.instance_methods(false) + [:command]).freeze

Instance Method Summary collapse

Constructor Details

#initialize(relation) ⇒ ReadOnlyRelationWrapper

Returns a new instance of ReadOnlyRelationWrapper.



8
9
10
# File 'lib/realm/rom/read_only_relation_wrapper.rb', line 8

def initialize(relation)
  @relation = relation
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args) ⇒ Object

Raises:

  • (Persistence::RelationIsReadOnly)


12
13
14
15
16
# File 'lib/realm/rom/read_only_relation_wrapper.rb', line 12

def method_missing(symbol, *args)
  raise Persistence::RelationIsReadOnly, @relation if FORBIDDEN_METHODS.include?(symbol)

  @relation.send(symbol, *args)
end

Instance Method Details

#respond_to_missing?(symbol) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/realm/rom/read_only_relation_wrapper.rb', line 18

def respond_to_missing?(symbol)
  !FORBIDDEN_METHODS.include?(symbol) && @relation.respond_to?(symbol)
end