Class: Dataset::SessionBinding
- Inherits:
-
Object
- Object
- Dataset::SessionBinding
- Defined in:
- lib/dataset/session_binding.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#block_variables ⇒ Object
readonly
Returns the value of attribute block_variables.
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#model_finders ⇒ Object
readonly
Returns the value of attribute model_finders.
-
#parent_binding ⇒ Object
readonly
Returns the value of attribute parent_binding.
-
#record_methods ⇒ Object
readonly
Returns the value of attribute record_methods.
Instance Method Summary collapse
- #copy_block_variables(dataset_block) ⇒ Object
- #create_model(record_type, *args) ⇒ Object
- #create_record(record_type, *args) ⇒ Object
- #find_id(record_type_or_meta, symbolic_name) ⇒ Object
- #find_model(record_type_or_meta, symbolic_name) ⇒ Object
-
#initialize(database_or_parent_binding) ⇒ SessionBinding
constructor
A new instance of SessionBinding.
- #install_block_variables(target) ⇒ Object
- #name_model(record, symbolic_name) ⇒ Object
- #name_to_sym(name) ⇒ Object
- #record_meta_for_type(record_type) ⇒ Object
Constructor Details
#initialize(database_or_parent_binding) ⇒ SessionBinding
Returns a new instance of SessionBinding.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/dataset/session_binding.rb', line 177 def initialize(database_or_parent_binding) @id_cache = Hash.new {|h,k| h[k] = {}} @record_methods = new_record_methods_module @model_finders = new_model_finders_module @block_variables = Hash.new case database_or_parent_binding when Dataset::SessionBinding @parent_binding = database_or_parent_binding @database = parent_binding.database @model_finders.module_eval { include database_or_parent_binding.model_finders } @block_variables.update(database_or_parent_binding.block_variables) else @database = database_or_parent_binding end end |
Instance Attribute Details
#block_variables ⇒ Object (readonly)
Returns the value of attribute block_variables.
175 176 177 |
# File 'lib/dataset/session_binding.rb', line 175 def block_variables @block_variables end |
#database ⇒ Object (readonly)
Returns the value of attribute database.
173 174 175 |
# File 'lib/dataset/session_binding.rb', line 173 def database @database end |
#model_finders ⇒ Object (readonly)
Returns the value of attribute model_finders.
174 175 176 |
# File 'lib/dataset/session_binding.rb', line 174 def model_finders @model_finders end |
#parent_binding ⇒ Object (readonly)
Returns the value of attribute parent_binding.
173 174 175 |
# File 'lib/dataset/session_binding.rb', line 173 def parent_binding @parent_binding end |
#record_methods ⇒ Object (readonly)
Returns the value of attribute record_methods.
174 175 176 |
# File 'lib/dataset/session_binding.rb', line 174 def record_methods @record_methods end |
Instance Method Details
#copy_block_variables(dataset_block) ⇒ Object
194 195 196 197 198 |
# File 'lib/dataset/session_binding.rb', line 194 def copy_block_variables(dataset_block) dataset_block.instance_variables.each do |name| self.block_variables[name] = dataset_block.instance_variable_get(name) end end |
#create_model(record_type, *args) ⇒ Object
200 201 202 |
# File 'lib/dataset/session_binding.rb', line 200 def create_model(record_type, *args) insert(Dataset::Record::Model, record_type, *args) end |
#create_record(record_type, *args) ⇒ Object
204 205 206 |
# File 'lib/dataset/session_binding.rb', line 204 def create_record(record_type, *args) insert(Dataset::Record::Fixture, record_type, *args) end |
#find_id(record_type_or_meta, symbolic_name) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/dataset/session_binding.rb', line 208 def find_id(, symbolic_name) = () heirarchy = .heirarchy if local_id = @id_cache[heirarchy.id_cache_key][symbolic_name] local_id elsif !parent_binding.nil? parent_binding.find_id , symbolic_name else raise RecordNotFound.new(heirarchy, symbolic_name) end end |
#find_model(record_type_or_meta, symbolic_name) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/dataset/session_binding.rb', line 220 def find_model(, symbolic_name) = () heirarchy = .heirarchy if local_id = @id_cache[heirarchy.id_cache_key][symbolic_name] heirarchy.base_class.find local_id elsif !parent_binding.nil? parent_binding.find_model , symbolic_name else raise RecordNotFound.new(heirarchy, symbolic_name) end end |
#install_block_variables(target) ⇒ Object
232 233 234 235 236 |
# File 'lib/dataset/session_binding.rb', line 232 def install_block_variables(target) block_variables.each do |k,v| target.instance_variable_set(k,v) end end |
#name_model(record, symbolic_name) ⇒ Object
238 239 240 241 242 243 |
# File 'lib/dataset/session_binding.rb', line 238 def name_model(record, symbolic_name) = database.(record.class) @model_finders.create_finders() @id_cache[.heirarchy.id_cache_key][symbolic_name] = record.id record end |
#name_to_sym(name) ⇒ Object
252 253 254 |
# File 'lib/dataset/session_binding.rb', line 252 def name_to_sym(name) name.to_s.underscore.gsub("'", "").gsub("\"", "").gsub(" ", "_").to_sym if name end |