ar_condition 0.0.1

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.
@@ -0,0 +1,37 @@
1
+ # Class for create condition from Array
2
+ class ARCondition
3
+
4
+ # Returns Array
5
+ attr_reader :conditions
6
+ attr_writer :operator
7
+
8
+ def initialize(condition=nil, operator='AND')
9
+ @conditions = []
10
+ @operator = operator
11
+ add(condition) if condition
12
+ end
13
+
14
+ def add(condition)
15
+ if condition.is_a?(Array)
16
+ if @conditions.size > 0
17
+ @conditions.first << " #{@operator} (#{condition.first}) "
18
+ else
19
+ @conditions << " (#{condition.first}) "
20
+ end
21
+ @conditions += condition[1..-1]
22
+ elsif condition.is_a?(String)
23
+ if @conditions.size > 0
24
+ @conditions.first << " #{@operator} (#{condition})"
25
+ else
26
+ @conditions << " (#{condition})"
27
+ end
28
+ else
29
+ raise "Unsupported #{condition.class} condition: #{condition}"
30
+ end
31
+ self
32
+ end
33
+
34
+ def <<(condition)
35
+ add(condition)
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module ArCondition
3
+ VERSION = '0.0.1'
4
+ end
@@ -0,0 +1,2 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'ar_condition/ar_condition'
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ar_condition
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Belorusov Dmitriy
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-16 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 3.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ description: The SQL Condition builder for ActiveRecord Ruby on Rails.
31
+ email:
32
+ - Develby@gmail.com
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/ar_condition.rb
38
+ - lib/ar_condition/ar_condition.rb
39
+ - lib/ar_condition/version.rb
40
+ homepage: http://worldalias.com
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.19
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: The SQL Condition builder for ActiveRecord Ruby on Rails.
64
+ test_files: []