Class: Disposable::Twin
- Inherits:
-
Object
- Object
- Disposable::Twin
- Extended by:
- Representable::Feature, Uber::InheritableAttr
- Includes:
- Accessors, ModelReaders, Option, Setup, ToS
- Defined in:
- lib/disposable/twin/sync.rb,
lib/disposable.rb,
lib/disposable/twin.rb,
lib/disposable/twin/save.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/representer.rb
Overview
#sync!
1. assign scalars to model (respecting virtual, excluded attributes)
2. call sync! on nested
Note: #sync currently implicitly saves AR objects with collections
Defined Under Namespace
Modules: Accessors, Builder, Changed, Coercion, Composition, Default, Expose, ModelReaders, Option, Persisted, Save, Setup, Struct, Sync, ToS Classes: Collection, Decorator, PropertyProcessor, Schema, Twinner
Instance Attribute Summary
Attributes included from ModelReaders
Class Method Summary collapse
- .collection(name, options = {}, &block) ⇒ Object
- .from_collection(collection) ⇒ Object
-
.property(name, options = {}, &block) ⇒ Object
TODO: move to Declarative, as in Representable and Reform.
- .register_feature(mod) ⇒ Object
Instance Method Summary collapse
-
#schema ⇒ Object
Returns an each’able array of all properties defined in this twin.
Methods included from Option
Methods included from ToS
Methods included from Setup
Class Method Details
.collection(name, options = {}, &block) ⇒ Object
70 71 72 |
# File 'lib/disposable/twin.rb', line 70 def collection(name, ={}, &block) property(name, .merge(collection: true), &block) end |
.from_collection(collection) ⇒ Object
74 75 76 |
# File 'lib/disposable/twin.rb', line 74 def from_collection(collection) collection.collect { |model| new(model) } end |
.property(name, options = {}, &block) ⇒ Object
TODO: move to Declarative, as in Representable and Reform.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/disposable/twin.rb', line 48 def property(name, ={}, &block) [:private_name] = .delete(:from) || name if .delete(:virtual) [:writeable] = [:readable] = false end [:extend] = [:twin] # e.g. property :album, twin: Album. representer_class.property(name, , &block).tap do |definition| create_accessors(name, definition) if definition[:extend] and ![:twin] # This will soon be replaced with Declarative's API. # DISCUSS: could we use build_inline's api here to inject the name feature? nested_twin = definition[:extend].evaluate(nil) process_inline!(nested_twin, definition) definition.merge!(twin: nested_twin) # DISCUSS: where do we need this? end end end |
.register_feature(mod) ⇒ Object
41 42 43 |
# File 'lib/disposable/twin.rb', line 41 def self.register_feature(mod) representer_class.representable_attrs[:features][mod] = true end |
Instance Method Details
#schema ⇒ Object
Returns an each’able array of all properties defined in this twin. Allows to filter using
* collection: true
* twin: true
* scalar: true
* exclude: ["title", "email"]
35 36 37 |
# File 'lib/disposable/twin.rb', line 35 def schema self.class.representer_class end |