Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Derek Leadbetter committed Sep 6, 2023
0 parents commit 677f4d0
Show file tree
Hide file tree
Showing 80 changed files with 1,259 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.bundle/
/doc/
/log/*.log
/pkg/
/tmp/
/test/dummy/db/*.sqlite3
/test/dummy/db/*.sqlite3-*
/test/dummy/log/*.log
/test/dummy/storage/
/test/dummy/tmp/
.idea
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.2.2
8 changes: 8 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

# Specify your gem's dependencies in fuzzy_dates.gemspec.
gemspec

# Start debugger with binding.b [https://github.com/ruby/debug]
# gem "debug", ">= 1.0.0"
162 changes: 162 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
PATH
remote: .
specs:
fuzzy_dates (0.1.0)
rails (>= 6.0.3.2, < 8)

GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.7.2)
actionpack (= 7.0.7.2)
activesupport (= 7.0.7.2)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.7.2)
actionpack (= 7.0.7.2)
activejob (= 7.0.7.2)
activerecord (= 7.0.7.2)
activestorage (= 7.0.7.2)
activesupport (= 7.0.7.2)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.7.2)
actionpack (= 7.0.7.2)
actionview (= 7.0.7.2)
activejob (= 7.0.7.2)
activesupport (= 7.0.7.2)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.7.2)
actionview (= 7.0.7.2)
activesupport (= 7.0.7.2)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.7.2)
actionpack (= 7.0.7.2)
activerecord (= 7.0.7.2)
activestorage (= 7.0.7.2)
activesupport (= 7.0.7.2)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.7.2)
activesupport (= 7.0.7.2)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.7.2)
activesupport (= 7.0.7.2)
globalid (>= 0.3.6)
activemodel (7.0.7.2)
activesupport (= 7.0.7.2)
activerecord (7.0.7.2)
activemodel (= 7.0.7.2)
activesupport (= 7.0.7.2)
activestorage (7.0.7.2)
actionpack (= 7.0.7.2)
activejob (= 7.0.7.2)
activerecord (= 7.0.7.2)
activesupport (= 7.0.7.2)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.7.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
builder (3.2.4)
concurrent-ruby (1.2.2)
crass (1.0.6)
date (3.3.3)
erubi (1.12.0)
globalid (1.1.0)
activesupport (>= 5.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
loofah (2.21.3)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
mail (2.8.1)
mini_mime (>= 0.1.1)
net-imap
net-pop
net-smtp
marcel (1.0.2)
method_source (1.0.0)
mini_mime (1.1.5)
mini_portile2 (2.8.4)
minitest (5.19.0)
net-imap (0.3.7)
date
net-protocol
net-pop (0.1.2)
net-protocol
net-protocol (0.2.1)
timeout
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.4)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
nokogiri (1.15.4-x86_64-darwin)
racc (~> 1.4)
racc (1.7.1)
rack (2.2.8)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.7.2)
actioncable (= 7.0.7.2)
actionmailbox (= 7.0.7.2)
actionmailer (= 7.0.7.2)
actionpack (= 7.0.7.2)
actiontext (= 7.0.7.2)
actionview (= 7.0.7.2)
activejob (= 7.0.7.2)
activemodel (= 7.0.7.2)
activerecord (= 7.0.7.2)
activestorage (= 7.0.7.2)
activesupport (= 7.0.7.2)
bundler (>= 1.15.0)
railties (= 7.0.7.2)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
nokogiri (>= 1.6)
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.0.7.2)
actionpack (= 7.0.7.2)
activesupport (= 7.0.7.2)
method_source
rake (>= 12.2)
thor (~> 1.0)
zeitwerk (~> 2.5)
rake (13.0.6)
thor (1.2.2)
timeout (0.4.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
websocket-driver (0.7.6)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
zeitwerk (2.6.11)

PLATFORMS
ruby
x86_64-darwin-19

DEPENDENCIES
fuzzy_dates!

BUNDLED WITH
2.3.16
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2023 Derek Leadbetter

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# FuzzyDates
Short description and motivation.

## Installation
Add this line to your application's Gemfile:

```ruby
gem "fuzzy_dates"
```

And then execute:
```bash
$ bundle install
```

Or install it yourself as:
```bash
$ gem install fuzzy_dates
```

## Usage
How to use my plugin.

## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require "bundler/setup"

APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
load "rails/tasks/engine.rake"

load "rails/tasks/statistics.rake"

require "bundler/gem_tasks"
Empty file added app/controllers/concerns/.keep
Empty file.
4 changes: 4 additions & 0 deletions app/controllers/fuzzy_dates/application_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module FuzzyDates
class ApplicationController < ActionController::Base
end
end
4 changes: 4 additions & 0 deletions app/jobs/fuzzy_dates/application_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module FuzzyDates
class ApplicationJob < ActiveJob::Base
end
end
6 changes: 6 additions & 0 deletions app/mailers/fuzzy_dates/application_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module FuzzyDates
class ApplicationMailer < ActionMailer::Base
default from: "[email protected]"
layout "mailer"
end
end
Empty file added app/models/concerns/.keep
Empty file.
42 changes: 42 additions & 0 deletions app/models/concerns/fuzzy_dates/fuzzy_dateable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module FuzzyDates
module FuzzyDateable
extend ActiveSupport::Concern

included do
def self.has_fuzzy_dates(*attributes)
attributes.each do |attribute|
# Relationship
has_one attribute, -> { where(attribute: attribute) }, as: :dateable, class_name: 'FuzzyDate', dependent: :destroy, required: false, inverse_of: :dateable

# Nested attributes
accepts_nested_attributes_for attribute, allow_destroy: true, reject_if: :is_empty?

# Resourceable params
allow_params "#{attribute}_attributes".to_sym => [:id, :attribute, :accuracy, :range, :start_date, :end_date, :description, :_destroy]

define_singleton_method("#{attribute}_join".to_sym) do
table = self.arel_table
date_table = FuzzyDate.arel_table.alias(attribute)

table
.join(date_table, Arel::Nodes::OuterJoin)
.on(
date_table[:dateable_id].eq(table[:id])
.and(date_table[:dateable_type].eq(self.to_s)
.and(date_table[:attribute].eq(attribute)))
)
.join_sources
end
end
end

private

def is_empty?(attributes)
!(attributes['start_date'].present? && attributes['end_date'].present?)
end

end

end
end
5 changes: 5 additions & 0 deletions app/models/fuzzy_dates/application_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module FuzzyDates
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
end
13 changes: 13 additions & 0 deletions app/models/fuzzy_dates/fuzzy_date.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module FuzzyDates
class FuzzyDate < ApplicationRecord
# Relationships
belongs_to :dateable, polymorphic: true

# Enumerated fields
enum accurary: [:year, :month, :date]

def present?
self.start_date.present? || (self.description.present? && !self.description.empty?)
end
end
end
15 changes: 15 additions & 0 deletions app/views/layouts/fuzzy_dates/application.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<title>Fuzzy dates</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag "fuzzy_dates/application", media: "all" %>
</head>
<body>

<%= yield %>

</body>
</html>
14 changes: 14 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path("..", __dir__)
ENGINE_PATH = File.expand_path("../lib/fuzzy_dates/engine", __dir__)
APP_PATH = File.expand_path("../test/dummy/config/application", __dir__)

# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])

require "rails/all"
require "rails/engine/commands"
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FuzzyDates::Engine.routes.draw do
end
17 changes: 17 additions & 0 deletions db/migrate/20230901161604_create_fuzzy_dates_fuzzy_dates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateFuzzyDatesFuzzyDates < ActiveRecord::Migration[7.0]
def change
create_table :fuzzy_dates_fuzzy_dates do |t|
t.references :dateable, polymorphic: true, null: false, index: true
t.string :attribute
t.integer :accuracy
t.boolean :range
t.date :start_date
t.date :end_date
t.text :description

t.timestamps
end

add_index :fuzzy_dates_fuzzy_dates, [:dateable_id, :dateable_type, :attribute], name: 'index_fuzzy_dates_dateable_id_dateable_type_attribute'
end
end
21 changes: 21 additions & 0 deletions fuzzy_dates.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative 'lib/fuzzy_dates/version'

Gem::Specification.new do |spec|
spec.name = 'fuzzy_dates'
spec.version = FuzzyDates::VERSION
spec.authors = ['Performant Software Solutions']
spec.email = ['[email protected]']
spec.homepage = 'https://github.com/performant-software/fuzzy-dates'
spec.summary = 'Summary of FuzzyDates.'
spec.description = 'Description of FuzzyDates.'
spec.license = 'MIT'

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = spec.homepage

spec.files = Dir.chdir(File.expand_path(__dir__)) do
Dir['{app,config,db,lib}/**/*', 'MIT-LICENSE', 'Rakefile', 'README.md']
end

spec.add_dependency 'rails', '>= 6.0.3.2', '< 8'
end
Loading

0 comments on commit 677f4d0

Please sign in to comment.