Class: Morpheus::Base
- Inherits:
-
Object
- Object
- Morpheus::Base
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Dirty, ActiveModel::Serializers::JSON, ActiveModel::Serializers::Xml, ActiveModel::Validations, Mixins::Associations, Mixins::Attributes, Mixins::Conversion, Mixins::Filtering, Mixins::Finders, Mixins::Introspection, Mixins::Persistence, Mixins::Reflections, Mixins::RequestHandling, Mixins::ResponseParsing, Mixins::UrlSupport
- Defined in:
- lib/morpheus/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(comparison_object) ⇒ Object
-
#initialize(new_attributes = {}) ⇒ Base
constructor
A new instance of Base.
Methods included from Mixins::UrlSupport
Methods included from Mixins::ResponseParsing
Methods included from Mixins::RequestHandling
Methods included from Mixins::Reflections
Methods included from Mixins::Persistence
#destroy, included, #save, #update_attributes
Methods included from Mixins::Introspection
#destroyed?, #new_record?, #persisted?, #respond_to?
Methods included from Mixins::Finders
Methods included from Mixins::Filtering
Methods included from Mixins::Conversion
#to_key, #to_model, #to_param, #to_partial_path
Methods included from Mixins::Attributes
#attributes, #attributes_without_basic_attributes, included, #read_attribute_for_validation, #typecast, #update_attribute, #update_reflection
Methods included from Mixins::Associations
Constructor Details
#initialize(new_attributes = {}) ⇒ Base
Returns a new instance of Base.
35 36 37 38 39 40 41 42 |
# File 'lib/morpheus/base.rb', line 35 def initialize(new_attributes = {}) new_attributes = HashWithIndifferentAccess.new(new_attributes) @errors = ActiveModel::Errors.new(self) new_attributes.each do |attribute, value| self.class.default_attributes.store(attribute.to_sym, nil) unless self.class.attribute_defined?(attribute) update_attribute(attribute, value) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object (private)
55 56 57 58 59 60 61 62 63 |
# File 'lib/morpheus/base.rb', line 55 def method_missing(m, *args, &block) if attributes.keys.include?(m.to_s.delete('=')) # Defines attribute accessors when the missing method can be found in the attributes hash self.class.send(:define_attribute_accessor, m) send(m, *args, &block) else super end end |
Class Method Details
.base_class ⇒ Object
49 50 51 |
# File 'lib/morpheus/base.rb', line 49 def self.base_class self end |
Instance Method Details
#==(comparison_object) ⇒ Object
44 45 46 47 |
# File 'lib/morpheus/base.rb', line 44 def ==(comparison_object) comparison_object.equal?(self) || (comparison_object.instance_of?(self.class) && comparison_object.id == id && !comparison_object.new_record?) end |