primary 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.md +1 -0
  2. data/lib/primary.rb +15 -1
  3. data/lib/primary/version.rb +1 -1
  4. metadata +34 -12
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  #Primary
2
+ ![travis-ci](https://secure.travis-ci.org/prograils/primary.png)
2
3
 
3
4
  `primary` is simple gem/plugin that will help you ensure, that you have only one primary / default record in DB. Ie. your site can have multiple languages (stored in db), but only one of them is primary / default.
4
5
 
@@ -31,10 +31,24 @@ module Primary
31
31
  def get_primary_scope(options)
32
32
  check = self.class.where("#{options[:on].to_s} = ?", true)
33
33
  if options[:scope]
34
- check = check.where("#{options[:scope].to_s} = ?", self.send(options[:scope]))
34
+ sc = options[:scope]
35
+ if sc.is_a?(Symbol) or sc.is_a?(String)
36
+ check = build_primary_scope(check, sc)
37
+ elsif sc.is_a?(Array)
38
+ sc.each do |scope_elem|
39
+ check = build_primary_scope(check, scope_elem)
40
+ end
41
+ end
35
42
  end
36
43
  check
37
44
  end
45
+
46
+ def build_primary_scope(scope_chain, elem)
47
+ if elem.is_a?(String)
48
+ elem = elem.to_sym
49
+ end
50
+ scope_chain.where("#{elem} = ?", self.send(elem))
51
+ end
38
52
  end
39
53
  end
40
54
  ActiveRecord::Base.extend Primary
@@ -1,3 +1,3 @@
1
1
  module Primary
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: primary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-21 00:00:00.000000000Z
12
+ date: 2012-07-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70330926958120 !ruby/object:Gem::Requirement
16
+ requirement: &70344345470500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.2.0
21
+ version: 3.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70330926958120
24
+ version_requirements: *70344345470500
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sqlite3
27
- requirement: &70330926957700 !ruby/object:Gem::Requirement
27
+ requirement: &70344345470000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70330926957700
35
+ version_requirements: *70344345470000
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec-rails
38
- requirement: &70330926957240 !ruby/object:Gem::Requirement
38
+ requirement: &70344345469380 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,32 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70330926957240
46
+ version_requirements: *70344345469380
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: factory_girl
49
- requirement: &70330926956820 !ruby/object:Gem::Requirement
49
+ requirement: &70344345468720 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70344345468720
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: &70344345468040 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70344345468040
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &70344345467620 !ruby/object:Gem::Requirement
50
72
  none: false
51
73
  requirements:
52
74
  - - ! '>='
@@ -54,7 +76,7 @@ dependencies:
54
76
  version: '0'
55
77
  type: :development
56
78
  prerelease: false
57
- version_requirements: *70330926956820
79
+ version_requirements: *70344345467620
58
80
  description: This simple gem will help you with keeping default or primary record
59
81
  (one record that is marked as primary) - ie. default domain or language for site
60
82
  email: