Class: FormCore::VirtualModel
- Inherits:
-
ActiveEntity::Base
- Object
- ActiveEntity::Base
- FormCore::VirtualModel
- Defined in:
- lib/form_core/virtual_model.rb
Constant Summary collapse
- ARRAY_WITHOUT_BLANK_PATTERN =
Hack
"!ruby/array:ArrayWithoutBlank"
Class Method Summary collapse
- ._embeds_reflections ⇒ Object
- .build(name = nil) ⇒ Object
- .coder ⇒ Object
- .coder=(klass) ⇒ Object
-
.inspect ⇒ Object
Returns a string like “Post(id:integer, title:string, body:text)”.
- .name ⇒ Object
- .name=(value) ⇒ Object
Instance Method Summary collapse
- #dump ⇒ Object
-
#inspect ⇒ Object
Returns the contents of the record as a nicely formatted string.
- #serializable_hash(options = {}) ⇒ Object
Class Method Details
._embeds_reflections ⇒ Object
71 72 73 |
# File 'lib/form_core/virtual_model.rb', line 71 def _reflections.select { |_, v| v.is_a? ::ActiveEntity::Reflection::EmbeddedAssociationReflection } end |
.build(name = nil) ⇒ Object
59 60 61 62 63 |
# File 'lib/form_core/virtual_model.rb', line 59 def build(name = nil) klass = Class.new(self) klass.name = name klass end |
.coder ⇒ Object
47 48 49 |
# File 'lib/form_core/virtual_model.rb', line 47 def coder @_coder ||= FormCore.virtual_model_coder_class.new(self) end |
.coder=(klass) ⇒ Object
51 52 53 54 55 |
# File 'lib/form_core/virtual_model.rb', line 51 def coder=(klass) raise ArgumentError, "#{klass} should be sub-class of #{Coder}." unless klass && klass < Coder @_coder = klass.new(self) end |
.inspect ⇒ Object
Returns a string like “Post(id:integer, title:string, body:text)”
66 67 68 69 |
# File 'lib/form_core/virtual_model.rb', line 66 def inspect attr_list = attribute_types.map { |name, type| "#{name}: #{type.type}" } * ", " "#<VirtualModel:#{name}:#{object_id} #{attr_list}>" end |
.name ⇒ Object
36 37 38 |
# File 'lib/form_core/virtual_model.rb', line 36 def name @_name ||= "Form" end |
.name=(value) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/form_core/virtual_model.rb', line 40 def name=(value) value = value.classify raise ArgumentError, "`value` isn't a valid class name" if value.blank? @_name = value end |
Instance Method Details
#dump ⇒ Object
31 32 33 |
# File 'lib/form_core/virtual_model.rb', line 31 def dump self.class.dump(self).gsub(ARRAY_WITHOUT_BLANK_PATTERN, "") end |
#inspect ⇒ Object
Returns the contents of the record as a nicely formatted string.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/form_core/virtual_model.rb', line 8 def inspect # We check defined?(@attributes) not to issue warnings if the object is # allocated but not initialized. inspection = if defined?(@attributes) && @attributes self.class.attribute_names.collect do |name| "#{name}: #{attribute_for_inspect(name)}" if has_attribute?(name) end.compact.join(", ") else "not initialized" end "#<VirtualModel:#{self.class.name}:#{object_id} #{inspection}>" end |
#serializable_hash(options = {}) ⇒ Object
23 24 25 26 |
# File 'lib/form_core/virtual_model.rb', line 23 def serializable_hash( = {}) = ( || {}).reverse_merge include: self.class..keys super(**) end |