Class: Disposable::Twin
- Inherits:
-
Object
show all
- Extended by:
- Declarative::Schema
- 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
Defined Under Namespace
Modules: Accessors, Builder, Changed, Coercion, Composition, Default, DefinitionsEach, Expose, ModelReaders, Parent, Persisted, 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 Setup
#initialize
Class Method Details
.collection(name, options = {}, &block) ⇒ Object
41
42
43
|
# File 'lib/disposable/twin.rb', line 41
def collection(name, options={}, &block)
property(name, options.merge(collection: true), &block)
end
|
.default_nested_class ⇒ Object
22
23
24
|
# File 'lib/disposable/twin.rb', line 22
def default_nested_class
Twin
end
|
.definition_class ⇒ Object
13
14
15
|
# File 'lib/disposable/twin.rb', line 13
def self.definition_class
Definition
end
|
.from_collection(collection) ⇒ Object
46
47
48
|
# File 'lib/disposable/twin.rb', line 46
def from_collection(collection)
collection.collect { |model| new(model) }
end
|
.property(name, options = {}, &block) ⇒ Object
TODO: move to Declarative, as in Representable and Reform.
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/disposable/twin.rb', line 27
def property(name, options={}, &block)
options[:private_name] = options.delete(:from) || name
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|
create_accessors(name, definition)
end
end
|
Instance Method Details
#schema ⇒ Object
17
18
19
|
# File 'lib/disposable/twin.rb', line 17
def schema
self.class.definitions.extend(DefinitionsEach)
end
|