sequenceid 0.0.3 → 0.0.4

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.
data/README.md CHANGED
@@ -20,6 +20,8 @@ SequenceId is a fairly straight forward gem and you need to ensure only ONE cond
20
20
 
21
21
  Back to our original example, if you want invoices to start from 1 for each new company, the Invoice RESOURCE is nested to the Company RESOURCE. The gem will check for the relationhip in the database (Invoice table in this case) and ensure the sequence_num (SequenceId column created in the table) and the parent resource_id are a secondary compound key in the nested resource's table.
22
22
 
23
+ At no point is the sequence_num changed once its assigned since it will serve as one of the columns of the compound secondary key. If you ever do rollback the migration, be *careful* since re-running the migration might result in a different sequence_num if a nested resource is deleted.
24
+
23
25
  SequenceId is compatible with Active Record **3.0**.
24
26
 
25
27
  ## Docs, Info and Support
@@ -36,6 +38,8 @@ SequenceId is compatible with Active Record **3.0**.
36
38
  # add to Gemfile
37
39
  gem "sequenceid"
38
40
 
41
+ bundle install
42
+
39
43
  rails generate sequenceid <parent resource> <nested resource> #eg rails generate sequenceid Company Invoice
40
44
 
41
45
  rake db:migrate
@@ -67,9 +71,11 @@ If you have a bug to report, please include the following information:
67
71
  ## Credits
68
72
 
69
73
  SequenceId was create by Syed Ali @ 7vals
74
+
70
75
  * [7vals](http://www.7vals.com)
71
76
 
72
77
  Special thanks to
78
+
73
79
  * [cancan](https://github.com/ryanb/cancan)
74
80
 
75
81
  * [FriendlyId](https://github.com/norman/friendly_id)
@@ -22,22 +22,22 @@ class SequenceidGenerator < ActiveRecord::Generators::Base
22
22
  @parent_resource=eval parent_resource_s.classify
23
23
  @nested_resource=eval nested_resource_s.classify
24
24
  if((!@parent_resource.ancestors.include?ORM) || (!@nested_resource.ancestors.include?ORM))
25
- puts "both #{parent_resource_s} and #{nested_resource_s} need to be ActiveRecords"
25
+ puts "ERROR: both #{parent_resource_s} and #{nested_resource_s} need to be ActiveRecords"
26
26
  exit
27
27
  end
28
28
 
29
29
  if((!@nested_resource.new.respond_to? parent_resource_s) & (!@nested_resource.new.respond_to? parent_resource_s.pluralize))
30
- puts "#{nested_resource_s} should have an association with #{parent_resource_s} otherwise its not possible to have a unique sequence number to identify #{nested_resource_s} from the url"
30
+ puts "ERROR: #{nested_resource_s} should have an association with #{parent_resource_s} otherwise its not possible to have a unique sequence number to identify #{nested_resource_s} from the url"
31
31
  #TODO need to check for belongs_to relation
32
32
  exit
33
33
  end
34
34
  #if not belongs to
35
35
  if(!@parent_resource.new.respond_to? @nested_resource.to_s.downcase.pluralize)
36
- exit unless yes?("The resource #{nested_resource_s} should have a belongs to association with #{parent_resource_s}, do you still want to continue (risky)?")
36
+ exit unless yes?("ERROR: The resource #{nested_resource_s} should have a belongs to association with #{parent_resource_s}, do you still want to continue (risky)?")
37
37
  end
38
38
 
39
39
  rescue =>e
40
- puts "both #{parent_resource_s} and #{nested_resource_s} need to be ActiveRecords #{e.message}"
40
+ puts "ERROR: both #{parent_resource_s} and #{nested_resource_s} need to be ActiveRecords.\n #{e.message}"
41
41
  exit
42
42
  end
43
43
  end
@@ -47,6 +47,6 @@ class SequenceidGenerator < ActiveRecord::Generators::Base
47
47
  migration_template "migration.rb", "db/migrate/add_sequence_num_to_#{@nested_resource.to_s.downcase.pluralize}"
48
48
  #inject into model class module includeA
49
49
  @model_path ||= File.join("app", "models", "#{@nested_resource.to_s.underscore}.rb")
50
- inject_into_class(@model_path,@nested_resource,"sequenceid '#{@parent_resource.to_s.downcase}','#{@nested_resource.to_s.downcase.pluralize}'\n")
50
+ inject_into_class(@model_path,@nested_resource,"\tsequenceid :#{@parent_resource.to_s.downcase.to_sym} , :#{@nested_resource.to_s.downcase.pluralize.to_sym}\n")
51
51
  end
52
52
  end
@@ -1,41 +1,43 @@
1
1
  module Sequenceid
2
2
  module Logic
3
3
 
4
- def sequenceid(parent_rel,current_rel)
5
- #TODO:need to ensure multiple before_saves are not added - possibly use respond_to?
4
+ def sequenceid(parent_rel_sym,current_rel_sym)
5
+ @parent_rel=parent_rel_sym.to_s
6
+ @current_rel=current_rel_sym.to_s
7
+
6
8
  class_eval do
7
- before_create :set_sequence_num
8
- after_rollback :reset_sequence_num
9
- include InstanceMethods
9
+ before_create :set_sequence_num
10
+ after_rollback :reset_sequence_num
11
+ include InstanceMethods
12
+
10
13
  end
11
- @relation_for_sequence_string=(parent_rel+"."+current_rel)
12
14
  end
13
15
 
14
16
  module InstanceMethods
15
17
  def to_param
16
- "#{sequence_num}"
18
+ "#{sequence_num}"
17
19
  end
18
20
 
19
21
  protected
20
22
  def set_sequence_num
21
- if new_record?
22
- @relation_sequence=self.send @relation_for_sequence_string
23
- self.sequence_num=@relation_sequence.order("id").last.try(:sequence_num) || 0
24
- self.sequence_num+=1
25
- end
26
- return true
23
+ if new_record?
24
+ @relation_sequence=self.send(self.class.instance_variable_get("@parent_rel")).send(self.class.instance_variable_get("@current_rel"))
25
+ self.sequence_num=@relation_sequence.order("id").last.try(:sequence_num) || 0
26
+ self.sequence_num+=1
27
+ end
28
+ return true
27
29
  end
28
30
 
29
31
  def reset_sequence_num
30
- @save_counter||=1
31
- if new_record? && @save_counter<3
32
- logger.info "SQUENCENUM:: attempt number #{@save_counter} of a max 2"
33
- self.sequence_num=@relation_sequence.order("id").last.try(:sequence_num) +1
34
- @save_counter+=1
35
- save
36
- else
37
- raise
38
- end
32
+ @save_counter||=1
33
+ if new_record? && @save_counter<3
34
+ logger.info "SQUENCENUM:: attempt number #{@save_counter} of a max 2"
35
+ self.sequence_num=@relation_sequence.order("id").last.try(:sequence_num) +1
36
+ @save_counter+=1
37
+ save
38
+ else
39
+ raise
40
+ end
39
41
  end
40
42
  end
41
43
  end
@@ -1,3 +1,3 @@
1
1
  module Sequenceid
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequenceid
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Syed Ali
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-31 00:00:00 Z
18
+ date: 2011-08-04 00:00:00 +05:00
19
+ default_executable:
19
20
  dependencies: []
20
21
 
21
22
  description: For SaaS applications, there are times when we dont want to show the resource id to the user since its being shared with multiple companies that have signed up. And for scenarios where we want the URL to show numbers and not worded URL's like what friendly_id provide, this is the gem for you! It'll create id's sequentially starting from 1 for each relation parent/nested resource relation definedi\n Feel free to get in touch for any specific questions until the help, support group and readme are not done at info@7vals.com \n http://www.7vals.com
@@ -28,21 +29,18 @@ extensions: []
28
29
  extra_rdoc_files: []
29
30
 
30
31
  files:
31
- - .DS_Store
32
- - .README.swp
33
32
  - .gitignore
34
33
  - Gemfile
35
34
  - README.md
36
35
  - Rakefile
37
- - lib/.DS_Store
38
36
  - lib/generators/sequenceid/sequenceid_generator.rb
39
37
  - lib/generators/sequenceid/template/migration.rb
40
38
  - lib/sequenceid.rb
41
- - lib/sequenceid/.DS_Store
42
39
  - lib/sequenceid/model_adapters/active_record_adapter.rb
43
40
  - lib/sequenceid/model_adapters/sequenceid_logic.rb
44
41
  - lib/sequenceid/version.rb
45
42
  - sequenceid.gemspec
43
+ has_rdoc: true
46
44
  homepage: ""
47
45
  licenses: []
48
46
 
@@ -72,7 +70,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
70
  requirements: []
73
71
 
74
72
  rubyforge_project: sequenceid
75
- rubygems_version: 1.7.2
73
+ rubygems_version: 1.6.2
76
74
  signing_key:
77
75
  specification_version: 3
78
76
  summary: Create resource URL's starting from 1 for each SaaS company
data/.DS_Store DELETED
Binary file
data/.README.swp DELETED
Binary file
data/lib/.DS_Store DELETED
Binary file
Binary file