Module: Trax::Model

Extended by:
ActiveSupport::Autoload, ActiveSupport::Concern
Includes:
ActiveModel::Dirty, Core::InheritanceHooks, Matchable
Defined in:
lib/trax/model.rb,
lib/trax/model/uuid.rb,
lib/trax/model/mixin.rb,
lib/trax/model/errors.rb,
lib/trax/model/mixins.rb,
lib/trax/model/railtie.rb,
lib/trax/model/registry.rb,
lib/trax/model/cache_key.rb,
lib/trax/model/matchable.rb,
lib/trax/model/attributes.rb,
lib/trax/model/uuid_array.rb,
lib/trax/model/uuid_prefix.rb,
lib/trax/model/attributes/dsl.rb,
lib/trax/model/extensions_for.rb,
lib/trax/model/attributes/type.rb,
lib/trax/model/core_extensions.rb,
lib/trax/model/mixins/sti_enum.rb,
lib/trax/model/attributes/types.rb,
lib/trax/model/attributes/value.rb,
lib/trax/model/mixins/freezable.rb,
lib/trax/model/mixins/id_scopes.rb,
lib/trax/model/mixins/unique_id.rb,
lib/trax/model/attributes/errors.rb,
lib/trax/model/attributes/fields.rb,
lib/trax/model/mixins/restorable.rb,
lib/trax/model/extensions_for/set.rb,
lib/trax/model/extensions_for/base.rb,
lib/trax/model/mixins/field_scopes.rb,
lib/trax/model/attributes/attribute.rb,
lib/trax/model/attributes/types/set.rb,
lib/trax/model/attributes/types/enum.rb,
lib/trax/model/extensions_for/string.rb,
lib/trax/model/extensions_for/struct.rb,
lib/trax/model/mixins/cached_find_by.rb,
lib/trax/model/mixins/sort_by_scopes.rb,
lib/trax/model/attributes/definitions.rb,
lib/trax/model/attributes/types/array.rb,
lib/trax/model/core_extensions/string.rb,
lib/trax/model/extensions_for/boolean.rb,
lib/trax/model/extensions_for/integer.rb,
lib/trax/model/extensions_for/numeric.rb,
lib/trax/model/attributes/types/string.rb,
lib/trax/model/attributes/types/struct.rb,
lib/trax/model/mixins/cached_relations.rb,
lib/trax/model/attributes/types/boolean.rb,
lib/trax/model/attributes/types/integer.rb,
lib/trax/model/extensions_for/enumerable.rb,
lib/trax/model/attributes/types/uuid_array.rb,
lib/trax/model/extensions_for/struct_fields.rb,
lib/trax/model/extensions_for/struct_fields/enum.rb,
lib/trax/model/extensions_for/struct_fields/time.rb,
lib/trax/model/extensions_for/struct_fields/float.rb,
lib/trax/model/extensions_for/struct_fields/string.rb,
lib/trax/model/extensions_for/struct_fields/boolean.rb,
lib/trax/model/extensions_for/struct_fields/integer.rb,
lib/trax/model/extensions_for/struct_fields/numeric.rb

Defined Under Namespace

Modules: Attributes, ClassMethods, CoreExtensions, Errors, ExtensionsFor, Matchable, Mixin, Mixins Classes: CacheKey, Railtie, Registry, UUID, UUIDArray, UUIDPrefix

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.mixin_registryObject

Returns the value of attribute mixin_registry.



58
59
60
# File 'lib/trax/model.rb', line 58

def mixin_registry
  @mixin_registry
end

Class Method Details

.cacheObject



70
71
72
# File 'lib/trax/model.rb', line 70

def self.cache
  ::Trax::Model.config.cache
end

.cache=(cache_store) ⇒ Object



74
75
76
77
78
# File 'lib/trax/model.rb', line 74

def self.cache=(cache_store)
  ::Trax::Model.configure do |config|
    config.cache = cache_store
  end
end

.eager_autoload_mixins!Object



84
85
86
87
88
89
90
91
92
93
94
# File 'lib/trax/model.rb', line 84

def self.eager_autoload_mixins!
  ::Trax::Model::Mixins::CachedFindBy
  ::Trax::Model::Mixins::CachedRelations
  ::Trax::Model::Mixins::FieldScopes
  ::Trax::Model::Mixins::Freezable
  ::Trax::Model::Mixins::IdScopes
  ::Trax::Model::Mixins::Restorable
  ::Trax::Model::Mixins::SortByScopes
  ::Trax::Model::Mixins::StiEnum
  ::Trax::Model::Mixins::UniqueId
end

.find_by_uuid(uuid) ⇒ Object



98
99
100
# File 'lib/trax/model.rb', line 98

def self.find_by_uuid(uuid)
  ::Trax::Model::UUID.new(uuid).record
end

.register_mixin(mixin_klass, key = nil) ⇒ Object



63
64
65
66
67
68
# File 'lib/trax/model.rb', line 63

def self.register_mixin(mixin_klass, key = nil)
  mixin_key = mixin_klass.respond_to?(:mixin_registry_key) ? mixin_klass.mixin_registry_key : (key || mixin_klass.name.demodulize.underscore.to_sym)

  return if mixin_registry.key?(mixin_key)
  mixin_registry[mixin_key] = mixin_klass
end

.rootObject



80
81
82
# File 'lib/trax/model.rb', line 80

def self.root
  ::Pathname.new(::File.path(__FILE__))
end

Instance Method Details

#reverse_assign_attributes(attributes_hash) ⇒ Object

like reverse merge, only assigns attributes which have not yet been assigned



51
52
53
54
55
# File 'lib/trax/model.rb', line 51

def reverse_assign_attributes(attributes_hash)
  attributes_to_assign = attributes_hash.keys.reject{|_attribute_name| attribute_present?(_attribute_name) }

  assign_attributes(attributes_hash.slice(attributes_to_assign))
end