tweet_validator 0.0.1.beta1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cfaffe1b3280b525266cd7248b39dc4833d0048f
4
+ data.tar.gz: 1c7ee20c219e1d3cc52354b36362e5ec885326cb
5
+ SHA512:
6
+ metadata.gz: 1d512477379974b4b6e29c01361a9a614274b637bfa9d2eb7a050d4ba4052f41584df2859820bdfbe3edac7813b67d2dec7644cc6981d543ada718eafcbf7cad
7
+ data.tar.gz: 5f33d9113b8b71a1b34ef02104ae7f9d443b30c1ebe5bcf3f76f0c40c997796f90ebbcd6629da71097d5623f847a17852ebc227c465549c73809bb652a464e1c
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: VWVbgT4ROD8NRNIx63lwDPUVThGccAdf3
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.hound.yml ADDED
@@ -0,0 +1,27 @@
1
+ Style/LineLength:
2
+ Description: 'Limit lines to 130 characters.'
3
+ Max: 130
4
+ Style/SpaceInsideParens:
5
+ Enabled: false
6
+ Style/SpaceBeforeBlockBraces:
7
+ Enabled: false
8
+ StringLiterals:
9
+ Enabled: false
10
+ Style/TrailingComma:
11
+ Enabled: false
12
+ Style/BlockComments:
13
+ Enabled: false
14
+ Style/NilComparison:
15
+ Enabled: false
16
+ Style/Documentation:
17
+ Enabled: false
18
+ Style/RegexpLiteral:
19
+ Enabled: false
20
+ Style/SignalException:
21
+ Enabled: false
22
+ Style/CaseEquality:
23
+ Enabled: false
24
+ Style/SpaceBeforeComma:
25
+ Enabled: false
26
+ Style/SpaceInsideBlockBraces:
27
+ EnforcedStyle: space
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,23 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2
6
+ - ruby-head
7
+ bundler_args: "--jobs=2"
8
+ before_script:
9
+ - export CODECLIMATE_REPO_TOKEN=61b7ac90a58416aff0da12650d731dbdae34c38f806601899e9df3f5883bfedc
10
+ - export COVERAGE=true
11
+ script:
12
+ - bundle exec rspec
13
+ branches:
14
+ only:
15
+ - master
16
+ notifications:
17
+ email: false
18
+ slack:
19
+ secure: ZVIAWIIVaTjj1m4CVUtCj8WZH6HlGvkceKIGbyMOYaSDBAF+2veKrfUMfTeiTiQqveV3dXFjfnHSuP6zV3X1qIT2MrFb+MsDF7uKOMY4xUL+4mtk72sZ1jCdgg5LoBtNz/ueDGI6wIR14q1Z+L9JIlgXSiXKZfoSJj6b71JCAKM=
20
+ matrix:
21
+ allow_failures:
22
+ - rvm: 2.2
23
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tweet_validator.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 sueyoshi_go
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # TweetValidator
2
+
3
+ tweet length check validator
4
+
5
+ [![Build Status](https://travis-ci.org/sue445/tweet_validator.png?branch=master)](https://travis-ci.org/sue445/tweet_validator)
6
+ [![Dependency Status](https://gemnasium.com/sue445/tweet_validator.svg)](https://gemnasium.com/sue445/tweet_validator)
7
+ [![Code Climate](https://codeclimate.com/github/sue445/tweet_validator/badges/gpa.svg)](https://codeclimate.com/github/sue445/tweet_validator)
8
+ [![Coverage Status](https://img.shields.io/coveralls/sue445/tweet_validator.svg)](https://coveralls.io/r/sue445/tweet_validator)
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'tweet_validator'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install tweet_validator
25
+
26
+ ## Usage
27
+
28
+ TODO: Write usage instructions here
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/sue445/tweet_validator/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,6 @@
1
+ require "tweet_validator/version"
2
+ require "tweet_validator/tweet_length_validator"
3
+
4
+ module TweetValidator
5
+ # Your code goes here...
6
+ end
@@ -0,0 +1,23 @@
1
+ module TweetValidator
2
+ require "active_model"
3
+
4
+ class TweetLengthValidator < ActiveModel::EachValidator
5
+ TWEET_MAX_LENGTH = 140
6
+
7
+ def validate_each(record, attribute, value)
8
+ record.errors.add(attribute, :invalid_tweet) unless TweetLengthValidator.valid_tweet?(value)
9
+ end
10
+
11
+ def self.valid_tweet?(tweet)
12
+ return false unless tweet
13
+ return false if tweet.empty?
14
+ return false unless sanitize(tweet).length <= TWEET_MAX_LENGTH
15
+
16
+ true
17
+ end
18
+
19
+ def self.sanitize(tweet)
20
+ tweet.gsub(/%<.+?>/, "").gsub(/%{.+?}/, "")
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ module TweetValidator
2
+ VERSION = "0.0.1.beta1"
3
+ end
@@ -0,0 +1,107 @@
1
+ if ENV["COVERAGE"]
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+ require 'codeclimate-test-reporter'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ CodeClimate::TestReporter::Formatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ SimpleCov.start
11
+ end
12
+
13
+
14
+ require "tweet_validator"
15
+ require "rspec-parameterized"
16
+
17
+ # This file was generated by the `rspec --init` command. Conventionally, all
18
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
19
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
20
+ # file to always be loaded, without a need to explicitly require it in any files.
21
+ #
22
+ # Given that it is always loaded, you are encouraged to keep this file as
23
+ # light-weight as possible. Requiring heavyweight dependencies from this file
24
+ # will add to the boot time of your test suite on EVERY test run, even for an
25
+ # individual file that may not need all of that loaded. Instead, consider making
26
+ # a separate helper file that requires the additional dependencies and performs
27
+ # the additional setup, and require it from the spec files that actually need it.
28
+ #
29
+ # The `.rspec` file also contains a few flags that are not defaults but that
30
+ # users commonly want.
31
+ #
32
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
33
+ RSpec.configure do |config|
34
+ # rspec-expectations config goes here. You can use an alternate
35
+ # assertion/expectation library such as wrong or the stdlib/minitest
36
+ # assertions if you prefer.
37
+ config.expect_with :rspec do |expectations|
38
+ # This option will default to `true` in RSpec 4. It makes the `description`
39
+ # and `failure_message` of custom matchers include text for helper methods
40
+ # defined using `chain`, e.g.:
41
+ # be_bigger_than(2).and_smaller_than(4).description
42
+ # # => "be bigger than 2 and smaller than 4"
43
+ # ...rather than:
44
+ # # => "be bigger than 2"
45
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
46
+ end
47
+
48
+ # rspec-mocks config goes here. You can use an alternate test double
49
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
50
+ config.mock_with :rspec do |mocks|
51
+ # Prevents you from mocking or stubbing a method that does not exist on
52
+ # a real object. This is generally recommended, and will default to
53
+ # `true` in RSpec 4.
54
+ mocks.verify_partial_doubles = true
55
+ end
56
+
57
+ # The settings below are suggested to provide a good initial experience
58
+ # with RSpec, but feel free to customize to your heart's content.
59
+ =begin
60
+ # These two settings work together to allow you to limit a spec run
61
+ # to individual examples or groups you care about by tagging them with
62
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
63
+ # get run.
64
+ config.filter_run :focus
65
+ config.run_all_when_everything_filtered = true
66
+
67
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
68
+ # For more details, see:
69
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
70
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
71
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
72
+ config.disable_monkey_patching!
73
+
74
+ # This setting enables warnings. It's recommended, but in some cases may
75
+ # be too noisy due to issues in dependencies.
76
+ config.warnings = true
77
+
78
+ # Many RSpec users commonly either run the entire suite or an individual
79
+ # file, and it's useful to allow more verbose output when running an
80
+ # individual spec file.
81
+ if config.files_to_run.one?
82
+ # Use the documentation formatter for detailed output,
83
+ # unless a formatter has already been configured
84
+ # (e.g. via a command-line flag).
85
+ config.default_formatter = 'doc'
86
+ end
87
+
88
+ # Print the 10 slowest examples and example groups at the
89
+ # end of the spec run, to help surface which specs are running
90
+ # particularly slow.
91
+ config.profile_examples = 10
92
+
93
+ # Run specs in random order to surface order dependencies. If you find an
94
+ # order dependency and want to debug it, you can fix the order by providing
95
+ # the seed, which is printed after each run.
96
+ # --seed 1234
97
+ config.order = :random
98
+
99
+ # Seed global randomization in this process using the `--seed` CLI option.
100
+ # Setting this allows you to use `--seed` to deterministically reproduce
101
+ # test failures related to randomization by passing the same `--seed` value
102
+ # as the one that triggered the failure.
103
+ Kernel.srand config.seed
104
+ =end
105
+
106
+ config.order = :random
107
+ end
@@ -0,0 +1,65 @@
1
+ describe TweetValidator::TweetLengthValidator do
2
+ let(:model_class) do
3
+ Struct.new(:message_template) do
4
+ include ActiveModel::Validations
5
+ include TweetValidator
6
+
7
+ def self.name
8
+ 'Tweet'
9
+ end
10
+
11
+ validates :message_template, tweet_length: true
12
+ end
13
+ end
14
+
15
+ describe "#validate" do
16
+ subject{ model_class.new(message_template) }
17
+
18
+ context "with valid tweet" do
19
+ where(:message_template) do
20
+ [
21
+ ["a"],
22
+ ["a" * 130 + "%<this_is_variable>"],
23
+ ["a" * 130 + "%{this_is_variable}"],
24
+ ]
25
+ end
26
+
27
+ with_them do
28
+ it { should be_valid }
29
+ end
30
+ end
31
+
32
+ context "with invalid tweet" do
33
+ where(:message_template) do
34
+ [
35
+ [nil ],
36
+ ["" ],
37
+ ["a" * 141],
38
+ ]
39
+ end
40
+
41
+ with_them do
42
+ it { should_not be_valid }
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ describe "#sanitize" do
49
+ subject{ TweetValidator::TweetLengthValidator.sanitize(tweet) }
50
+
51
+ where(:tweet, :expected) do
52
+ [
53
+ ["foo" , "foo"],
54
+ ["foo%<hoge>", "foo"],
55
+ ["foo%{hoge}", "foo"],
56
+ ["foo%{hoge}bar%{hoe}", "foobar"],
57
+ ]
58
+ end
59
+
60
+ with_them do
61
+ it { should eq expected }
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tweet_validator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tweet_validator"
8
+ spec.version = TweetValidator::VERSION
9
+ spec.authors = ["sueyoshi_go"]
10
+ spec.email = ["go.sueyoshi@drecom.co.jp"]
11
+ spec.summary = %q{tweet length check validator}
12
+ spec.description = %q{tweet length check validator}
13
+ spec.homepage = "https://github.com/sue445/tweet_validator"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activemodel"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "codeclimate-test-reporter"
25
+ spec.add_development_dependency "coveralls"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec", "~> 3.1.0"
28
+ spec.add_development_dependency "rspec-parameterized"
29
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tweet_validator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.beta1
5
+ platform: ruby
6
+ authors:
7
+ - sueyoshi_go
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codeclimate-test-reporter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec-parameterized
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: tweet length check validator
112
+ email:
113
+ - go.sueyoshi@drecom.co.jp
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".coveralls.yml"
119
+ - ".gitignore"
120
+ - ".hound.yml"
121
+ - ".rspec"
122
+ - ".travis.yml"
123
+ - Gemfile
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - lib/tweet_validator.rb
128
+ - lib/tweet_validator/tweet_length_validator.rb
129
+ - lib/tweet_validator/version.rb
130
+ - spec/spec_helper.rb
131
+ - spec/tweet_validator/tweet_length_validator_spec.rb
132
+ - tweet_validator.gemspec
133
+ homepage: https://github.com/sue445/tweet_validator
134
+ licenses:
135
+ - MIT
136
+ metadata: {}
137
+ post_install_message:
138
+ rdoc_options: []
139
+ require_paths:
140
+ - lib
141
+ required_ruby_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">"
149
+ - !ruby/object:Gem::Version
150
+ version: 1.3.1
151
+ requirements: []
152
+ rubyforge_project:
153
+ rubygems_version: 2.2.2
154
+ signing_key:
155
+ specification_version: 4
156
+ summary: tweet length check validator
157
+ test_files:
158
+ - spec/spec_helper.rb
159
+ - spec/tweet_validator/tweet_length_validator_spec.rb