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
-
.process_inline!(mod, definition) ⇒ Object
DISCUSS: this method might disappear or change pretty soon.
-
.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
74 75 76 |
# File 'lib/disposable/twin.rb', line 74 def self.collection(name, ={}, &block) property(name, .merge(collection: true), &block) end |
.process_inline!(mod, definition) ⇒ Object
DISCUSS: this method might disappear or change pretty soon.
112 113 |
# File 'lib/disposable/twin.rb', line 112 def self.process_inline!(mod, definition) end |
.property(name, options = {}, &block) ⇒ Object
TODO: move to Declarative, as in Representable and Reform.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/disposable/twin.rb', line 47 def self.property(name, ={}, &block) [:private_name] = .delete(:from) || name [:pass_options] = true if .delete(:virtual) [:writeable] = [:readable] = false end representer_class.property(name, , &block).tap do |definition| mod = Module.new do define_method(name) { @fields[name.to_s] } # define_method(name) { read_property(name) } define_method("#{name}=") { |value| write_property(name, value, definition) } # TODO: this is more like prototyping. end include mod # property -> build_inline(representable_attrs.features) if definition[:extend] nested_twin = definition[:extend].evaluate(nil) process_inline!(nested_twin, definition) # DISCUSS: could we use build_inline's api here to inject the name feature? definition.merge!(:twin => nested_twin) 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 |