semantic_attributes 1.0.4 → 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f61914c744a168e768b8f1758b4a5105450c876
4
- data.tar.gz: 4661dc4b0819fec9ba75f705cecf07693cebb766
3
+ metadata.gz: 171c2270aa742ab42f199d4898db3fff22a74391
4
+ data.tar.gz: 3c11f86efec71c907a53df0f7122ee34dfafcfd9
5
5
  SHA512:
6
- metadata.gz: 42ff158e847d45e25336f827f77b248357cee54cdfb849ccc6060a5c4d6e0ff37ceab40e8785062e0f01332257b4a451e3a275b4b014481036f5ed120d004833
7
- data.tar.gz: fe5f47dff95a3758c3a4a27988fff87221e6894a23187480ec02fc5dc7fc9d1bec496b6149f06998e95c69cd6a82263c0b06994039ac780c2345be74419a9b08
6
+ metadata.gz: abdf4b7ff9e57fec950ba63f24eb243470edc915bc1d4e538fb99caa8a18b67d33c5dd1ef8cd53ff7439fb06c42bd389936ffda75c459f51e77ff9d13b0d5b0e
7
+ data.tar.gz: e5697b5751cabbcb2f7b3ff572b624ba88cb0dccaab55a96e99cd5d460d11d53460c17198315f5fed856784a129ca003957d9ae8badf9bef2c8fc8e9971d8b7a
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source :rubygems
2
-
3
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Rakefile CHANGED
@@ -1,37 +1,10 @@
1
- #!/usr/bin/env rake
2
- begin
3
- require 'bundler/setup'
4
- rescue LoadError
5
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
- end
7
- require 'rake/testtask'
8
- begin
9
- require 'rdoc/task'
10
- rescue LoadError
11
- require 'rdoc/rdoc'
12
- require 'rake/rdoctask'
13
- RDoc::Task = Rake::RDocTask
14
- end
15
-
16
- desc 'Default: run unit tests.'
17
- task :default => :test
18
-
19
- desc 'Test the SemanticAttributes plugin.'
20
- Rake::TestTask.new(:test) do |t|
21
- t.libs << 'lib'
22
- t.pattern = 'test/unit/**/*_test.rb'
23
- t.verbose = true
24
- end
25
-
26
- desc 'Generate documentation for the SemanticAttributes plugin.'
27
- RDoc::Task.new(:rdoc) do |rdoc|
28
- rdoc.rdoc_dir = 'rdoc'
29
- rdoc.title = 'SemanticAttributes'
30
- rdoc.options << '--line-numbers' << '--inline-source'
31
- rdoc.rdoc_files.include('README')
32
- rdoc.rdoc_files.include('gist.rdoc')
33
- rdoc.rdoc_files.include('lib/**/*.rb')
34
- end
35
-
36
- Bundler::GemHelper.install_tasks
37
-
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/**/*test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -7,7 +7,7 @@ require 'uri'
7
7
  # :schemes [array, default ['http', 'https']] - a whitelist of allowed schemes. set to nil to allow all schemes.
8
8
  # :ports [array, default nil] - a whitelist of allowed ports. set to nil to allow all ports.
9
9
  # :allow_ip_address [boolean, default true] - whether to allow ip addresses instead to domain names.
10
- # :implied_scheme [string, symbol, default 'http'] - what scheme to assume if non is present.
10
+ # :implied_scheme [string, symbol, default 'http'] - what scheme to assume if none is present.
11
11
  #
12
12
  # ==Examples
13
13
  # # if you need an ftp url
@@ -10,28 +10,6 @@ module SemanticAttributes #:nodoc:
10
10
  base.extend ClassMethods
11
11
  end
12
12
 
13
- def respond_to?(method_name, *args)
14
- if md = method_name.to_s.match(/_for_human$/) and semantic_attributes.include?(md.pre_match)
15
- true
16
- else
17
- super
18
- end
19
- end
20
-
21
- protected
22
-
23
- def method_missing(method_name, *args, &block)
24
- if md = method_name.to_s.match(/_for_human$/) and semantic_attributes.include?(md.pre_match)
25
- self.class.humanize(md.pre_match, self.send(md.pre_match))
26
- else
27
- begin
28
- super
29
- rescue
30
- raise $!, $!.to_s, caller
31
- end
32
- end
33
- end
34
-
35
13
  module ClassMethods
36
14
  # converts the object into human format according to the predicates for the attribute.
37
15
  # the object may really be anything: string, integer, date, etc.
@@ -47,14 +25,15 @@ module SemanticAttributes #:nodoc:
47
25
 
48
26
  protected
49
27
 
50
- def define_normalization_method_for(attr)
51
- if Gem::Version.new(::ActiveRecord::VERSION::STRING) >= Gem::Version.new("4.0.4")
52
- # Changes from Rails 4.0.4: https://github.com/rails/rails/commit/714634ad02b443ab51f8ef3ded324de411715d2a
53
- self.define_attribute_methods if !@attribute_methods_generated
54
- else
55
- self.define_attribute_methods if self.respond_to? :attribute_methods_generated? and !self.attribute_methods_generated?
28
+ def define_humanization_method_for(attr)
29
+ ensure_attribute_methods_defined
30
+ define_method "#{attr}_for_human" do
31
+ self.class.humanize(attr, send(attr))
56
32
  end
33
+ end
57
34
 
35
+ def define_normalization_method_for(attr)
36
+ ensure_attribute_methods_defined
58
37
  writer = "#{attr}_with_normalization="
59
38
  old_writer = "#{attr}_without_normalization=".to_sym
60
39
  unless method_defined? writer
@@ -67,6 +46,14 @@ module SemanticAttributes #:nodoc:
67
46
  raise SemanticAttributes::MissingAttribute.new(attr)
68
47
  end
69
48
 
49
+ def ensure_attribute_methods_defined
50
+ if Gem::Version.new(::ActiveRecord::VERSION::STRING) >= Gem::Version.new("4.0.4")
51
+ # Changes from Rails 4.0.4: https://github.com/rails/rails/commit/714634ad02b443ab51f8ef3ded324de411715d2a
52
+ self.define_attribute_methods if !@attribute_methods_generated
53
+ else
54
+ self.define_attribute_methods if self.respond_to? :attribute_methods_generated? and !self.attribute_methods_generated?
55
+ end
56
+ end
70
57
  end
71
58
  end
72
59
  end
@@ -128,6 +128,7 @@ module SemanticAttributes
128
128
  args << options if options
129
129
  fields.each do |field|
130
130
  # TODO: create a less sugary method that may be used programmatically and takes care of defining the normalization method properly
131
+ define_humanization_method_for field
131
132
  define_normalization_method_for field
132
133
  self.semantic_attributes[field].add *args
133
134
  end
@@ -1,3 +1,3 @@
1
- module SemanticAttributes
2
- VERSION = "1.0.4"
3
- end
1
+ module SemanticAttributes
2
+ VERSION = "1.0.5"
3
+ end
@@ -1,67 +1,67 @@
1
- ENV["RAILS_ENV"] = "test"
2
-
3
- # load the support libraries
4
- require 'test/unit'
5
- require 'rubygems'
6
- require 'active_record'
7
- require 'active_record/fixtures'
8
- require 'active_support/time'
9
-
10
- # load the code-to-be-tested
11
- require 'semantic_attributes'
12
-
13
- Time.zone = 'UTC'
14
-
15
- # establish the database connection
16
- ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/db/database.yml'))
17
- ActiveRecord::Base.establish_connection('semantic_attributes_test')
18
-
19
- # capture the logging
20
- ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/test.log")
21
-
22
- # load the schema ... silently
23
- ActiveRecord::Migration.verbose = false
24
- load(File.dirname(__FILE__) + "/db/schema.rb")
25
-
26
- # load the ActiveRecord models
27
- require File.dirname(__FILE__) + '/db/models'
28
-
29
- # configure the TestCase settings
30
- class SemanticAttributes::TestCase < ActiveSupport::TestCase
31
- include ActiveRecord::TestFixtures
32
- include PluginTestModels
33
-
34
- self.use_transactional_fixtures = true
35
- self.use_instantiated_fixtures = false
36
- self.fixture_path = File.dirname(__FILE__) + '/fixtures/'
37
-
38
- fixtures :all
39
- end
40
-
41
- class ActiveRecord::Base
42
- # Aids the management of per-test semantics.
43
- #
44
- # Examples:
45
- #
46
- # User.stub_semantics_with(:email => :email)
47
- # User.stub_semantics_with(:email => [:email, :unique])
48
- # User.stub_semantics_with(:email => {:length => {:above => 5}})
49
- # User.stub_semantics_with(:email => [:email, {:length => {:above => 5}}])
50
- def self.stub_semantics_with(attr_predicates = {})
51
- semantics = SemanticAttributes::Set.new
52
- attr_predicates.each do |attr, predicates|
53
- [predicates].flatten.each do |predicate|
54
- case predicate
55
- when String, Symbol
56
- semantics[attr].add(predicate)
57
- when Hash
58
- semantics[attr].add(predicate.keys.first, predicate.values.first)
59
- else
60
- raise '???'
61
- end
62
- end
63
- end
64
-
65
- self.stubs(:semantic_attributes).returns(semantics)
66
- end
67
- end
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ # load the support libraries
4
+ require 'minitest/autorun'
5
+ require 'rubygems'
6
+ require 'active_record'
7
+ require 'active_record/fixtures'
8
+ require 'active_support/time'
9
+
10
+ # load the code-to-be-tested
11
+ require 'semantic_attributes'
12
+
13
+ Time.zone = 'UTC'
14
+
15
+ # establish the database connection
16
+ ActiveRecord::Base.configurations = YAML::load(IO.read(File.dirname(__FILE__) + '/db/database.yml'))
17
+ ActiveRecord::Base.establish_connection(:semantic_attributes_test)
18
+
19
+ # capture the logging
20
+ ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/test.log")
21
+
22
+ # load the schema ... silently
23
+ ActiveRecord::Migration.verbose = false
24
+ load(File.dirname(__FILE__) + "/db/schema.rb")
25
+
26
+ # load the ActiveRecord models
27
+ require File.dirname(__FILE__) + '/db/models'
28
+
29
+ # configure the TestCase settings
30
+ class SemanticAttributes::TestCase < ActiveSupport::TestCase
31
+ include ActiveRecord::TestFixtures
32
+ include PluginTestModels
33
+
34
+ self.use_transactional_fixtures = true
35
+ self.use_instantiated_fixtures = false
36
+ self.fixture_path = File.dirname(__FILE__) + '/fixtures/'
37
+
38
+ fixtures :all
39
+ end
40
+
41
+ class ActiveRecord::Base
42
+ # Aids the management of per-test semantics.
43
+ #
44
+ # Examples:
45
+ #
46
+ # User.stub_semantics_with(:email => :email)
47
+ # User.stub_semantics_with(:email => [:email, :unique])
48
+ # User.stub_semantics_with(:email => {:length => {:above => 5}})
49
+ # User.stub_semantics_with(:email => [:email, {:length => {:above => 5}}])
50
+ def self.stub_semantics_with(attr_predicates = {})
51
+ semantics = SemanticAttributes::Set.new
52
+ attr_predicates.each do |attr, predicates|
53
+ [predicates].flatten.each do |predicate|
54
+ case predicate
55
+ when String, Symbol
56
+ semantics[attr].add(predicate)
57
+ when Hash
58
+ semantics[attr].add(predicate.keys.first, predicate.values.first)
59
+ else
60
+ raise '???'
61
+ end
62
+ end
63
+ end
64
+
65
+ self.stubs(:semantic_attributes).returns(semantics)
66
+ end
67
+ end
metadata CHANGED
@@ -1,83 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: semantic_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lance Ivy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-18 00:00:00.000000000 Z
11
+ date: 2015-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 3.2.13
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.13
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: 1.0.0
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.0.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.8.7
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.8.7
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.10.5
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.10.5
83
83
  description: A validation library for ActiveRecord models that allows introspection
@@ -87,7 +87,7 @@ executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - .gitignore
90
+ - ".gitignore"
91
91
  - Gemfile
92
92
  - MIT-LICENSE
93
93
  - README
@@ -169,12 +169,12 @@ require_paths:
169
169
  - lib
170
170
  required_ruby_version: !ruby/object:Gem::Requirement
171
171
  requirements:
172
- - - '>='
172
+ - - ">="
173
173
  - !ruby/object:Gem::Version
174
174
  version: '0'
175
175
  required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - '>='
177
+ - - ">="
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []