fossil 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/fossil.gemspec +2 -2
- data/lib/sequel/fos_dates.rb +53 -31
- data/lib/sequel/model_patch.rb +10 -71
- data/spec/sequel/fos_dates_spec.rb +11 -2
- data/spec/sequel/model_patch_spec.rb +18 -10
- data/spec/spec_helper.rb +6 -9
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/fossil.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{fossil}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Patrick Lardin, Daniel Sudol"]
|
12
|
-
s.date = %q{2010-01-
|
12
|
+
s.date = %q{2010-01-24}
|
13
13
|
s.description = %q{Access FOS/betrieve db with this Sequel based orm wrapper}
|
14
14
|
s.email = %q{plardin@xojet.com}
|
15
15
|
s.files = [
|
data/lib/sequel/fos_dates.rb
CHANGED
@@ -11,44 +11,66 @@ class Date
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
DATE_FORMATS[:hm] = "%H:%M"
|
14
|
+
module TimeFunctions
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
self.original_to_s(args)
|
16
|
+
def self.included(klass)
|
17
|
+
klass.send(:include,TimeFunctions::InstanceMethods)
|
18
|
+
klass.send(:extend,TimeFunctions::ClassMethods)
|
21
19
|
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
21
|
+
module InstanceMethods
|
22
|
+
def as_minutes
|
23
|
+
hour*60 + min
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
def in_hundredths
|
27
|
+
return 0 if hour + min == 0
|
28
|
+
minutes = hour*60 + min
|
29
|
+
val = "#{minutes/60}.#{((100*(minutes.modulo(60)))/60).to_s.rjust(2, '0')}"
|
30
|
+
BigDecimal.new(val, 2).round(1).to_s
|
31
|
+
end
|
32
|
+
|
33
|
+
def in_hundredths_rounded_XOJET_style
|
34
|
+
return 0 if hour + min == 0
|
35
|
+
# It was determined that "ODD" increments of .05 (ie .15, .35, .55, .75, .95) of an hour (ie. 9,21,33,45,57 minutes) rounded UP whereas even increments of .05 rounded DOWN - sn
|
36
|
+
minutes = hour*60 + min
|
37
|
+
(minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.001 : -0.001)).round(2)
|
38
|
+
#minutes/60.0
|
39
|
+
end
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
41
|
+
def in_tenths_rounded_XOJET_style
|
42
|
+
return 0 if hour + min == 0
|
43
|
+
# It was determined that "ODD" increments of .05 (ie .15, .35, .55, .75, .95) of an hour (ie. 9,21,33,45,57 minutes) rounded UP whereas even increments of .05 rounded DOWN - sn
|
44
|
+
minutes = hour*60 + min
|
45
|
+
(minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.01 : -0.01)).round(1)
|
46
|
+
end
|
37
47
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
48
|
+
|
49
|
+
module ClassMethods
|
50
|
+
# creates utc time from days and minutes
|
51
|
+
def from_fos_date_time(days, minutes)
|
52
|
+
from_fos_time(days*1440 + minutes)
|
53
|
+
end
|
54
|
+
|
55
|
+
# creates utc time from minutes
|
56
|
+
def from_fos_time(minutes)
|
57
|
+
DateTime.new(1899, 12, 31).advance(:minutes=>minutes)
|
58
|
+
end
|
45
59
|
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class Time
|
63
|
+
include TimeFunctions
|
64
|
+
DATE_FORMATS[:hm] = "%H:%M"
|
65
|
+
|
66
|
+
alias :original_to_s :to_s
|
46
67
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
minutes = hour*60 + min
|
51
|
-
(minutes/60.0 + ([9, 21, 33, 45, 57].include?( min ) ? 0.01 : -0.01)).round(1)
|
68
|
+
def to_s(args=nil)
|
69
|
+
args = :hm unless args
|
70
|
+
self.original_to_s(args)
|
52
71
|
end
|
53
|
-
|
72
|
+
end
|
73
|
+
|
74
|
+
class DateTime
|
75
|
+
include TimeFunctions
|
54
76
|
end
|
data/lib/sequel/model_patch.rb
CHANGED
@@ -5,27 +5,16 @@ class Sequel::Model
|
|
5
5
|
self.use_transactions=false
|
6
6
|
plugin :validation_helpers
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
hash
|
8
|
+
# passing in an array of attribute names, fills a hash with values from the model.
|
9
|
+
def fill_hash(attributes)
|
10
|
+
attributes.inject({}) do |hash,attribute|
|
11
|
+
hash[attribute]= values[attribute] if values.has_key?(attribute)
|
12
|
+
hash
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
16
|
class << self
|
16
17
|
|
17
|
-
def pk_for_select(options={})
|
18
|
-
table = options[:table] || table_name
|
19
|
-
use_alias = options[:alias]
|
20
|
-
primary_key.collect do |k|
|
21
|
-
if use_alias
|
22
|
-
k.qualify(table).as("#{table}_#{k}")
|
23
|
-
else
|
24
|
-
k.qualify(table)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
18
|
attr_accessor :datatypes, :aliases
|
30
19
|
|
31
20
|
def clear_schema
|
@@ -50,61 +39,13 @@ class Sequel::Model
|
|
50
39
|
key = primary_key
|
51
40
|
graph_conditions = { :"#{prefix} kid - date" => :'kid - date', :"#{prefix} kid - time" => :'kid - time', :"#{prefix} kid - user" => :'kid - user', :"#{prefix} kid - mult" => :'kid - mult', :"#{prefix} kid - comm" => :'kid - comm' }
|
52
41
|
dataset_filter = proc { class_name.to_s.constantize.filter( :"#{prefix} kid - date"=>self[:'kid - date'], :"#{prefix} kid - time"=>self[:'kid - time'], :"#{prefix} kid - user"=>self[:'kid - user'], :"#{prefix} kid - mult"=>self[:'kid - mult'], :"#{prefix} kid - comm"=>self[:'kid - comm']) }
|
53
|
-
eager_load_proc =
|
54
|
-
proc do |key_hash, parents, associations|
|
55
|
-
id_map = {}
|
56
|
-
filter_args = Hash.new{|k,v| k[v]=[]}
|
57
|
-
parents.each do |p|
|
58
|
-
key_arr = []
|
59
|
-
primary_key.each do |k|
|
60
|
-
key_arr << p[k]
|
61
|
-
filter_args[k] << p[k]
|
62
|
-
end
|
63
|
-
id_map[key_arr] = p
|
64
|
-
end
|
65
|
-
parent_keys = graph_conditions.keys
|
66
|
-
filter_expr = Sequel::SQL::BooleanExpression.new(
|
67
|
-
:OR,
|
68
|
-
*id_map.keys.map{|k| [ [graph_conditions.keys[0], k[0]], [graph_conditions.keys[1], k[1]], [graph_conditions.keys[2], k[2]], [graph_conditions.keys[3], k[3]], [graph_conditions.keys[4], k[4]] ].sql_expr}
|
69
|
-
)
|
70
|
-
class_name.to_s.constantize.filter(filter_expr).all do |h|
|
71
|
-
parent_key_values = parent_keys.collect{|k| h[k]}
|
72
|
-
if d = id_map[parent_key_values]
|
73
|
-
d.associations[assoc_name] = [] unless d.associations[assoc_name]
|
74
|
-
d.associations[assoc_name] << h
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
42
|
when :many_to_one
|
80
43
|
key = nil
|
81
44
|
graph_conditions = { :'kid - date'=>:"#{prefix} kid - date", :'kid - time'=>:"#{prefix} kid - time", :'kid - user'=>:"#{prefix} kid - user", :'kid - mult'=>:"#{prefix} kid - mult", :'kid - comm'=>:"#{prefix} kid - comm" }
|
82
45
|
dataset_filter = proc { class_name.to_s.constantize.filter( :"kid - date"=>self[:"#{prefix} kid - date"], :"kid - time"=>self[:"#{prefix} kid - time"], :"kid - user"=>self[:"#{prefix} kid - user"], :"kid - mult"=>self[:"#{prefix} kid - mult"], :"kid - comm"=>self[:"#{prefix} kid - comm"]) }
|
83
|
-
eager_load_proc =
|
84
|
-
proc do |key_hash, parents, associations|
|
85
|
-
id_map = {}
|
86
|
-
filter_args = Hash.new{|k,v| k[v]=[]}
|
87
|
-
parents.each do |p|
|
88
|
-
key_arr = []
|
89
|
-
primary_key.each do |k|
|
90
|
-
key_arr << p[k]
|
91
|
-
filter_args[k] << p[k]
|
92
|
-
end
|
93
|
-
id_map[key_arr] = p
|
94
|
-
end
|
95
|
-
parent_to_child_keys = graph_conditions.keys
|
96
|
-
filter_expr = Sequel::SQL::BooleanExpression.new(
|
97
|
-
:OR,
|
98
|
-
*id_map.keys.map{|k| [ [parent_to_child_keys[0], k[0]], [parent_to_child_keys[1], k[1]], [parent_to_child_keys[2], k[2]], [parent_to_child_keys[3], k[3]], [parent_to_child_keys[4], k[4]] ].sql_expr}
|
99
|
-
)
|
100
|
-
class_name.to_s.constantize.filter(filter_expr).all do |h|
|
101
|
-
parent_key_values = parent_to_child_keys.collect{|k| h[k]}
|
102
|
-
id_map[parent_key_values].associations[assoc_name] = h
|
103
|
-
end
|
104
|
-
end
|
105
46
|
end
|
106
47
|
graph_conditions.merge!(options[:graph_only_conditions]) if options[:graph_only_conditions]
|
107
|
-
send(assoc_type, assoc_name, :key=> key, :class => class_name, :dataset=> dataset_filter, :graph_only_conditions=>graph_conditions
|
48
|
+
send(assoc_type, assoc_name, :key=> key, :class => class_name, :dataset=> dataset_filter, :graph_only_conditions=>graph_conditions)
|
108
49
|
end
|
109
50
|
|
110
51
|
# for creating an association to the 'Codes' table
|
@@ -129,14 +70,12 @@ class Sequel::Model
|
|
129
70
|
delegate :description, :to=> assoc_name, :prefix=>true, :allow_nil => true
|
130
71
|
end
|
131
72
|
|
73
|
+
# date_column,time_column should be a Fixnum because fos stores dates,times as numbers
|
132
74
|
def column_def_datetime(datetime_column_name, date_column, time_column)
|
133
75
|
inst_def datetime_column_name do
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
loc_time = date.to_time
|
138
|
-
time_utc = Time.gm(loc_time.year, loc_time.month, loc_time.day)
|
139
|
-
time_utc + time.minutes
|
76
|
+
days = send(:[], date_column) || 0 # nil defaults to 0 days
|
77
|
+
minutes = send(:[], time_column) || 0 # nil defaults to 0 minutes
|
78
|
+
Time.from_fos_date_time(days, minutes) # returns utc time
|
140
79
|
end
|
141
80
|
end
|
142
81
|
|
@@ -2,12 +2,22 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe "fos_dates" do
|
4
4
|
|
5
|
+
it "Time and DateTime have proper class methods included from TimeFunctions" do
|
6
|
+
Time.should respond_to(:from_fos_time)
|
7
|
+
DateTime.should respond_to(:from_fos_time)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "Time and DateTime have proper class methods included from TimeFunctions" do
|
11
|
+
Time.new.should respond_to(:as_minutes)
|
12
|
+
DateTime.new.should respond_to(:as_minutes)
|
13
|
+
end
|
14
|
+
|
5
15
|
it "converts fos date number to a Ruby Date" do
|
6
16
|
Date.from_fos_days(10).should == Date.new(1900,1,10)
|
7
17
|
end
|
8
18
|
|
9
19
|
it "converts fos time number to a Ruby Time" do
|
10
|
-
Time.from_fos_time(100).should ==
|
20
|
+
Time.from_fos_time(100).should == DateTime.new(1899,12,31,1,40,0)
|
11
21
|
end
|
12
22
|
|
13
23
|
it "converts a Ruby Time to hundredths" do
|
@@ -21,5 +31,4 @@ describe "fos_dates" do
|
|
21
31
|
it "Time view defaults to M:H" do
|
22
32
|
Time.parse('Sept 9, 2009 07:10').to_s.should == "07:10"
|
23
33
|
end
|
24
|
-
|
25
34
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../spec_helper'
|
2
2
|
require File.dirname(__FILE__) + '/spec_helper_tables' unless metaclass.class_variable_defined? :@@set_up_demo_tables
|
3
|
-
|
3
|
+
|
4
4
|
describe "Sequel::Model extentions" do
|
5
|
-
|
5
|
+
|
6
6
|
it "has fill_hash method" do
|
7
7
|
Dude.first.should respond_to(:fill_hash)
|
8
8
|
Dude.first.fill_hash([:'kid - date']).should == {:'kid - date'=>1}
|
@@ -100,9 +100,9 @@ describe "Sequel::Model extentions" do
|
|
100
100
|
@record.my_special_name_view.should == "01:00"
|
101
101
|
end
|
102
102
|
|
103
|
-
it "shows correct currency view" do
|
104
|
-
@record.price_currency.should ==
|
105
|
-
@record.price_precision.should ==
|
103
|
+
it "shows correct currency view" do
|
104
|
+
@record.price_currency.should == 12.15
|
105
|
+
@record.price_precision.should == 12.15
|
106
106
|
end
|
107
107
|
|
108
108
|
it "shows correct currency view" do
|
@@ -206,14 +206,22 @@ describe "Sequel::Model extentions" do
|
|
206
206
|
describe "column_def" do
|
207
207
|
|
208
208
|
before do
|
209
|
-
add_test_table_data({:date_col => 39992, :time_col=>60})
|
210
|
-
end
|
211
|
-
|
212
|
-
it "datetime" do
|
213
209
|
TestTable.column_def_datetime :datetime_col, :date_col, :time_col
|
210
|
+
end
|
214
211
|
|
212
|
+
it "datetime makes method to represent datetime" do
|
213
|
+
add_test_table_data({:date_col => 39992, :time_col => 60})
|
215
214
|
TestTable.first.should respond_to(:datetime_col)
|
216
|
-
|
215
|
+
end
|
216
|
+
|
217
|
+
it "datetime can parse valid dates" do
|
218
|
+
add_test_table_data({:date_col => 39992, :time_col => 60})
|
219
|
+
TestTable.first.datetime_col.should == DateTime.new(2009,6,29,1,0,0)
|
220
|
+
end
|
221
|
+
|
222
|
+
it "datetime can handle nil date or time" do
|
223
|
+
add_test_table_data({:date_col => nil, :time_col => nil})
|
224
|
+
TestTable.first.datetime_col.should == DateTime.new(1899,12,31,0,0,0)
|
217
225
|
end
|
218
226
|
|
219
227
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
-
RAILS_ENV = "test"
|
2
|
-
|
3
|
-
require 'rubygems'
|
4
|
-
|
5
1
|
require 'lib/fossil'
|
6
2
|
require 'spec'
|
7
3
|
require 'rr'
|
8
4
|
|
9
|
-
unless defined?(DB_DEMO)
|
5
|
+
unless defined?(DB_DEMO)
|
10
6
|
DB_DEMO = Sequel.odbc('demodata')#, :loggers=>[Logger.new($stdout)])
|
11
7
|
DB_DEMO.extend(Sequel::Pervasive::DatabaseMethods)
|
12
8
|
|
@@ -19,16 +15,17 @@ require File.dirname(__FILE__) + "/helper_classes"
|
|
19
15
|
##### custom matchers #####
|
20
16
|
require File.dirname(__FILE__) + "/be_model_with_values_matcher"
|
21
17
|
|
22
|
-
|
23
18
|
Spec::Runner.configure do |config|
|
24
19
|
config.include(HelperMethods)
|
25
20
|
config.mock_with :rr
|
26
21
|
config.include(BeModelWithValuesMatcher)
|
27
22
|
end
|
28
23
|
|
29
|
-
|
24
|
+
# These are special modifictations for testing with mysql db instead of pervasive
|
25
|
+
# if its not windows or linux where pervasive db is running ) .. modify the
|
26
|
+
# pervasive adapter to act more like mysql, so that the tests can still run.
|
27
|
+
# This is not ideal, but it works
|
30
28
|
unless RUBY_PLATFORM =~ /mswin32|linux/
|
31
|
-
# if its not windows ( pervasive db ) .. modify the pervasive adapter to act more like mysql for certain things
|
32
29
|
|
33
30
|
module Sequel::Pervasive::DatabaseMethods
|
34
31
|
def auto_increment_sql; "AUTO_INCREMENT" end
|
@@ -52,4 +49,4 @@ unless RUBY_PLATFORM =~ /mswin32|linux/
|
|
52
49
|
end
|
53
50
|
|
54
51
|
end
|
55
|
-
|
52
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fossil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Lardin, Daniel Sudol
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-24 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|