better_date_picker 0.0.1

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: 1f89943f9d755b093b059c9f3f34fcd247b85ec3
4
+ data.tar.gz: 135b98fb7f383b5348bea70230214a76c78cd84e
5
+ SHA512:
6
+ metadata.gz: 90459af232a7f6758646768be8123cd14133a8e17977b3eeed42eb5717b1047c6643724cbb175c7848d6e6dd9a2bd0242662d4a5ec0f77bf264199eb10334e24
7
+ data.tar.gz: d9e28325d50a73ed5080cf87c8cf74baf5a3101404293ba35803f62b5d1919123b652040f0bdb45549e136cf0435f31ea43fb3c439b17c9036975fd456001708
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in better_date_picker.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dan Pickett
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,29 @@
1
+ # BetterDatePicker
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'better_date_picker'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install better_date_picker
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,30 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ begin
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc "Run specs"
7
+ RSpec::Core::RakeTask.new do |t|
8
+ end
9
+
10
+ task default: :spec
11
+ rescue LoadError
12
+ puts "RSpec is not installed"
13
+ end
14
+
15
+ begin
16
+ require "yard"
17
+ YARD::Rake::YardocTask.new do |t|
18
+ t.files = ['lib/**/*.rb'] # optional
19
+ end
20
+ rescue LoadError
21
+ puts "Yard is not installed"
22
+ end
23
+
24
+ task :console do
25
+ require 'irb'
26
+ require 'irb/completion'
27
+ require 'better_date_picker'
28
+ ARGV.clear
29
+ IRB.start
30
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'better_date_picker/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "better_date_picker"
8
+ spec.version = BetterDatePicker::VERSION
9
+ spec.authors = ["Dan Pickett"]
10
+ spec.email = ["dan.pickett@launchware.com"]
11
+ spec.description = %q{Assign Dates with Chronic Strings}
12
+ spec.summary = %q{Use Chronic Strings to Assign Dates}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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
+ spec.add_dependency "activesupport"
23
+ spec.add_dependency "chronic"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.3"
26
+ spec.add_development_dependency "yard"
27
+ spec.add_development_dependency "rake"
28
+ spec.add_development_dependency "rspec"
29
+ spec.add_development_dependency "pry"
30
+ end
@@ -0,0 +1,78 @@
1
+ require "active_support"
2
+ require "active_model"
3
+ require "chronic"
4
+
5
+ module BetterDatePicker
6
+ module Model
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ extend ClassMethods
11
+ class_attribute :better_date_fields
12
+ class_attribute :better_date_defaults
13
+ end
14
+
15
+ module ClassMethods
16
+ def better_time_picker(field, options = {})
17
+ self.better_date_fields ||= []
18
+ self.better_date_defaults ||= {}
19
+
20
+ define_method "#{field}=" do |date_val|
21
+ #we don't want to clobber the ivar if we're setting via the string
22
+ unless setting_via_string?
23
+ val_to_set = date_val.nil? ? nil : date_val.strftime(self.class.better_date_format)
24
+ instance_variable_set("@#{field}_date", val_to_set)
25
+ end
26
+
27
+ #if the setter is not defined as a method, just set the ivar
28
+ begin
29
+ super(date_val)
30
+ rescue NoMethodError => e
31
+ instance_variable_set("@#{field}", date_val)
32
+ end
33
+
34
+ end
35
+
36
+ define_method "#{field}_date" do
37
+ string_val = instance_variable_get("@#{field}_date")
38
+ if string_val.nil?
39
+ if the_date = self.send(field)
40
+ the_date.strftime(self.class.better_date_format)
41
+ end
42
+ else
43
+ string_val
44
+ end
45
+ end
46
+
47
+ define_method "#{field}_date=" do |stringified_date|
48
+ setting_via_string do
49
+ instance_variable_set("@#{field}_date", stringified_date)
50
+ self.send("#{field}=", Chronic.parse(stringified_date))
51
+ end
52
+ stringified_date
53
+ end
54
+
55
+ self.better_date_fields << field
56
+ self.better_date_defaults[field] = options[:default]
57
+ end
58
+
59
+ def better_date_format
60
+ "%m/%d/%Y"
61
+ end
62
+ end
63
+
64
+ protected
65
+ def setting_via_string(&block)
66
+ begin
67
+ @setting_via_string = true
68
+ block.call
69
+ ensure
70
+ @setting_via_string = false
71
+ end
72
+ end
73
+
74
+ def setting_via_string?
75
+ @setting_via_string
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module BetterDatePicker
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "better_date_picker/version"
2
+ require "better_date_picker/model"
3
+
4
+ module BetterDatePicker
5
+ end
@@ -0,0 +1,48 @@
1
+ require 'spec_helper'
2
+
3
+ describe BetterDatePicker::Model do
4
+ class Widget
5
+ include ActiveModel::Model
6
+ include ActiveModel::Validations::Callbacks
7
+ include BetterDatePicker::Model
8
+
9
+
10
+ attr_accessor :built_at
11
+
12
+ better_time_picker :built_at
13
+ end
14
+
15
+ it 'allows the setting of a date via a string' do
16
+ widget = Widget.new
17
+ date_string = '03/09/1984'
18
+ widget.built_at_date = date_string
19
+ expect(widget.built_at).to eql(Chronic.parse(date_string))
20
+ end
21
+
22
+ it 'sets the date to nil when assigned' do
23
+ widget = Widget.new
24
+ widget.built_at = Date.today
25
+ widget.built_at_date = nil
26
+ expect(widget.built_at).to be_nil
27
+ end
28
+
29
+ it 'sets the date to nil when a badly formed string is assigned' do
30
+ widget = Widget.new
31
+ widget.built_at = Date.today
32
+ widget.built_at_date = "INVALID DATE"
33
+ expect(widget.built_at).to be_nil
34
+ end
35
+
36
+ it 'sets the date string when the date is set' do
37
+ widget = Widget.new
38
+ widget.built_at = Date.today
39
+ expect(widget.built_at_date).to be_kind_of(String)
40
+ end
41
+
42
+ it 'nils the date string when the date is assigned nil' do
43
+ widget = Widget.new
44
+ widget.built_at_date = 'yesterday'
45
+ widget.built_at = nil
46
+ expect(widget.built_at_date).to be_nil
47
+ end
48
+ end
@@ -0,0 +1,4 @@
1
+ require 'rspec'
2
+ require 'pry'
3
+
4
+ require File.join(File.dirname(__FILE__), '../lib/better_date_picker')
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_date_picker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dan Pickett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-01 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: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: chronic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
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
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Assign Dates with Chronic Strings
126
+ email:
127
+ - dan.pickett@launchware.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.md
137
+ - Rakefile
138
+ - better_date_picker.gemspec
139
+ - lib/better_date_picker.rb
140
+ - lib/better_date_picker/model.rb
141
+ - lib/better_date_picker/version.rb
142
+ - spec/better_date_picker/model_spec.rb
143
+ - spec/spec_helper.rb
144
+ homepage: ''
145
+ licenses:
146
+ - MIT
147
+ metadata: {}
148
+ post_install_message:
149
+ rdoc_options: []
150
+ require_paths:
151
+ - lib
152
+ required_ruby_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - '>='
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ required_rubygems_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ requirements: []
163
+ rubyforge_project:
164
+ rubygems_version: 2.0.6
165
+ signing_key:
166
+ specification_version: 4
167
+ summary: Use Chronic Strings to Assign Dates
168
+ test_files:
169
+ - spec/better_date_picker/model_spec.rb
170
+ - spec/spec_helper.rb
171
+ has_rdoc: