bitrix_on_rails 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.1.8
data/app/models/iblock.rb CHANGED
@@ -122,25 +122,11 @@ class Iblock < ActiveRecord::Base
122
122
  unless Kernel.const_defined? const_name
123
123
  e = Class.new(ActiveRecord::Base) do
124
124
  extend BitrixOnRails::IblockElementPropS
125
-
126
- class << self
127
- @m_prop_class = nil
128
- @m_props = nil
129
-
130
- def m_prop_class
131
- Kernel.const_get(@m_prop_class)
132
- end
133
-
134
- def m_props
135
- @m_props
136
- end
137
- end
138
-
139
- acts_as_iblock_element_prop_s(iblock_id)
140
- end
141
- Kernel.const_set const_name, e
142
- end
143
- Kernel.const_get(const_name).init
125
+ acts_as_iblock_element_prop_s(iblock_id)
126
+ end
127
+ Kernel.const_set const_name, e
128
+ end
129
+ Kernel.const_get(const_name).init
144
130
 
145
131
  # Создаем классы IblockElementPropMНОМЕР
146
132
  #
@@ -29,11 +29,15 @@ class IblockElement < ActiveRecord::Base
29
29
  def set_iblock_id(id)
30
30
  @iblock_id = id
31
31
 
32
- prop_s_class = "IblockElementPropS#{id}"
33
- prop_m_class = "IblockElementPropM#{id}"
32
+ hash = {
33
+ :class_name => Iblock.s_props_class(id).name,
34
+ :foreign_key => 'iblock_element_id',
35
+ :autosave => true}
36
+ has_one :s_prop, hash
37
+ has_one "iblock_element_prop_s#{iblock_id}".to_sym, hash
34
38
 
35
- has_one :property_set, :class_name => "::#{prop_s_class}", :foreign_key => 'iblock_element_id', :autosave => true
36
- has_many :m_prop_values, :class_name => "::#{prop_m_class}", :foreign_key => 'iblock_element_id'
39
+ has_many :m_prop_values, :class_name => Iblock.m_props_class(id),
40
+ :foreign_key => 'iblock_element_id', :autosave => true
37
41
 
38
42
  default_scope where(:iblock_id => id, :active => 'Y')
39
43
 
@@ -56,4 +60,12 @@ class IblockElement < ActiveRecord::Base
56
60
  def to_s
57
61
  name
58
62
  end
63
+
64
+ def multiply_properties
65
+ send "iblock_element_prop_m#{iblock_id}"
66
+ end
67
+
68
+ def property_set
69
+ send "iblock_element_prop_s#{iblock_id}"
70
+ end
59
71
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{bitrix_on_rails}
8
- s.version = "0.1.7"
8
+ s.version = "0.1.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Danil Pismenny"]
@@ -4,11 +4,6 @@ module BitrixOnRails::IblockElementPropS
4
4
  extend ClassMethods
5
5
  include InstanceMethods
6
6
 
7
- @m_prop_class = "IblockElementPropM#{id}"
8
- # Название свойства сохраняется только для наглядности, чтобы можно было через консоль понять
9
- # что за свойство.
10
- @m_props = IblockProperty.where(:iblock_id => id).inject({}){ |a,e| a[e.code] = e.id if e.multiple == 'Y'; a }
11
-
12
7
  # Убираем лишнюю s вконце
13
8
  #set_table_name 'b_'+table_name.chop
14
9
  set_table_name "b_iblock_element_prop_s#{id}"
@@ -26,10 +21,9 @@ module BitrixOnRails::IblockElementPropS
26
21
  end
27
22
 
28
23
  before_save do
29
- self.class.m_props.each_value { |id|
30
- values = m_prop_values(id)
31
- self.send("property_#{id}=", PHP.serialize({'VALUE' => values, 'DESCRIPTION' => Array.new(values.size, nil)}))
32
- # self.send("property_#{id}=", PhpSerialization.dump({'VALUE' => values, 'DESCRIPTION' => Array.new(values.size, nil)}))
24
+ self.class.m_props.each_value { |p|
25
+ values = m_prop_values(p.id)
26
+ self.send("property_#{p.id}=", PHP.serialize({'VALUE' => values, 'DESCRIPTION' => Array.new(values.size, nil)}))
33
27
  }
34
28
  end
35
29
 
@@ -41,6 +35,14 @@ module BitrixOnRails::IblockElementPropS
41
35
 
42
36
  module ClassMethods
43
37
 
38
+
39
+ def m_props
40
+ # @m_prop_class = "IblockElementPropM#{id}"
41
+ # Название свойства сохраняется только для наглядности, чтобы можно было через консоль понять
42
+ # что за свойство.
43
+ @m_props ||= Iblock.get_properties(iblock_id).select { |k,e| e.multiple == 'Y' }
44
+ end
45
+
44
46
  # code - врое как кодовое название свойства
45
47
  # name - русское описание
46
48
 
@@ -60,11 +62,17 @@ module BitrixOnRails::IblockElementPropS
60
62
  #
61
63
  # self.post_id вместо self.property_120
62
64
  #
65
+
66
+ def iblock_id
67
+ self.name=~/(\d+)/
68
+ $1.to_i
69
+ end
70
+
63
71
  def init
64
- self.to_s=~/(\d+)/
65
- iblock_id = $1.to_i
66
72
 
67
- IblockElement.send :has_one, "iblock_element_prop_s#{iblock_id}".to_sym, :class_name=>"::IblockElementPropS#{iblock_id}"
73
+ # Вот это не срабатывает для Post::Element
74
+ #
75
+ IblockElement.send :has_one, "iblock_element_prop_s#{iblock_id}".to_sym, :class_name=>Iblock.s_props_class(iblock_id).name, :autosave => true
68
76
 
69
77
  self.properties = {}
70
78
  attribute_names.select {|a| a[0,4]=='prop' }.each do |name|
@@ -96,6 +104,11 @@ module BitrixOnRails::IblockElementPropS
96
104
 
97
105
  module InstanceMethods
98
106
 
107
+ def iblock_id
108
+ self.class.to_s=~/(\d+)/
109
+ $1.to_i
110
+ end
111
+
99
112
  # Возвращает десериализованное (при необходимости) значение свойства
100
113
  #
101
114
  # prop - код свойства (post_id к примеру)
@@ -104,15 +117,15 @@ module BitrixOnRails::IblockElementPropS
104
117
  end
105
118
 
106
119
  def m_prop_values(prop_id)
107
- self.class.m_prop_class.where(:iblock_element_id => self.id, :iblock_property_id => prop_id).collect { |e| e.value }
120
+ Iblock.m_props_class(iblock_id).where(:iblock_element_id => self.id, :iblock_property_id => prop_id).collect { |e| e.value }
108
121
  end
109
122
 
110
123
  def create_m_prop_value(prop_id, value)
111
- self.class.m_prop_class.create(:iblock_element_id => self.id, :iblock_property_id => prop_id, :value => value)
124
+ Iblock.m_props_class(iblock_id).create(:iblock_element_id => self.id, :iblock_property_id => prop_id, :value => value)
112
125
  end
113
126
 
114
127
  def destroy_m_prop_value(prop_id, value)
115
- m_props = self.class.m_prop_class.where(:iblock_element_id => self.iblock_element_id, :iblock_property_id => prop_id, :value => value)
128
+ m_props = Iblock.m_props_class(iblock_id).where(:iblock_element_id => self.iblock_element_id, :iblock_property_id => prop_id, :value => value)
116
129
  m_props.each { |p| p.destroy } if m_props.any?
117
130
  end
118
131
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitrix_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
17
- requirement: &2152591520 !ruby/object:Gem::Requirement
17
+ requirement: &2156264660 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2152591520
25
+ version_requirements: *2156264660
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: sqlite3
28
- requirement: &2152590160 !ruby/object:Gem::Requirement
28
+ requirement: &2156263400 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
- version_requirements: *2152590160
36
+ version_requirements: *2156263400
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: shoulda
39
- requirement: &2152588760 !ruby/object:Gem::Requirement
39
+ requirement: &2156261940 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2152588760
47
+ version_requirements: *2156261940
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
- requirement: &2152587320 !ruby/object:Gem::Requirement
50
+ requirement: &2156260820 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.0.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2152587320
58
+ version_requirements: *2156260820
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: jeweler
61
- requirement: &2152585880 !ruby/object:Gem::Requirement
61
+ requirement: &2156259780 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.6.4
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2152585880
69
+ version_requirements: *2156259780
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rcov
72
- requirement: &2152584520 !ruby/object:Gem::Requirement
72
+ requirement: &2156258340 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2152584520
80
+ version_requirements: *2156258340
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: ruby-debug19
83
- requirement: &2152583840 !ruby/object:Gem::Requirement
83
+ requirement: &2156257140 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *2152583840
91
+ version_requirements: *2156257140
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: test-unit
94
- requirement: &2152583100 !ruby/object:Gem::Requirement
94
+ requirement: &2156255520 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *2152583100
102
+ version_requirements: *2156255520
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rb-fsevent
105
- requirement: &2152582460 !ruby/object:Gem::Requirement
105
+ requirement: &2156236280 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *2152582460
113
+ version_requirements: *2156236280
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: growl
116
- requirement: &2152581680 !ruby/object:Gem::Requirement
116
+ requirement: &2156220420 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *2152581680
124
+ version_requirements: *2156220420
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: guard-test
127
- requirement: &2152581040 !ruby/object:Gem::Requirement
127
+ requirement: &2156216740 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ! '>='
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: '0'
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *2152581040
135
+ version_requirements: *2156216740
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: test-unit-rr
138
- requirement: &2152580340 !ruby/object:Gem::Requirement
138
+ requirement: &2156214480 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,7 +143,7 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *2152580340
146
+ version_requirements: *2156214480
147
147
  description: Использование инфоблоков 1С-Битрикс в Ruby On Rails проектах
148
148
  email: danil@orionet.ru
149
149
  executables: []
@@ -199,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
199
  version: '0'
200
200
  segments:
201
201
  - 0
202
- hash: -279074760190885807
202
+ hash: 4502115155340295236
203
203
  required_rubygems_version: !ruby/object:Gem::Requirement
204
204
  none: false
205
205
  requirements: