nali 0.1.5 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,29 +22,36 @@ Nali.extend Model:
22
22
  @
23
23
 
24
24
  notice: ( params ) ->
25
+ # добавляет уведомление в очередь на выполнение, запускает выполнение очереди
25
26
  @noticesWait.push params
26
27
  @runNotices()
27
28
  @
28
29
 
29
30
  runNotices: ->
31
+ # запускает выполнение уведомлений на существующих моделях
30
32
  for item, index in @noticesWait[ 0.. ]
31
33
  if model = @extensions[ item.model ].find item.id
32
34
  model[ item.notice ] item.params
33
35
  @noticesWait.splice @noticesWait.indexOf( item ), 1
34
36
  @
35
-
36
- force: ( params = {} ) ->
37
- attributes = @default_attributes()
38
- attributes[ name ] = value for name, value of params
39
- attributes[ name ] = @normalizeValue value for name, value of attributes
40
- @clone( attributes: attributes ).accessing()
37
+
38
+ # работа с моделями
41
39
 
42
40
  accessing: ->
41
+ # устанавливает геттеры доступа к атрибутам и связям
43
42
  @access @attributes
44
43
  @setRelations()
45
44
  @
46
45
 
46
+ force: ( params = {} ) ->
47
+ # создает новую модель с заданными атрибутами
48
+ attributes = @default_attributes()
49
+ attributes[ name ] = value for name, value of params
50
+ attributes[ name ] = @normalizeValue value for name, value of attributes
51
+ @clone( attributes: attributes ).accessing()
52
+
47
53
  save: ( success, failure ) ->
54
+ # отправляет на сервер запрос на сохранение модели, вызывает success в случае успеха и failure при неудаче
48
55
  if @isValid()
49
56
  @query "#{ @sysname.lowercase() }s.save", @attributes,
50
57
  ( { attributes, created, updated } ) =>
@@ -54,6 +61,7 @@ Nali.extend Model:
54
61
  @
55
62
 
56
63
  sync: ( { sysname, attributes, created, updated, destroyed } ) ->
64
+ # синхронизирует пришедшую с сервера модель с локальной, либо создает новую
57
65
  if model = @extensions[ sysname ].find attributes.id
58
66
  if destroyed then model.remove()
59
67
  else model.update attributes, updated, created
@@ -65,12 +73,11 @@ Nali.extend Model:
65
73
  @
66
74
 
67
75
  select: ( filters, success, failure ) ->
76
+ # отправляет на сервер запрос на выборку моделей по фильтру, вызывает success в случае успеха и failure при неудаче
68
77
  @query @sysname.lowercase() + 's.select', filters, success, failure if Object.keys( filters ).length
69
-
70
- destroy: ( success, failure ) ->
71
- @query @sysname.lowercase() + 's.destroy', @attributes, success, failure
72
-
78
+
73
79
  write: ->
80
+ # добавляет модель во временную таблицу, генерирует событие create
74
81
  unless @ in @table
75
82
  @table.push @
76
83
  @table.index[ @id ] = @
@@ -80,6 +87,7 @@ Nali.extend Model:
80
87
  @
81
88
 
82
89
  remove: ->
90
+ # удаляет модель из временной таблицы, генерирует событие destroy
83
91
  if @ in @table
84
92
  delete @table.index[ @id ]
85
93
  @table.splice @table.indexOf( @ ), 1
@@ -89,12 +97,15 @@ Nali.extend Model:
89
97
  @
90
98
 
91
99
  build: ( attributes ) ->
100
+ # создает модель, не сохраняя её на сервере
92
101
  @force attributes
93
102
 
94
103
  create: ( attributes, success, failure ) ->
104
+ # создает модель, и сохраняет её на сервере, вызывает success в случае успеха и failure при неудаче
95
105
  @build( attributes ).save success, failure
96
106
 
97
107
  update: ( attributes, updated = 0, created = 0 ) ->
108
+ # обновляет атрибуты модели, проверяя их валидность, генерирует событие update
98
109
  if not updated or updated > @updated
99
110
  @created = created if created
100
111
  changed = []
@@ -106,6 +117,7 @@ Nali.extend Model:
106
117
  @
107
118
 
108
119
  update_attribute: ( name, value ) ->
120
+ # обновляет один атрибут модели, проверяя его валидность, генерирует событие update.{ propertyName }
109
121
  value = @normalizeValue value
110
122
  if @attributes[ name ] isnt value and @isValidAttributeValue( name, value )
111
123
  @attributes[ name ] = value
@@ -113,11 +125,20 @@ Nali.extend Model:
113
125
  @trigger "update.#{ name }", @
114
126
  true
115
127
  else false
116
-
128
+
129
+ destroy: ( success, failure ) ->
130
+ # отправляет на сервер запрос на удаление модели, вызывает success в случае успеха и failure при неудаче
131
+ @query @sysname.lowercase() + 's.destroy', @attributes, success, failure
132
+
133
+ # поиск моделей
134
+
117
135
  find: ( id ) ->
136
+ # находит модель по её id используя индекс
118
137
  @table.index[ id ]
119
138
 
120
139
  where: ( filters ) ->
140
+ # находит все модели соответствующие фильтру, также отправляет запрос с фильтром на сервер,
141
+ # возвращает коллекцию моделей, модели найденные на сервере также попадут в эту коллекцию
121
142
  collection = @Collection.clone model: @, filters: filters
122
143
  collection.add model for model in @table when model.isCorrect filters
123
144
  if @forced and not collection.length
@@ -65,7 +65,7 @@ module Nali
65
65
  def self.initialize!
66
66
  Dir[ File.join( root, 'lib/*/**/*.rb' ) ].each { |file| require( file ) }
67
67
  Dir[ File.join( root, 'app/**/*.rb' ) ].each { |file| require( file ) }
68
- Dir[ File.join( root, 'vendor/*/**/*.rb' ) ].each { |file| require( file ) }
68
+ #Dir[ File.join( root, 'vendor/*/**/*.rb' ) ].each { |file| require( file ) }
69
69
  require File.join( root, 'config/application' )
70
70
  self
71
71
  end
data/lib/nali/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Nali
2
2
 
3
- VERSION = '0.1.5'
3
+ VERSION = '0.1.6'
4
4
 
5
- end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nali
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-10-09 00:00:00.000000000 Z
12
+ date: 2014-10-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thin