stringex 2.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzM4MDQ5OGJlOWM2Mzk0NGIxZmYxZDAxYWQ3MDYxYzQyN2VhMGQ5Nw==
4
+ Mjk4ZWZjOTA4ODlmMDVmOWQ0YzFkNTc4ZWRiNTkzMzY5MTU3OTVkNA==
5
5
  data.tar.gz: !binary |-
6
- YzcxYjcxMDEyZjZjNmVjZmI0YmU4NDFjZWViNzU4ODRmNDljZTQ0Mg==
6
+ YzcwNWY5M2YxYWY3OTZiMDJkOTIyMGM2MDVkNjRkOTU4Y2FjNmU2NQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODRkZWIxMzdmMzkyYjMwZDU5MjNjNzc2Y2YzYzJjOGEwNzIxZGUyMDA3MjIz
10
- NGI4NjBjNzBhZjIxMWRjMWJiOTIyMzJhMThmOGFjYjlhZGFkYmQwY2I4MGJm
11
- YzA2OTExNmExNzdiNWZmNzgwMGU1NTgyYTJiMzM4MTQzMjFlM2E=
9
+ NzVkMGNjNTVjMWY1NTk3YTdkYjRkNzdkNjg1Y2U0ZWRkOTJhZDZiYjliZmYx
10
+ MGU5YTAwZDVkOTIwMWY4NDZjMWQxYzZiMDEwMDY0NDg3ZGI0NmMyMjg4YjE5
11
+ ZjE3M2Y0MWU5OTJlYzMwMDY4ZmFmMGNiMTIzM2QxOGVlNDlkMzM=
12
12
  data.tar.gz: !binary |-
13
- MTc2YmNkNWUzNGVjOWQzMDIzNTQwYjNlZDhkODExMWE4ZTk2Mjc1OWJmZjRh
14
- NzhhMjJjODAxZmQwZGRlNDhjZjI4NzNlOTU0YzkzZjQyNGU0NjJmZmE0MTQy
15
- ZjhjNWNhYmUwM2EyZmNlYWExZjY4ZTNjOTU2ZDkyZjliYTgwOGI=
13
+ YzI1YzdjMWMwOGE2OGQ2MWExNzZhYWFmNjVmZTFkOTg1NmI3NTQyMzEzNGIz
14
+ NmU1ZGM4YmQ4YjZiZDRjZGE0Mzg0OGIxMDUyOTgwOGEyZjEzZGRlOThkNGU1
15
+ YjYzNmUxMzJkNDFiNDUwZDZjM2Q4YmQwOGYzMzA1OTlkYTZiNTA=
@@ -27,7 +27,6 @@ which will populate the <tt>url</tt> attribute on the object with the converted
27
27
  be guaranteed to lookup the expected record based on a duplicate slug.</em>
28
28
  <tt>:limit</tt>:: If set, will limit length of url generated. Default is nil.
29
29
 
30
-
31
30
  In order to use the generated url attribute, you will probably want to override <tt>to_param</tt> like so, in your Model:
32
31
 
33
32
  # Inside your model
@@ -37,7 +36,7 @@ In order to use the generated url attribute, you will probably want to override
37
36
 
38
37
  Routing called via named routes like <tt>foo_path(@foo)</tt> will automatically use the url. In your controllers you will need to call <tt>Foo.find_by_url(params[:id])</tt> instead of the regular find. Don't look for <tt>params[:url]</tt> unless you set it explicitly in the routing, <tt>to_param</tt> will generate <tt>params[:id]</tt>.
39
38
 
40
- Note that if you add <tt>acts_as_url</tt> to an old model, the <tt>url</tt> database column will inititally be blank. To set this column for your old instances, you can use the <tt>initialize_urls</tt> method. So if your class is <tt>Post</tt>, just say <tt>Post.initialize_urls</tt>.
39
+ Note that if you add <tt>acts_as_url</tt> to an existing model, the <tt>url</tt> database column will initially be blank. To set this column for your existing instances, you can use the <tt>initialize_urls</tt> method. So if your class is <tt>Post</tt>, just say <tt>Post.initialize_urls</tt>.
41
40
 
42
41
  Unlike other permalink solutions, ActsAsUrl doesn't rely on Iconv (which is inconsistent across platforms and doesn't provide great transliteration as is) but instead uses a transliteration scheme (see the code for Unidecoder) which produces much better results for Unicode characters. It also mixes in some custom helpers to translate common characters into a more URI-friendly format rather than just dump them completely. Examples:
43
42
 
@@ -90,17 +89,17 @@ In both the YAML and pure Hash implementation, the end result should be a Hash w
90
89
 
91
90
  == StringExtensions
92
91
 
93
- A collection of extensions on Ruby's String class. Please see the documentation for StringExtensions module for more information. There's not much to explain about them really.
92
+ A small collection of extensions on Ruby's String class. Please see the documentation for StringExtensions module for more information. There's not much to explain about them really.
94
93
 
95
94
  == Localization
96
95
 
97
- With Stringex version 2.0 and higher, you can localize the different conversions in Stringex. Read more here[https://github.com/rsl/stringex/wiki/Localization-of-Stringex-conversions]
96
+ With Stringex version 2.0 and higher, you can localize the different conversions in Stringex. Read more here[https://github.com/rsl/stringex/wiki/Localization-of-Stringex-conversions]. If you add a new language, please submit a pull request so we can make it available to other users also.
98
97
 
99
98
  == Using with Rails
100
99
 
101
100
  When using Stringex with Ruby on Rails, you automatically get built-in translations for miscellaneous characters, HTML entities, and vulgar fractions.
102
101
 
103
- You can see Stringex's standard translations here: TODO: Insert link to the +locales+ folder.
102
+ You can see Stringex's standard translations here[https://github.com/rsl/stringex/tree/master/locales].
104
103
 
105
104
  Currently, built-in translations are available for the following languages:
106
105
  English (en), Danish (da)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
@@ -56,14 +56,15 @@ module Stringex
56
56
 
57
57
  def add_new_record_url_owner_conditions
58
58
  return if is_new?(instance)
59
- @url_owner_conditions.first << " and #{instance.class.primary_key} != ?"
59
+ @url_owner_conditions.first << " and #{primary_key} != ?"
60
60
  @url_owner_conditions << instance.id
61
61
  end
62
62
 
63
63
  def add_scoped_url_owner_conditions
64
- return unless settings.scope_for_url
65
- @url_owner_conditions.first << " and #{settings.scope_for_url} = ?"
66
- @url_owner_conditions << instance.send(settings.scope_for_url)
64
+ [settings.scope_for_url].flatten.compact.each do |scope|
65
+ @url_owner_conditions.first << " and #{scope} = ?"
66
+ @url_owner_conditions << instance.send(scope)
67
+ end
67
68
  end
68
69
 
69
70
  def create_callback
@@ -145,6 +146,10 @@ module Stringex
145
146
  self.class.orm_class
146
147
  end
147
148
 
149
+ def primary_key
150
+ instance.class.primary_key
151
+ end
152
+
148
153
  def read_attribute(instance, attribute)
149
154
  instance.read_attribute attribute
150
155
  end
@@ -42,6 +42,10 @@ module Stringex
42
42
  klass.all(:conditions => {settings.url_attribute => nil}).each(&block)
43
43
  end
44
44
 
45
+ def primary_key
46
+ instance.class.key.first.instance_variable_get '@name'
47
+ end
48
+
45
49
  def read_attribute(instance, attribute)
46
50
  instance.attributes[attribute]
47
51
  end
@@ -15,8 +15,9 @@ module Stringex
15
15
  end
16
16
 
17
17
  def add_scoped_url_owner_conditions
18
- return unless settings.scope_for_url
19
- @url_owner_conditions.merge! settings.scope_for_url => instance.send(settings.scope_for_url)
18
+ [settings.scope_for_url].flatten.compact.each do |scope|
19
+ @url_owner_conditions.merge! scope => instance.send(scope)
20
+ end
20
21
  end
21
22
 
22
23
  def get_base_url_owner_conditions
@@ -1,10 +1,12 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require 'yaml'
4
+
3
5
  module Stringex
4
6
  module Unidecoder
5
7
  # Contains Unicode codepoints, loading as needed from YAML files
6
8
  CODEPOINTS = Hash.new{|h, k|
7
- h[k] = YAML.load_file(File.join(File.expand_path(File.dirname(__FILE__)), "unidecoder_data", "#{k}.yml"))
9
+ h[k] = ::YAML.load_file(File.join(File.expand_path(File.dirname(__FILE__)), "unidecoder_data", "#{k}.yml"))
8
10
  } unless defined?(CODEPOINTS)
9
11
 
10
12
  class << self
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "stringex"
8
- s.version = "2.0.1"
8
+ s.version = "2.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Russell Norris"]
@@ -14,11 +14,11 @@ ActiveRecord::Base.establish_connection :adapter => "sqlite3", :database => ":me
14
14
  ActiveRecord::Migration.verbose = false
15
15
  ActiveRecord::Schema.define do
16
16
  create_table :documents, :force => true do |t|
17
- t.string :title, :other, :url
17
+ t.string :title, :other, :another, :url
18
18
  end
19
19
 
20
20
  create_table :sti_base_documents, :force => true do |t|
21
- t.string :title, :other, :url, :type
21
+ t.string :title, :other, :another, :url, :type
22
22
  end
23
23
  end
24
24
  ActiveRecord::Migration.verbose = true
@@ -22,21 +22,23 @@ DataMapper.setup :default, 'sqlite::memory:'
22
22
  DefineTestClasses = proc do
23
23
  class Document
24
24
  include DataMapper::Resource
25
- property :id, Serial
26
- property :title, String
27
- property :other, String
28
- property :url, String, :lazy => false
25
+ property :id, Serial
26
+ property :title, String
27
+ property :other, String
28
+ property :another, String
29
+ property :url, String, :lazy => false
29
30
 
30
31
  acts_as_url :title
31
32
  end
32
33
 
33
34
  class STIBaseDocument
34
35
  include DataMapper::Resource
35
- property :id, Serial
36
- property :title, String
37
- property :other, String
38
- property :url, String, :lazy => false
39
- property :type, String
36
+ property :id, Serial
37
+ property :title, String
38
+ property :other, String
39
+ property :another, String
40
+ property :url, String, :lazy => false
41
+ property :type, String
40
42
 
41
43
  # This gets redefined in the only test that uses it but I want to be uniform
42
44
  # in setting configuration details in the tests themselves
@@ -15,19 +15,21 @@ end
15
15
 
16
16
  class Document
17
17
  include Mongoid::Document
18
- field :title, :type => String
19
- field :other, :type => String
20
- field :url, :type => String
18
+ field :title, :type => String
19
+ field :other, :type => String
20
+ field :another, :type => String
21
+ field :url, :type => String
21
22
 
22
23
  acts_as_url :title
23
24
  end
24
25
 
25
26
  class STIBaseDocument
26
27
  include Mongoid::Document
27
- field :title, :type => String
28
- field :other, :type => String
29
- field :url, :type => String
30
- field :type, :type => String
28
+ field :title, :type => String
29
+ field :other, :type => String
30
+ field :another, :type => String
31
+ field :url, :type => String
32
+ field :type, :type => String
31
33
 
32
34
  # This gets redefined in the only test that uses it but I want to be uniform
33
35
  # in setting configuration details in the tests themselves
@@ -89,6 +89,29 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
89
89
  assert_not_equal @doc.url, @other_doc.url
90
90
  end
91
91
 
92
+ def test_should_allow_multiple_scopes
93
+ Document.class_eval do
94
+ acts_as_url :title, :scope => [:other, :another]
95
+ end
96
+
97
+ @doc = Document.create(:title => "Mocumentary", :other => "I don't care if I'm unique for some reason",
98
+ :another => "Whatever")
99
+ @other_doc = Document.create(:title => "Mocumentary", :other => "Me either", :another => "Whatever")
100
+ assert_equal @doc.url, @other_doc.url
101
+ end
102
+
103
+ def test_should_only_create_unique_urls_for_multiple_scopes_if_both_attributes_are_same
104
+ Document.class_eval do
105
+ acts_as_url :title, :scope => [:other, :another]
106
+ end
107
+
108
+ @doc = Document.create(:title => "Mocumentary", :other => "Suddenly, I care if I'm unique",
109
+ :another => "Whatever")
110
+ @other_doc = Document.create(:title => "Mocumentary", :other => "Suddenly, I care if I'm unique",
111
+ :another => "Whatever")
112
+ assert_not_equal @doc.url, @other_doc.url
113
+ end
114
+
92
115
  def test_should_allow_setting_url_attribute
93
116
  Document.class_eval do
94
117
  # Manually undefining the url method on Document which, in a real class not reused for tests,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Russell Norris