Module: Inflorm
- Defined in:
- lib/inflorm.rb,
lib/inflorm/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/inflorm.rb', line 9 def self.included(base) base.class_eval do include Virtus.model include ActiveModel::Validations attribute :id, String # Need to override Virtus.model to_h, but self.included is run *after* our module # is included, so we can't define this method below with the others (unless we prepended) # Note we're unfortunately relying on rails monkey patching # active_support/core_ext/object/json # which will recursively call as_json on all nested objs. Apparently Virtus 2.0 will give us # these facilities without relying on it. def to_h as_json.deep_symbolize_keys end end end |
Instance Method Details
#marked_for_destruction? ⇒ Boolean
32 33 34 |
# File 'lib/inflorm.rb', line 32 def marked_for_destruction? respond_to?(marked_for_destruction_param) && send(marked_for_destruction_param).present? end |
#persisted? ⇒ Boolean
28 29 30 |
# File 'lib/inflorm.rb', line 28 def persisted? id.present? end |
#save ⇒ Object
36 37 38 |
# File 'lib/inflorm.rb', line 36 def save valid? && persist! end |