Module: Lore::Mockable
- Defined in:
- lib/lore/model/mockable.rb
Class Method Summary collapse
-
.extended(object) ⇒ Object
Alias module .self methods.
Instance Method Summary collapse
-
#create_shallow(attrib_values) ⇒ Object
Create a shallow instance, that is: A mock instance with no reference to DB model.
Class Method Details
.extended(object) ⇒ Object
Alias module .self methods
51 52 53 54 55 56 57 58 |
# File 'lib/lore/model/mockable.rb', line 51 def self.extended(object) class << object alias_method :create_mock, :create_shallow unless method_defined? :create_mock alias_method :create_shallow, :create_mock alias_method :mock, :create_shallow unless method_defined? :mock alias_method :create_shallow, :mock end end |
Instance Method Details
#create_shallow(attrib_values) ⇒ Object
Create a shallow instance, that is: A mock instance with no reference to DB model. Attribute values passed to Table_Accessor.create_shallow are not processed through hooks, filters, and validation. Values are, however, processed through output filters. Usage and result is the same as for Table_Accessor.create, but it only returns an accessor instance, without storing it in the database. To commit a shallow copy to database (and thus process given attribute values through stages mentioned before), call #commit.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/lore/model/mockable.rb', line 15 def create_shallow(attrib_values) before_create(attrib_values) input_filters = get_input_filters attrib_key = '' attrib_name = '' attrib_values.each_pair { |attrib_name, attrib_value| if attrib_name.instance_of? Symbol then attrib_key = attrib_name else attrib_key = attrib_name.split('.')[-1].intern end if (input_filters && input_filters[attrib_key]) then attrib_values[attrib_name] = input_filters[attrib_key].call(attrib_value) end } after_filters(attrib_values) values = distribute_attrib_values(attrib_values) before_validation(values) Lore::Validation::Parameter_Validator.invalid_params(self, values) before_insert(attrib_values) values = distribute_attrib_values(attrib_values) flat_attribs = [] get_all_table_names.each { |table| get_attributes[table].each { |attrib| flat_attribs << (values[table][attrib]) } } instance = self.new(flat_attribs) end |