fossil 0.5.35 → 0.5.36
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/fossil.gemspec +2 -2
- data/lib/models/flight_log_expense.rb +1 -0
- data/lib/models/trip_leg.rb +1 -4
- data/lib/sequel/model_patch.rb +50 -33
- data/spec/silly_spec.rb +6 -3
- data/spec/spec_helper.rb +0 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.36
|
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.5.
|
8
|
+
s.version = "0.5.36"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Daniel Sudol", "Patrick Lardin"]
|
12
|
-
s.date = %q{2011-03-
|
12
|
+
s.date = %q{2011-03-16}
|
13
13
|
s.description = %q{Access FOS/betrieve db with this Sequel based orm wrapper}
|
14
14
|
s.email = %q{dansudol@yahoo.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -4,6 +4,7 @@ class FlightLogExpense < Sequel::Model(:'flight log expenses')
|
|
4
4
|
|
5
5
|
#Many to one association with composite keys
|
6
6
|
n_to_o :trip_leg, :class=>:TripLeg, :prefix=>'trip leg'
|
7
|
+
many_to_one :vendor, :class=>:Vendor, :key=>:vendor_id, :primary_key=>:'vendor id'
|
7
8
|
|
8
9
|
#### BEGIN GENERATED SECTION ####
|
9
10
|
set_primary_key [:'kid - user', :'kid - mult', :'kid - comm', :'kid - date', :'kid - time']
|
data/lib/models/trip_leg.rb
CHANGED
@@ -75,6 +75,7 @@ class TripLeg < Sequel::Model(:'trip legs')
|
|
75
75
|
o_to_n :crew_legs, :class=>:CrewLeg, :prefix=>'trip leg'
|
76
76
|
o_to_n :audit_trails, :class=>:AuditTrail, :prefix=>'owner'
|
77
77
|
o_to_n :flight_log_expenses, :class=>:FlightLogExpense, :prefix=>'trip leg'
|
78
|
+
o_to_n :fuel_expenses, :class=>:FlightLogExpense, :prefix=>'trip leg', :extra_conditions => {:type => 1}
|
78
79
|
|
79
80
|
# Code associations
|
80
81
|
code_association :approval_value, :'approval code', :trip_approval
|
@@ -900,10 +901,6 @@ class TripLeg < Sequel::Model(:'trip legs')
|
|
900
901
|
end
|
901
902
|
|
902
903
|
# Fuel Expense Stuff
|
903
|
-
def fuel_expenses
|
904
|
-
flight_log_expenses.find_all { |expense| expense.type == 1 }
|
905
|
-
end
|
906
|
-
|
907
904
|
def departure_fuel_expenses
|
908
905
|
fuel_expenses.select { |expense| expense.arrival_airport == 0 }
|
909
906
|
end
|
data/lib/sequel/model_patch.rb
CHANGED
@@ -20,9 +20,10 @@ class Sequel::Model
|
|
20
20
|
# TripLeg['MERE',0,8,40443,1259], you would get a trip leg
|
21
21
|
# You still have to massage this key alittle to make the query:
|
22
22
|
# see Sequel.fos_id_to_lookup_key in core_patch.rb
|
23
|
-
PK_KEYS = [:"kid - user"
|
23
|
+
PK_KEYS = [:"kid - user", :"kid - mult", :"kid - comm", :"kid - date", :"kid - time"]
|
24
|
+
|
24
25
|
def fos_id
|
25
|
-
PK_KEYS.collect{|key| value=send(key); value.strip! if value.is_a?(String); value}.join('-')
|
26
|
+
PK_KEYS.collect { |key| value=send(key); value.strip! if value.is_a?(String); value }.join('-')
|
26
27
|
end
|
27
28
|
|
28
29
|
# Passing in an array of attribute / method names, fills a hash with values from
|
@@ -39,7 +40,7 @@ class Sequel::Model
|
|
39
40
|
hash[attribute_name] = send(attribute_name) if respond_to? attribute_name
|
40
41
|
hash
|
41
42
|
end
|
42
|
-
elsif attributes.is_a? Hash
|
43
|
+
elsif attributes.is_a? Hash
|
43
44
|
hash = {}
|
44
45
|
attributes.each do |key, attribute|
|
45
46
|
attribute_name = attribute.to_s.gsub('__', '_').to_sym
|
@@ -50,12 +51,12 @@ class Sequel::Model
|
|
50
51
|
end
|
51
52
|
end
|
52
53
|
|
53
|
-
def method_missing(method, *args, &block)
|
54
|
+
def method_missing(method, * args, & block)
|
54
55
|
if method.to_s.split(/__/).size > 1
|
55
56
|
generate_delegator(method)
|
56
|
-
send(method.to_s.gsub('__','_').to_sym)
|
57
|
+
send(method.to_s.gsub('__', '_').to_sym)
|
57
58
|
else
|
58
|
-
super(method, *args, &block)
|
59
|
+
super(method, * args, & block)
|
59
60
|
end
|
60
61
|
end
|
61
62
|
|
@@ -96,15 +97,31 @@ class Sequel::Model
|
|
96
97
|
class_name = options[:class]
|
97
98
|
prefix = options[:prefix]
|
98
99
|
case assoc_type
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
100
|
+
when :one_to_many
|
101
|
+
key = options[:key] || primary_key
|
102
|
+
primary_key = options[:primary_key] || key
|
103
|
+
extra_dataset_conditions = options[:extra_conditions] || {}
|
104
|
+
graph_conditions = {:"#{prefix} kid - date" => :'kid - date',
|
105
|
+
:"#{prefix} kid - time" => :'kid - time',
|
106
|
+
:"#{prefix} kid - user" => :'kid - user',
|
107
|
+
:"#{prefix} kid - mult" => :'kid - mult',
|
108
|
+
:"#{prefix} kid - comm" => :'kid - comm'}.
|
109
|
+
merge(extra_dataset_conditions)
|
110
|
+
dataset_filter = proc {
|
111
|
+
class_name.to_s.constantize.filter(
|
112
|
+
{:"#{prefix} kid - date"=>self[:'kid - date'],
|
113
|
+
:"#{prefix} kid - time"=>self[:'kid - time'],
|
114
|
+
:"#{prefix} kid - user"=>self[:'kid - user'],
|
115
|
+
:"#{prefix} kid - mult"=>self[:'kid - mult'],
|
116
|
+
:"#{prefix} kid - comm"=>self[:'kid - comm']}.
|
117
|
+
merge(extra_dataset_conditions)
|
118
|
+
)
|
119
|
+
}
|
120
|
+
when :many_to_one
|
121
|
+
key = nil
|
122
|
+
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"}
|
123
|
+
extra_dataset_conditions = options[:dataset_conditions] || {}
|
124
|
+
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"]}.merge(extra_dataset_conditions)) }
|
108
125
|
end
|
109
126
|
graph_conditions.merge!(options[:graph_only_conditions]) if options[:graph_only_conditions]
|
110
127
|
send(assoc_type, assoc_name, :key=> key, :primary_key=>primary_key, :class => class_name, :dataset=> dataset_filter, :graph_only_conditions=>graph_conditions)
|
@@ -114,13 +131,13 @@ class Sequel::Model
|
|
114
131
|
def code_association(assoc_name, column_name_holding_code, code_group_name)
|
115
132
|
# create the many to one association
|
116
133
|
send(:many_to_one, assoc_name, :class=>:Code, :key=>nil,
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
134
|
+
# dataset adds
|
135
|
+
:dataset=>proc {
|
136
|
+
value = self[column_name_holding_code] || send(column_name_holding_code)
|
137
|
+
Code.filter(:'value'=> value, :name=>CodeGroup.send(code_group_name))
|
138
|
+
},
|
139
|
+
# graph_only_conditions add the join conditions when using eager_graph in query
|
140
|
+
:graph_only_conditions => {:'value'=> column_name_holding_code, :name=>CodeGroup.send(code_group_name)}
|
124
141
|
)
|
125
142
|
|
126
143
|
# create the :get_all method to find all codes of the code group name
|
@@ -128,15 +145,15 @@ class Sequel::Model
|
|
128
145
|
Code.get_codes(CodeGroup.send(code_group_name))
|
129
146
|
end
|
130
147
|
# add a delegator that calls for the code, and one for description
|
131
|
-
delegate :code,
|
132
|
-
delegate :description, :to=> assoc_name, :prefix=>true,
|
148
|
+
delegate :code, :to=> assoc_name, :prefix=>true, :allow_nil => true
|
149
|
+
delegate :description, :to=> assoc_name, :prefix=>true, :allow_nil => true
|
133
150
|
end
|
134
151
|
|
135
152
|
# date_column,time_column should be a Fixnum because fos stores dates,times as numbers
|
136
153
|
def column_def_datetime(datetime_column_name, date_column, time_column)
|
137
154
|
inst_def datetime_column_name do
|
138
|
-
days = send(:[], date_column) || 0
|
139
|
-
minutes = send(:[], time_column) || 0
|
155
|
+
days = send(:[], date_column) || 0 # nil defaults to 0 days
|
156
|
+
minutes = send(:[], time_column) || 0 # nil defaults to 0 minutes
|
140
157
|
DateTime.from_fos_date_time(days, minutes) # returns utc datetime
|
141
158
|
end
|
142
159
|
end
|
@@ -214,7 +231,7 @@ class Sequel::Model
|
|
214
231
|
# paid_boolean => which returns a string ("False" / "True") for values ( 0 / 1 )
|
215
232
|
#
|
216
233
|
def column_view(column_name, type, custom_method_name=nil)
|
217
|
-
raise(StandardError,"Expect the type to be either :date, :datetime, :time, :currency, :precision or :boolean") unless [:date, :time, :datetime, :currency, :precision, :boolean].include? type
|
234
|
+
raise(StandardError, "Expect the type to be either :date, :datetime, :time, :currency, :precision or :boolean") unless [:date, :time, :datetime, :currency, :precision, :boolean].include? type
|
218
235
|
# will get value from old_column_name
|
219
236
|
method_name = custom_method_name || "#{column_name}_#{type.to_s}"
|
220
237
|
|
@@ -223,16 +240,16 @@ class Sequel::Model
|
|
223
240
|
column_value = send(column_name)
|
224
241
|
case type
|
225
242
|
when :date
|
226
|
-
|
243
|
+
Date.from_fos_days(column_value) if column_value
|
227
244
|
when :time
|
228
245
|
Time.from_fos_time(column_value) if column_value
|
229
246
|
when :currency
|
230
|
-
number_to_currency(
|
247
|
+
number_to_currency((column_value || 0).to_f/100, :unit=>'', :precision=>2)
|
231
248
|
when :precision
|
232
249
|
# precision wont do delimiter .. so send to currency
|
233
|
-
number_to_currency(
|
250
|
+
number_to_currency((column_value || 0).to_f/100, :unit=>'', :precision=>2)
|
234
251
|
when :boolean
|
235
|
-
return "True" if column_value and (
|
252
|
+
return "True" if column_value and (column_value == 1 or column_value == true)
|
236
253
|
"False"
|
237
254
|
end
|
238
255
|
end
|
@@ -267,8 +284,8 @@ class Sequel::Model
|
|
267
284
|
end
|
268
285
|
end
|
269
286
|
|
270
|
-
def select_fields(table, *fields)
|
271
|
-
dataset.select_fields(table, *fields)
|
287
|
+
def select_fields(table, * fields)
|
288
|
+
dataset.select_fields(table, * fields)
|
272
289
|
end
|
273
290
|
end
|
274
291
|
|
data/spec/silly_spec.rb
CHANGED
@@ -7,12 +7,13 @@ DB = Sequel.fos('fos', :loggers=>[Logger.new($stdout)])
|
|
7
7
|
#DB = Sequel.fos('demo_company_fos_db')#, :loggers=>[Logger.new($stdout)])
|
8
8
|
#DB = Sequel.fos('flyos')#, :loggers=>[Logger.new($stdout)])
|
9
9
|
#[CityPair,CityCost].each {|model| model.db = DB}
|
10
|
-
[
|
10
|
+
[TripLeg,FlightLogExpense].each {|model| model.db = DB}
|
11
|
+
#[Vendor].each {|model| model.db = DB}
|
11
12
|
#p Aircraft.first.type_id
|
12
13
|
#p [AirportFuel.min(:kid_date),AirportFuel.max(:kid_date)]
|
13
14
|
#p [TripLeg.min(:dept_date_gmt),TripLeg.max(:dept_date_gmt)]
|
14
15
|
#p [Date.from_fos_days(TripLeg.min(:dept_date_gmt)).to_s,Date.from_fos_days(TripLeg.max(:dept_date_gmt)).to_s]
|
15
|
-
p Vendor.count
|
16
|
+
#p Vendor.count
|
16
17
|
#p TripLeg.filter{kid_date > 40500}.limit(10).all.collect &:dep_fuel_vendor
|
17
18
|
#p Passenger.filter(:kid_date=>38439, :kid_time=>1428, :kid_comm=>1, :kid_mult=>0).first
|
18
19
|
#p Aircraft.filter(:kid_date=>39722).first.owner_name
|
@@ -76,7 +77,9 @@ p Vendor.count
|
|
76
77
|
#p AirportFbo.filter(:icao=>'KSFO').count
|
77
78
|
#DB.execute('Update "trip legs" set "lunch comment" = \'hi\' where "trip number" = 83100 and "leg number" = 3')
|
78
79
|
#DB.execute('Update "trip legs" set "pax count" = 4 where "trip number" = 62 and "leg number" = 1 ')
|
79
|
-
#tl = TripLeg.filter(:trip_number=>69012,:leg_number=>1).
|
80
|
+
#tl = TripLeg.filter(:trip_number=>69012,:leg_number=>1).eager_graph(:fuel_expenses).all.first
|
81
|
+
tl = TripLeg.first
|
82
|
+
p tl.fuel_expenses
|
80
83
|
#p tl.actual_arrival_date_time_gmt
|
81
84
|
#date = TripLeg.filter(:arr_date_act_gmt=>0).filter{:verify_date >0}.order(:kid_date).last.kid_date # :arrival_date_gmt
|
82
85
|
#p Date.from_fos_days(date).to_s
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 36
|
9
|
+
version: 0.5.36
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Daniel Sudol
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-16 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|