stringify_date 0.0.5 → 0.1.0

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
- SHA1:
3
- metadata.gz: 1cd8b5cdd13ef8963c90c44bd1360572dece4aca
4
- data.tar.gz: bf011c635c3c4c3c9254ae4a0294f4c9dde5ba99
2
+ SHA256:
3
+ metadata.gz: 1c36c467d2864024c8942016582d931db2e34ddfa197523ba68b82d7a2aba715
4
+ data.tar.gz: c5e6ba9e0021916dd65abcace40ecd1046e5e6fe7bb4d93c16ac02e184f8166c
5
5
  SHA512:
6
- metadata.gz: f3e2b1a01adbb4d4ebeecdcd965163993d9a6ea19f6d844bf9ac1684e6f4c6f2d02fe3ec2a42e867aa6ea46e1f9d463af2dac3b7426aa709f39f70a86699edff
7
- data.tar.gz: 7e42e6f7b3db793e5802b83ebfe38e90fa294c62cf39921e878d93797767bdab300c0d6cbb650dba1214feb5d1e75d8b5992d372eec6eac07719262f4fa921a4
6
+ metadata.gz: a4b75ce0c58dd86aecb76d6de4ada3f2070a8fb3e23f2b5a5923ce2ca7e7fd7cd2d937bd8b49abd51465cf9a3ba7fb715e83c3f2c6ddcabea19d9e5eb1945d22
7
+ data.tar.gz: 5d42e66e68cece36b667717f2799dab40edf625132aff24d7e016ab8f4e950cbe6b8d4a52d388373de1b70cbe302e2a5bffeaee2b0b5fc9d99b7b944fed46a0a
@@ -1,8 +1,13 @@
1
1
  language: ruby
2
2
  script:
3
- - 'rake spec'
3
+ - 'bundle exec rspec'
4
4
 
5
5
  rvm:
6
- - 1.9.3
7
- - 2.0.0
8
- - 2.1.2
6
+ - 2.2
7
+ - 2.3
8
+ - 2.4
9
+ - 2.5
10
+
11
+ before_install:
12
+ - gem update --system
13
+ - gem update bundler
data/Guardfile CHANGED
@@ -1,24 +1,42 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
1
+ guard :rspec, cmd: 'bundle exec rspec' do
2
+ require 'guard/rspec/dsl'
3
+ dsl = Guard::RSpec::Dsl.new(self)
3
4
 
4
- guard :rspec do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
5
+ # RSpec files
6
+ rspec = dsl.rspec
7
+ watch(rspec.spec_helper) { rspec.spec_dir }
8
+ watch(rspec.spec_support) { rspec.spec_dir }
9
+ watch(rspec.spec_files)
8
10
 
9
- # Rails example
10
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
- watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
- watch('config/routes.rb') { "spec/routing" }
15
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
11
+ # Ruby files
12
+ ruby = dsl.ruby
13
+ dsl.watch_spec_files_for(ruby.lib_files)
14
+
15
+ # Rails files
16
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
17
+ dsl.watch_spec_files_for(rails.app_files)
18
+ dsl.watch_spec_files_for(rails.views)
19
+
20
+ watch(rails.controllers) do |m|
21
+ [
22
+ rspec.spec.call("routing/#{m[1]}_routing"),
23
+ rspec.spec.call("controllers/#{m[1]}_controller"),
24
+ rspec.spec.call("acceptance/#{m[1]}")
25
+ ]
26
+ end
27
+
28
+ # Rails config changes
29
+ watch(rails.spec_helper) { rspec.spec_dir }
30
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
31
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
16
32
 
17
33
  # Capybara features specs
18
- watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
34
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
35
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
19
36
 
20
37
  # Turnip features and steps
21
38
  watch(%r{^spec/acceptance/(.+)\.feature$})
22
- watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
39
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
40
+ Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance'
41
+ end
23
42
  end
24
-
data/README.md CHANGED
@@ -41,6 +41,7 @@ product = Product.new validity: Date.new(2001,2,3)
41
41
  ```
42
42
 
43
43
  We can use now ```_string```
44
+
44
45
  ```ruby
45
46
  product.validity_string # => '03/02/2001'
46
47
  ```
data/Rakefile CHANGED
@@ -1 +1 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
@@ -1,4 +1,4 @@
1
- require "stringify_date/version"
1
+ require 'stringify_date/version'
2
2
  require 'stringify_date/active_record/stringify'
3
3
 
4
4
  module StringifyDate
@@ -7,43 +7,39 @@ module StringifyDate
7
7
  module Stringify
8
8
  extend ActiveSupport::Concern
9
9
 
10
+ def parse_value(name, value, format)
11
+ return nil unless value.present?
12
+
13
+ begin
14
+ Time.strptime(value, format)
15
+ rescue ArgumentError
16
+ instance_variable_set("@#{name}_invalid", true)
17
+ nil
18
+ end
19
+ end
20
+
10
21
  module ClassMethods
11
22
  def stringify(field, *args)
12
23
  column_name = field.to_s
13
-
14
- options = args.extract_options!
15
-
16
- format = options[:format] || '%Y-%m-%d'
17
-
18
- name = [column_name, 'string'].join('_')
24
+ options = args.extract_options!
25
+ format = options[:format] || '%Y-%m-%d'
26
+ name = [column_name, 'string'].join('_')
19
27
 
20
28
  define_method name do
21
29
  date = send(column_name)
22
- date.strftime(format) unless date.nil?
30
+ date.strftime(format) if date.present?
23
31
  end
24
32
 
25
33
  define_method "#{name}=" do |value|
26
- self.send(
27
- "#{column_name}=",
28
- if value.present?
29
- begin
30
- Time.parse(value)
31
- rescue ArgumentError
32
- instance_variable_set("@#{name}_invalid", true)
33
- nil
34
- end
35
- else
36
- nil
37
- end
38
- )
34
+ parsed_value = parse_value(name, value, format)
35
+ send("#{column_name}=", parsed_value)
39
36
  end
40
37
 
41
38
  define_method "validate_#{name}" do
42
39
  errors.add(name.to_sym, I18n.t('errors.invalid')) if instance_variable_get("@#{name}_invalid")
43
40
  end
44
41
 
45
- self.send(:validate, :"validate_#{name}")
46
-
42
+ send(:validate, :"validate_#{name}")
47
43
  end
48
44
  end
49
45
  end
@@ -1,3 +1,3 @@
1
1
  module StringifyDate
2
- VERSION = "0.0.5"
2
+ VERSION = '0.1.0'.freeze
3
3
  end
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe StringifyDate::ActiveRecord::Stringify do
4
-
5
4
  let(:test_date) do
6
5
  TestDate.new(start_at: Date.today, end_at: DateTime.now)
7
6
  end
@@ -23,7 +22,7 @@ describe StringifyDate::ActiveRecord::Stringify do
23
22
  expect(test_date).to respond_to(:published_at_string=)
24
23
  end
25
24
 
26
- it "should set start_at_string to 22/10/2012 when start_at 2012-10-22 and stringify format is '%d/%m/%Y'" do
25
+ it 'should set start_at_string to 22/10/2012 when start_at 2012-10-22 and stringify format is "%d/%m/%Y"' do
27
26
  test_date.start_at = Date.new(2012, 10, 22)
28
27
 
29
28
  expect(test_date.start_at_string).to eq('22/10/2012')
@@ -47,14 +46,14 @@ describe StringifyDate::ActiveRecord::Stringify do
47
46
  expect(test_date.valid?).to be(true)
48
47
  end
49
48
 
50
- it "should set start_at_string to 22/10/2012 when start_at 2001-02-03 and stringify format is '%d/%m/%Y %H:%M:%S'" do
51
- test_date.end_at = DateTime.new(2001,2,3)
49
+ it 'should set start_at_string to 22/10/2012 when start_at 2001-02-03 and stringify format is "%d/%m/%Y %H:%M:%S"' do
50
+ test_date.end_at = DateTime.new(2001, 2, 3)
52
51
 
53
52
  expect(test_date.end_at_string).to eq('03/02/2001 00:00:00')
54
53
  end
55
54
 
56
- it "should set published_at_string to 2001-02-03 when published_at 2001-02-03 and stringify format is not passing" do
57
- test_date.published_at = DateTime.new(2001,2,3)
55
+ it 'should set published_at_string to 2001-02-03 when published_at 2001-02-03 and stringify format is not passing' do
56
+ test_date.published_at = Date.new(2001, 2, 3)
58
57
 
59
58
  expect(test_date.published_at_string).to eq('2001-02-03')
60
59
  end
@@ -1,5 +1,5 @@
1
1
  class TestDate < ActiveRecord::Base
2
- stringify :start_at, format: "%d/%m/%Y"
3
- stringify :end_at, format: "%d/%m/%Y %H:%M:%S"
2
+ stringify :start_at, format: '%d/%m/%Y'
3
+ stringify :end_at, format: '%d/%m/%Y %H:%M:%S'
4
4
  stringify :published_at
5
5
  end
@@ -1,6 +1,6 @@
1
- ENV["RAILS_ENV"] = 'test'
1
+ ENV['RAILS_ENV'] = 'test'
2
2
 
3
- require File.expand_path("../../spec/dummy/config/environment", __FILE__)
3
+ require File.expand_path('../../spec/dummy/config/environment', __FILE__)
4
4
 
5
5
  require 'rspec/rails'
6
6
 
@@ -1,36 +1,35 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'stringify_date/version'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "stringify_date"
6
+ spec.name = 'stringify_date'
8
7
  spec.version = StringifyDate::VERSION
9
- spec.authors = ["Rute Passos", "Matheus Oliveira"]
10
- spec.email = ["matheus.vetor@gmail.com"]
8
+ spec.authors = ['Matheus Oliveira']
9
+ spec.email = ['matheus.vetor@gmail.com']
11
10
  spec.summary = %q{Parser for string an date/datetime}
12
11
  spec.description = %q{This gem makes it easy to convert string to date and provides method to create a string version for the attribute}
13
- spec.homepage = "https://github.com/matheusvetor/stringify_date"
14
- spec.license = "MIT"
12
+ spec.homepage = 'https://github.com/matheusvetor/stringify_date'
13
+ spec.license = 'MIT'
15
14
 
16
- spec.files.delete("spec/dummy/log")
17
- spec.files.delete("spec/dummy/log/development.log")
18
- spec.files.delete("spec/dummy/log/test.log")
19
- spec.files.delete("spec/dummy/db/development.sqlite3")
20
- spec.files.delete("spec/dummy/db/test.sqlite3")
15
+ spec.files.delete('spec/dummy/log')
16
+ spec.files.delete('spec/dummy/log/development.log')
17
+ spec.files.delete('spec/dummy/log/test.log')
18
+ spec.files.delete('spec/dummy/db/development.sqlite3')
19
+ spec.files.delete('spec/dummy/db/test.sqlite3')
21
20
 
22
21
  spec.files = `git ls-files -z`.split("\x0")
23
22
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
- spec.require_paths = ["lib"]
23
+ spec.test_files = spec.files.grep(%r{^(spec)/})
24
+ spec.require_paths = ['lib']
26
25
 
27
- spec.add_dependency "activesupport", ">= 3.2"
28
- spec.add_dependency "railties", ">= 3.2"
26
+ spec.add_dependency 'activesupport', '>= 4.2'
27
+ spec.add_dependency 'railties', '>= 4.2'
29
28
 
30
- spec.add_development_dependency "bundler", "~> 1.6"
31
- spec.add_development_dependency "rake"
32
- spec.add_development_dependency "rails"
33
- spec.add_development_dependency "rspec-rails"
34
- spec.add_development_dependency "sqlite3"
29
+ spec.add_development_dependency 'bundler', '~> 1.6'
30
+ spec.add_development_dependency 'rake'
31
+ spec.add_development_dependency 'rails'
32
+ spec.add_development_dependency 'rspec-rails'
33
+ spec.add_development_dependency 'sqlite3'
35
34
  spec.add_development_dependency 'guard-rspec'
36
35
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stringify_date
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Rute Passos
8
7
  - Matheus Oliveira
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-10-07 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
@@ -17,28 +16,28 @@ dependencies:
17
16
  requirements:
18
17
  - - ">="
19
18
  - !ruby/object:Gem::Version
20
- version: '3.2'
19
+ version: '4.2'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - ">="
26
25
  - !ruby/object:Gem::Version
27
- version: '3.2'
26
+ version: '4.2'
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: railties
30
29
  requirement: !ruby/object:Gem::Requirement
31
30
  requirements:
32
31
  - - ">="
33
32
  - !ruby/object:Gem::Version
34
- version: '3.2'
33
+ version: '4.2'
35
34
  type: :runtime
36
35
  prerelease: false
37
36
  version_requirements: !ruby/object:Gem::Requirement
38
37
  requirements:
39
38
  - - ">="
40
39
  - !ruby/object:Gem::Version
41
- version: '3.2'
40
+ version: '4.2'
42
41
  - !ruby/object:Gem::Dependency
43
42
  name: bundler
44
43
  requirement: !ruby/object:Gem::Requirement
@@ -144,17 +143,8 @@ files:
144
143
  - spec/active_record/stringify_spec.rb
145
144
  - spec/dummy/README.rdoc
146
145
  - spec/dummy/Rakefile
147
- - spec/dummy/app/assets/images/.keep
148
- - spec/dummy/app/assets/javascripts/application.js
149
- - spec/dummy/app/assets/stylesheets/application.css
150
- - spec/dummy/app/controllers/application_controller.rb
151
- - spec/dummy/app/controllers/concerns/.keep
152
- - spec/dummy/app/helpers/application_helper.rb
153
- - spec/dummy/app/mailers/.keep
154
146
  - spec/dummy/app/models/.keep
155
- - spec/dummy/app/models/concerns/.keep
156
147
  - spec/dummy/app/models/test_date.rb
157
- - spec/dummy/app/views/layouts/application.html.erb
158
148
  - spec/dummy/bin/bundle
159
149
  - spec/dummy/bin/rails
160
150
  - spec/dummy/bin/rake
@@ -211,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
201
  version: '0'
212
202
  requirements: []
213
203
  rubyforge_project:
214
- rubygems_version: 2.4.1
204
+ rubygems_version: 2.7.4
215
205
  signing_key:
216
206
  specification_version: 4
217
207
  summary: Parser for string an date/datetime
@@ -219,17 +209,8 @@ test_files:
219
209
  - spec/active_record/stringify_spec.rb
220
210
  - spec/dummy/README.rdoc
221
211
  - spec/dummy/Rakefile
222
- - spec/dummy/app/assets/images/.keep
223
- - spec/dummy/app/assets/javascripts/application.js
224
- - spec/dummy/app/assets/stylesheets/application.css
225
- - spec/dummy/app/controllers/application_controller.rb
226
- - spec/dummy/app/controllers/concerns/.keep
227
- - spec/dummy/app/helpers/application_helper.rb
228
- - spec/dummy/app/mailers/.keep
229
212
  - spec/dummy/app/models/.keep
230
- - spec/dummy/app/models/concerns/.keep
231
213
  - spec/dummy/app/models/test_date.rb
232
- - spec/dummy/app/views/layouts/application.html.erb
233
214
  - spec/dummy/bin/bundle
234
215
  - spec/dummy/bin/rails
235
216
  - spec/dummy/bin/rake
File without changes
@@ -1,13 +0,0 @@
1
- // This is a manifest file that'll be compiled into application.js, which will include all the files
2
- // listed below.
3
- //
4
- // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
- // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
- //
7
- // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
- // compiled file.
9
- //
10
- // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
- // about supported directives.
12
- //
13
- //= require_tree .
@@ -1,15 +0,0 @@
1
- /*
2
- * This is a manifest file that'll be compiled into application.css, which will include all the files
3
- * listed below.
4
- *
5
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
- *
8
- * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
- * compiled file so the styles you add here take precedence over styles defined in any styles
10
- * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
- * file per style scope.
12
- *
13
- *= require_tree .
14
- *= require_self
15
- */
@@ -1,5 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- # Prevent CSRF attacks by raising an exception.
3
- # For APIs, you may want to use :null_session instead.
4
- protect_from_forgery with: :exception
5
- end
File without changes
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
File without changes
File without changes
@@ -1,14 +0,0 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Dummy</title>
5
- <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
- <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
- <%= csrf_meta_tags %>
8
- </head>
9
- <body>
10
-
11
- <%= yield %>
12
-
13
- </body>
14
- </html>