Class: FormCore::VirtualModel
- Inherits:
-
DuckRecord::Base
- Object
- DuckRecord::Base
- FormCore::VirtualModel
- Defined in:
- lib/form_core/virtual_model.rb
Class Method Summary collapse
- .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.
Class Method Details
.build(name = nil) ⇒ Object
56 57 58 59 60 |
# File 'lib/form_core/virtual_model.rb', line 56 def build(name = nil) klass = Class.new(self) klass.name = name klass end |
.coder ⇒ Object
42 43 44 |
# File 'lib/form_core/virtual_model.rb', line 42 def coder @_coder ||= FormCore.virtual_model_coder_class.new(self) end |
.coder=(klass) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/form_core/virtual_model.rb', line 46 def coder=(klass) unless klass && klass < Coder raise ArgumentError, "#{klass} should be sub-class of #{Coder}." end @_coder = klass.new(self) end |
.inspect ⇒ Object
Returns a string like “Post(id:integer, title:string, body:text)”
63 64 65 66 |
# File 'lib/form_core/virtual_model.rb', line 63 def inspect attr_list = attribute_types.map { |name, type| "#{name}: #{type.type}" } * ", " "#<VirtualModel:#{name}:#{object_id} #{attr_list}>" end |
.name ⇒ Object
31 32 33 |
# File 'lib/form_core/virtual_model.rb', line 31 def name @_name ||= "Form" end |
.name=(value) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/form_core/virtual_model.rb', line 35 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
25 26 27 |
# File 'lib/form_core/virtual_model.rb', line 25 def dump self.class.dump(self) 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 22 23 |
# 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| if has_attribute?(name) "#{name}: #{attribute_for_inspect(name)}" end end.compact.join(", ") else "not initialized" end "#<VirtualModel:#{self.class.name}:#{object_id} #{inspection}>" end |