Module: Rhom::BaseModel
- Included in:
- FixedSchema, PropertyBag
- Defined in:
- lib/framework/rhom/rhom_model.rb,
lib/framework/autocomplete/Rhom.rb,
lib/framework/newrhom/newrhom_model.rb
Class Attribute Summary collapse
-
.model_params ⇒ Object
Returns the value of attribute model_params.
Instance Method Summary collapse
- #belongs_to(name, owner) ⇒ Object
- #enable(name) ⇒ Object
- #fixed_schema? ⇒ Boolean
- #get_model_params ⇒ Object
- #index(name, cols) ⇒ Object
- #init_defaults ⇒ Object
- #init_model ⇒ Object
- #property(name, type = :string, option = nil) ⇒ Object
- #reset_model_params ⇒ Object
- #set(name, value) ⇒ Object
- #unique_index(name, cols) ⇒ Object
Class Attribute Details
.model_params ⇒ Object
Returns the value of attribute model_params.
31 32 33 |
# File 'lib/framework/rhom/rhom_model.rb', line 31 def model_params @model_params end |
Instance Method Details
#belongs_to(name, owner) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/framework/rhom/rhom_model.rb', line 88 def belongs_to(name, owner) BaseModel.model_params ||= {} BaseModel.model_params['belongs_to'] ||= [] if owner.is_a?(Array) owner.each do |src| BaseModel.model_params['belongs_to'] << {name.to_s => src.to_s} end else BaseModel.model_params['belongs_to'] << {name.to_s => owner.to_s} end end |
#enable(name) ⇒ Object
84 85 86 |
# File 'lib/framework/rhom/rhom_model.rb', line 84 def enable(name) set(name,true) end |
#fixed_schema? ⇒ Boolean
44 45 46 |
# File 'lib/framework/rhom/rhom_model.rb', line 44 def fixed_schema? false end |
#get_model_params ⇒ Object
35 36 37 38 |
# File 'lib/framework/rhom/rhom_model.rb', line 35 def get_model_params init_defaults BaseModel.model_params end |
#index(name, cols) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/framework/rhom/rhom_model.rb', line 101 def index(name,cols) return unless fixed_schema? BaseModel.model_params['schema'] ||= {} BaseModel.model_params['schema']['index'] ||= {} BaseModel.model_params['schema']['index'][name.to_s] = cols end |
#init_defaults ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/framework/rhom/rhom_model.rb', line 48 def init_defaults if fixed_schema? BaseModel.model_params ||= {} BaseModel.model_params['schema'] ||= {} BaseModel.model_params['schema']['property'] ||= {} else BaseModel.model_params ||= {} BaseModel.model_params ||= {} BaseModel.model_params['property'] ||= {} end end |
#init_model ⇒ Object
3 4 5 6 |
# File 'lib/framework/newrhom/newrhom_model.rb', line 3 def init_model puts "MZV_DEBUG: Model '#{klass_model.model_name}': init_model" klass_model.initModel end |
#property(name, type = :string, option = nil) ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/framework/rhom/rhom_model.rb', line 60 def property(name,type=:string,option=nil) init_defaults if fixed_schema?() BaseModel.model_params['schema']['property'][name.to_s] = [type,option] else BaseModel.model_params['property'][name.to_s] = [type,option] end end |
#reset_model_params ⇒ Object
40 41 42 |
# File 'lib/framework/rhom/rhom_model.rb', line 40 def reset_model_params BaseModel.model_params = {} end |
#set(name, value) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/framework/rhom/rhom_model.rb', line 70 def set(name,value) BaseModel.model_params ||= {} if ( name == :sync ) if ( value ) BaseModel.model_params['sync_type'] = 'incremental' unless BaseModel.model_params['sync_type'] else BaseModel.model_params.delete('sync_type') end else BaseModel.model_params[name.to_s] = value end end |
#unique_index(name, cols) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/framework/rhom/rhom_model.rb', line 110 def unique_index(name,cols) return unless fixed_schema? BaseModel.model_params['schema'] ||= {} BaseModel.model_params['schema']['unique_index'] ||= {} BaseModel.model_params['schema']['unique_index'][name.to_s] = cols end |