constructor-pages 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 27f76c8e1756acf621e7a34dae4b7b798feb78f8
4
- data.tar.gz: 046ce61e61f77fea4d4d79e845cc2532443db873
3
+ metadata.gz: faf1f032d1ec89024e5b084a5e2ac7d8d1f6c314
4
+ data.tar.gz: ac50636c415bcd262f2914351035f0dfc20ef8cb
5
5
  SHA512:
6
- metadata.gz: 35da98b6fb19281f2805672469f3d3ce5bda0cfaaa36177c8ba54ff777b6e266e6a051e63265fed720786e42dbaf119912ac4a8187c9d9d137e6726dfc39a747
7
- data.tar.gz: cc53c47824bc38ca8b93dea6595116a9de302faf124be0abb50681e9b4b182b32d467d36732723780d23ae59b0b72159c2ff3e3f70f82212bc1453829e4a30e2
6
+ metadata.gz: 8ee5412da1e0460c3dcbe2a5847c182c09e283c96bb9c89524c663ca527c92b1dc605804eedf13f4f8cb2380f60002a1426b1c6fe73de91d71eb4dfd2d46fc57
7
+ data.tar.gz: fa9d1b99f03fd28d70e6bf86cd55f46a44e919d92927c5a42826a36355c34cd958085ae6d439a0df511436f253c74a55c2444a098f0ceaed2ecaa0e645b94135
@@ -15,9 +15,9 @@ module ConstructorPages
15
15
 
16
16
  default_scope -> { order :lft }
17
17
 
18
- validate :template_check
18
+ validate :templates_existing_check
19
19
 
20
- before_save :friendly_url, :template_assign, :full_url_update
20
+ before_save :friendly_url, :assing_template, :full_url_update
21
21
  after_update :descendants_update
22
22
  after_create :create_fields_values
23
23
 
@@ -46,29 +46,32 @@ module ConstructorPages
46
46
  true
47
47
  end
48
48
 
49
- def search(what_search = nil)
50
- hash_search, array_search = {}, []
51
-
52
- @where_search = Page.find_by(full_url: @where_search) if @where_search.is_a?(String)
53
- array_search = ['lft > ? and rgt < ?', @where_search.lft, @where_search.rgt] if @where_search
54
-
55
- what_search && what_search = what_search.to_s.singularize.downcase
56
- hash_search[:template_id] = ConstructorPages::Template.find_by(code_name: what_search).try(:id) if what_search
57
-
58
- hash_search[:id] = ids_by_params(@params_search) if @params_search
59
-
60
- @where_search = @params_search = nil
61
-
62
- hash_search.empty? && array_search.empty? ? [] : Page.where(hash_search).where(array_search).to_a
49
+ # Search pages
50
+ #
51
+ # Example:
52
+ # Page.in('/conditioners').search_by(area: 25)
53
+ # Page.by('price<' => 5000).search_in('/zanussi')
54
+ # Page.in('/midea').by('price>' => 10000).search(:models)
55
+ def search(what = nil)
56
+ _hash, _array = {}, []
57
+ @where = Page.find_by(full_url: @where) if @where.is_a?(String)
58
+ _array = ['lft > ? and rgt < ?', @where.lft, @where.rgt] if @where
59
+ if what
60
+ what = what.to_s.singularize.downcase
61
+ _hash[:template_id] = ConstructorPages::Template.find_by(code_name: what).try(:id)
62
+ end
63
+ _hash[:id] = ids_by_params(@params) if @params
64
+ @where = @params = nil
65
+ _hash.empty? && _array.empty? ? [] : Page.where(_hash).where(_array).to_a
63
66
  end
64
67
 
65
- def in(where_search = nil); tap {@where_search = where_search} end
66
- def by(params_search = nil); tap {@params_search = params_search} end
67
-
68
- def search_in(where_search = nil); self.in(where_search).search end
69
- def search_by(params_search = nil); self.by(params_search).search end
68
+ def in(where = nil); tap {@where = where} end
69
+ def by(params = nil); tap {@params = params} end
70
70
 
71
+ def search_in(where = nil); self.in(where).search end
72
+ def search_by(params = nil); self.by(params).search end
71
73
 
74
+ # Return ids of pages founded by params
72
75
  def ids_by_params(params)
73
76
  _hash = {}
74
77
 
@@ -108,9 +111,9 @@ module ConstructorPages
108
111
  end
109
112
  end
110
113
 
111
- def search(what_search = nil); Page.in(self).search(what_search) end
112
- def by(params_search = nil); Page.by(params_search); self end
113
- def search_by(params_search = nil); Page.by(params_search).in(self).search end
114
+ def search(what = nil); Page.in(self).search(what) end
115
+ def by(params = nil); Page.by(params); self end
116
+ def search_by(params = nil); Page.by(params).in(self).search end
114
117
 
115
118
  # Get field by code_name
116
119
  def field(code_name)
@@ -205,10 +208,10 @@ module ConstructorPages
205
208
  end
206
209
 
207
210
  # Page is not valid if there is no template
208
- def template_check; errors.add_on_empty(:template_id) if Template.count == 0 end
211
+ def templates_existing_check; errors.add_on_empty(:template_id) if Template.count == 0 end
209
212
 
210
213
  # If template_id is nil then get first template
211
- def template_assign; self.template_id = Template.first.id unless template_id end
214
+ def assign_template; self.template_id = Template.first.id unless template_id end
212
215
 
213
216
  # Update full_url
214
217
  def full_url_update
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructor-pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Zotov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-09 00:00:00.000000000 Z
11
+ date: 2013-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: constructor-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.6
19
+ version: 0.8.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.6
26
+ version: 0.8.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dragonfly
29
29
  requirement: !ruby/object:Gem::Requirement