platanus 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ # tag_set.rb : word search optimized list serialization
2
+ #
3
+ # TODO: make notation compatible with fulltext-search.
4
+ #
5
+ # Copyright October 2012, Ignacio Baixas +mailto:ignacio@platan.us+.
6
+
7
+ module Platanus
8
+ module Serializers
9
+ class TagSet
10
+
11
+ def self.load(_str)
12
+ return [] if _str.nil?
13
+ return [] if _str == '::::'
14
+ _str.split('::')[1..-1]
15
+ end
16
+
17
+ def self.dump(_data)
18
+ "::#{_data.join('::')}::"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,81 @@
1
+ # tag_set_attr.rb : searchable tag sets.
2
+ #
3
+ # usage:
4
+ #
5
+ # class Model
6
+ # include Platanus::TagSetAttr
7
+ #
8
+ # attr_tagset :demo
9
+ # end
10
+ #
11
+ # t = Model.create
12
+ # t.demo << 'tag1'
13
+ # t.demo << 'tag2'
14
+ # t.save!
15
+ #
16
+ # t.demo # returns ['tag1', 'tag2']
17
+ #
18
+ # #searching
19
+ # Model.search_by_demo(all: 'tag1') # returns [t]
20
+ # Model.search_by_demo(all: 'tag1', none: 'tag2') # returns []
21
+ #
22
+ # # TODO: provide fulltext search support.
23
+ #
24
+ # Copyright February 2013, Ignacio Baixas +mailto:ignacio@platan.us+.
25
+
26
+ module Platanus::TagSetAttr
27
+
28
+ def self.included(base)
29
+ base.extend ClassMethods
30
+ end
31
+
32
+ module ClassMethods
33
+
34
+ # Adds a tag list attribute to the model.
35
+ def attr_tagset(_name, _options={})
36
+
37
+ _name = _name.to_s
38
+
39
+ send :serialize, _name, Platanus::Serializers::TagSet
40
+
41
+ klass = class << self; self; end
42
+
43
+ klass.send :define_method, "search_by_#{_name.singularize}" do |_opt={}|
44
+
45
+ target = self
46
+
47
+ # The 'any' filter matches if one of the tokens match
48
+ if _opt.has_key? :any
49
+ params = []; any_sql = []
50
+ Array(_opt[:any]).collect do |token|
51
+ params << "%::#{token}::%"
52
+ any_sql << "#{_name} LIKE ?"
53
+ end
54
+ target = target.where("(#{or_sql.join(' OR ')})", *params) if params.length > 0
55
+ end
56
+
57
+ # The 'all' filter matches if all of the tokens match
58
+ if _opt.has_key? :all
59
+ params = []; and_sql = []
60
+ Array(_opt[:all]).each do |token|
61
+ params << "%::#{token}::%"
62
+ and_sql << "#{_name} LIKE ?"
63
+ end
64
+ target = target.where("#{and_sql.join(' AND ')}", *params) if params.length > 0
65
+ end
66
+
67
+ # The 'none' filter matches if none of the tokens match
68
+ if _opt.has_key? :none
69
+ params = []; ex_sql = []
70
+ Array(_opt[:none]).each do |token|
71
+ params << "%::#{token}::%"
72
+ ex_sql << "#{_name} is NULL OR #{_name} NOT LIKE ?"
73
+ end
74
+ target = target.where("#{ex_sql.join(' AND ')}", *params) if params.length > 0
75
+ end
76
+
77
+ return target
78
+ end
79
+ end
80
+ end
81
+ end
@@ -1,3 +1,3 @@
1
1
  module Platanus
2
- VERSION = "0.1.6" # 0.2 will come with tests!
2
+ VERSION = "0.1.7" # 0.2 will come with tests!
3
3
  end
data/lib/platanus.rb CHANGED
@@ -1,21 +1,32 @@
1
1
  require "platanus/version"
2
2
 
3
- require 'platanus/canned'
4
- require 'platanus/stacked'
3
+ require 'platanus/canned' # TODO: deprecated, remove
4
+
5
+ # Serializers
6
+ require 'platanus/serializers/tag_set'
7
+ require 'platanus/serializers/json_sym'
8
+
9
+ # active record behaviors
10
+ require 'platanus/stacked' # TODO: deprecated, remove
5
11
  require 'platanus/activable'
6
12
  require 'platanus/traceable'
7
- require 'platanus/layered'
13
+ require 'platanus/layered' # TODO: deprecated, remove
14
+
15
+ # active record attribute related
16
+ require 'platanus/tag_set'
8
17
  require 'platanus/enum'
9
- require 'platanus/http_helpers'
10
18
  require 'platanus/model_shims'
19
+ # require 'platanus/onetime' # TODO: deprecated, remove
20
+
21
+ # boilerplate
22
+ require 'platanus/http_helpers' # TODO: deprecate in favor of api_boilerplate => first improve boilerplate
11
23
 
12
- # require 'platanus/onetime'
13
24
  # require 'platanus/gcontroller'
25
+
26
+ # Template engines connectors
14
27
  # require 'platanus/template/spreadsheet'
15
28
  # require 'platanus/template/prawn'
16
29
 
17
- require 'platanus/serializers/json_sym'
18
-
19
30
  module Platanus
20
31
  # Your code goes here...
21
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: platanus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
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: 2013-04-18 00:00:00.000000000 Z
12
+ date: 2013-07-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_json
@@ -68,8 +68,10 @@ files:
68
68
  - lib/platanus/model_shims.rb
69
69
  - lib/platanus/onetime.rb
70
70
  - lib/platanus/serializers/json_sym.rb
71
+ - lib/platanus/serializers/tag_set.rb
71
72
  - lib/platanus/stacked.rb
72
73
  - lib/platanus/stacked2.rb
74
+ - lib/platanus/tag_set.rb
73
75
  - lib/platanus/templates/prawn.rb
74
76
  - lib/platanus/templates/spreadsheet.rb
75
77
  - lib/platanus/traceable.rb