Class: Disposable::Twin

Inherits:
Object
  • Object
show all
Extended by:
Declarative::Schema, Property::Unnest
Includes:
Accessors, ModelReaders, Setup
Defined in:
lib/disposable.rb,
lib/disposable/twin.rb,
lib/disposable/twin/save.rb,
lib/disposable/twin/sync.rb,
lib/disposable/twin/setup.rb,
lib/disposable/twin/struct.rb,
lib/disposable/twin/builder.rb,
lib/disposable/twin/collection.rb,
lib/disposable/twin/composition.rb,
lib/disposable/twin/definitions.rb,
lib/disposable/twin/property/hash.rb,
lib/disposable/twin/property/struct.rb

Defined Under Namespace

Modules: Accessors, Builder, Changed, Coercion, Composition, Default, Expose, ModelReaders, Parent, Persisted, Property, Save, Setup, Struct, Sync Classes: Collection, Definition, PropertyProcessor, Twinner

Instance Attribute Summary

Attributes included from ModelReaders

#mapper, #model

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Property::Unnest

included, unnest

Methods included from Setup

#initialize

Class Method Details

.collection(name, options = {}, &block) ⇒ Object



49
50
51
# File 'lib/disposable/twin.rb', line 49

def collection(name, options={}, &block)
  property(name, options.merge(collection: true), &block)
end

.default_nested_classObject



29
30
31
# File 'lib/disposable/twin.rb', line 29

def default_nested_class
  Twin
end

.definition_classObject



13
14
15
# File 'lib/disposable/twin.rb', line 13

def self.definition_class
  Definition
end

.from_collection(collection) ⇒ Object

TODO: remove.



57
58
59
# File 'lib/disposable/twin.rb', line 57

def from_collection(collection)
  collection.collect { |model| new(model) }
end

.inherited(subclass) ⇒ Object



17
18
19
20
21
22
# File 'lib/disposable/twin.rb', line 17

def self.inherited(subclass)
  # no super here!
  heritage.(subclass) do |cfg|
    cfg[:args].last.merge!(_inherited: true) if cfg[:method] == :property
  end
end

.property(name, options = {}, &block) ⇒ Object

TODO: move to Declarative, as in Representable and Reform.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/disposable/twin.rb', line 34

def property(name, options={}, &block)
  options[:private_name] ||= options.delete(:from) || name
  is_inherited = options.delete(:_inherited)

  if options.delete(:virtual)
    options[:writeable] = options[:readable] = false
  end

  options[:nested] = options.delete(:twin) if options[:twin]

  super(name, options, &block).tap do |definition| # super is Declarative::Schema::property.
    create_accessors(name, definition) unless is_inherited
  end
end

Instance Method Details

#schemaObject



24
25
26
# File 'lib/disposable/twin.rb', line 24

def schema
  Definition::Each.new(self.class.definitions) # TODO: change this interface.
end