Module: ActiveType::Util

Extended by:
Util
Included in:
ActiveType, Util
Defined in:
lib/active_type/util.rb,
lib/active_type/util/unmutable_attributes.rb

Defined Under Namespace

Classes: UnmutableAttributes

Instance Method Summary collapse

Instance Method Details

#cast(object, klass, force: false) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/active_type/util.rb', line 7

def cast(object, klass, force: false)
  if object.is_a?(ActiveRecord::Relation)
    cast_relation(object, klass)
  elsif object.is_a?(ActiveRecord::Base)
    cast_record(object, klass, force: force)
  else
    raise ArgumentError, "Don't know how to cast #{object.inspect}"
  end
end

#scoped(klass_or_relation) ⇒ Object



17
18
19
# File 'lib/active_type/util.rb', line 17

def scoped(klass_or_relation)
  klass_or_relation.where(nil)
end