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, 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
52
53
54
|
# File 'lib/disposable/twin.rb', line 52
def collection(name, options={}, &block)
property(name, options.merge(collection: true), &block)
end
|
.default_nested_class ⇒ Object
33
34
35
|
# File 'lib/disposable/twin.rb', line 33
def default_nested_class
Twin
end
|
.definition_class ⇒ Object
24
25
26
|
# File 'lib/disposable/twin.rb', line 24
def self.definition_class
Definition
end
|
.from_collection(collection) ⇒ Object
56
57
58
|
# File 'lib/disposable/twin.rb', line 56
def from_collection(collection)
collection.collect { |model| new(model) }
end
|
.property(name, options = {}, &block) ⇒ Object
TODO: move to Declarative, as in Representable and Reform.
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/disposable/twin.rb', line 38
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
28
29
30
|
# File 'lib/disposable/twin.rb', line 28
def schema
self.class.definitions.extend(DefinitionsEach)
end
|