Class: Spider::Model::InlineModel
- Defined in:
- lib/spiderfw/model/inline_model.rb
Overview
BaseModel having its data defined in the class. The data must be an array of hashes, and will be handled by the Mappers::HashMapper.
Instance Attribute Summary
Attributes inherited from BaseModel
#_check_if_saved, #_modified_elements, #_no_identity_mapper, #_parent, #_parent_element, #_subclass_object, #loaded_elements, #model
Class Method Summary collapse
-
.data(val = nil) ⇒ Object
Sets/gets model data.
-
.data=(val) ⇒ Object
Sets model data.
- .get_storage(url = 'default') ⇒ Object
- .mapper ⇒ Object
- .translate=(val) ⇒ Object
- .translate? ⇒ Boolean
Instance Method Summary collapse
Methods inherited from BaseModel
#[], #[]=, _added_elements, #_check, add_element, #after_delete, #after_save, all, #all_children, all_values_observers, attribute, auto_primary_keys?, #autoload, #autoload=, #autoload?, #become, #before_delete, #before_save, choice, class_table_inheritance, #clear_values, #clone, condition, containing_module, count, create, create_inline_model, #cut, define_element_methods, #delete, #delete!, dump_element, #dump_to_all_data_hash, #dump_to_hash, #each, each_element, #each_val, element, element_association?, element_attributes, element_defined, #element_has_value?, #element_loaded, #element_loaded?, #element_modified?, element_query, elements, elements_array, #elements_modified?, embeddable?, #embedder, #empty?, #eql?, extend_model, extend_queryset, extended_models, find, first_definer, free_query_condition, from_hash_dump, from_yaml, get, #get, get_element, get_mapper, #get_new, #get_new_static, #get_no_load, get_static, group, has_element?, #identity_mapper, #identity_mapper=, #in_storage?, in_transaction, inherit_storage, inherited, #initialize, #insert, #insert!, #inspect, #instantiate_element, integrate, integrate_element, junction?, #keys_string, keys_string, #keys_to_condition, label, label_, label_plural, label_plural_, list, load, #load, load_or_create, managed?, many, #mapper=, mapper_include, mapper_include_for, #merge!, #merge_hash, #method_missing, #modified?, multiple_choice, #no_autoload, not_embeddable, #notify_observers, notify_observers, #obj_pks, #observe_all_values, #observe_element, observe_element, observer_all_values, on_element_defined, only_embedded, only_embedded?, own_elements, polymorphic, #polymorphic_become, #prepare_child, prepare_query, prepare_to_code, #prepare_value, prepare_value, primary_keys, #primary_keys, #primary_keys_hash, #primary_keys_set?, referenced_by_junctions, #remove_association, remove_element, remove_integrate, #reset_modified_elements, #respond_to?, #save, #save!, #save_all, #save_mode, #saving, #saving?, sequence, #set, #set!, #set_hash, #set_loaded_value, #set_modified, #set_parent, #set_reverse, #set_values, short_name, split_keys_string, static, storage, #storage, storage=, #subclass, subclasses, submodels, sync_schema, to_code, #to_hash, #to_json, #to_s, to_s, #to_yaml, #to_yaml_h, #unit_of_work_available?, #update, #update!, use_storage, #use_storage, value_observers, where, with_mapper, with_mapper_for
Methods included from EventSource
Methods included from QueryFuncs
Methods included from Logger
add, check_request_level, close, close_all, datetime_format, datetime_format=, #debug, debug, debug?, #debug?, enquire_loggers, #error, error, #error?, error?, fatal, #fatal, fatal?, #fatal?, info, #info, info?, #info?, #log, log, method_missing, open, reopen, request_level, send_to_loggers, set_request_level, unknown, #unknown, warn, #warn, warn?, #warn?
Methods included from App::AppClass
Constructor Details
This class inherits a constructor from Spider::Model::BaseModel
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Spider::Model::BaseModel
Class Method Details
.data(val = nil) ⇒ Object
Sets/gets model data.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spiderfw/model/inline_model.rb', line 17 def data(val=nil) self.data = val if (val) d = @data if self.translate? Spider::GetText.in_domain(self.app.short_name){ @data.each do |k, v| d[k] = _(v) end } end d end |
.data=(val) ⇒ Object
Sets model data.
12 13 14 |
# File 'lib/spiderfw/model/inline_model.rb', line 12 def data=(val) @data = val end |
.get_storage(url = 'default') ⇒ Object
42 43 44 |
# File 'lib/spiderfw/model/inline_model.rb', line 42 def get_storage(url='default') self.data end |
.mapper ⇒ Object
38 39 40 |
# File 'lib/spiderfw/model/inline_model.rb', line 38 def mapper return Mappers::HashMapper.new(self, self.data) end |
.translate=(val) ⇒ Object
30 31 32 |
# File 'lib/spiderfw/model/inline_model.rb', line 30 def translate=(val) @translate = val end |
.translate? ⇒ Boolean
34 35 36 |
# File 'lib/spiderfw/model/inline_model.rb', line 34 def translate? @translate end |
Instance Method Details
#==(val) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/spiderfw/model/inline_model.rb', line 52 def ==(val) return super unless self.class.primary_keys.length == 1 pk = self.class.primary_keys.first if pk.type == String || pk.type == Symbol if val.is_a?(String) || val.is_a?(Symbol) return val.to_s == self.get(pk).to_s end elsif val.is_a?(pk.type) return val == self.get(pk) end return super end |
#mapper ⇒ Object
48 49 50 |
# File 'lib/spiderfw/model/inline_model.rb', line 48 def mapper return self.class.mapper end |