buzztools 0.0.10 → 0.0.11

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
2
  SHA1:
3
- metadata.gz: 1eaae1e1dab86ea0752de2655f0a62b0f20662ac
4
- data.tar.gz: 113bda67b24d33fddcc40cbc4336c71acbcbe601
3
+ metadata.gz: aff31eabe68efa1e5a445bd12d0f9f396848eeb1
4
+ data.tar.gz: 2d2c6a0ade3692dd6df4a67f09a3822bea65e9f7
5
5
  SHA512:
6
- metadata.gz: 03b1c16af683d35b6aaf30f396b902cee0b89df02c58a7c2017c696bf7524558c90f59bc118ce6744f1fc42cbfff087fd0d099caa3e7d932edeabf04aea0e28b
7
- data.tar.gz: cb5dd2f7db57b298bfdbe41c8e1037d9c39dd711e1a91cb484007991383877e917ab1599b707c34e7c543eba0629d6c14e4cdf9bbec0758ae06c65e4f8f1d005
6
+ metadata.gz: 2565d3962a392389d285bf4dd57405270d41440eeda228dc4dd998c30876151bd129a212aa89545f343865b91f132169eb3d892f1c49b7e36e729b38edab1134
7
+ data.tar.gz: 752a338ddd6d7051aa953e87705239821313e8fc1a4b7fbf681343e5c08dd3a7f8a319636fda95f01fe5618c2a84c18e4229c14cf799dbaf84f842cdcf8d3738
@@ -0,0 +1,3 @@
1
+ <component name="CopyrightManager">
2
+ <settings default="" />
3
+ </component>
@@ -1,17 +1,41 @@
1
1
  Time.class_eval do
2
2
 
3
- if !respond_to?(:change) # no activesupport loaded
3
+ if !method_defined?(:change) # no activesupport loaded
4
4
  def change(options)
5
- ::Time.send(
6
- self.utc? ? :utc : :local,
7
- options[:year] || self.year,
8
- options[:month] || self.month,
9
- options[:day] || self.day,
10
- options[:hour] || self.hour,
11
- options[:min] || (options[:hour] ? 0 : self.min),
12
- options[:sec] || ((options[:hour] || options[:min]) ? 0 : self.sec),
13
- options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : self.usec)
14
- )
5
+ # ::Time.send(
6
+ # self.utc? ? :utc : :local,
7
+ # options[:year] || self.year,
8
+ # options[:month] || self.month,
9
+ # options[:day] || self.day,
10
+ # options[:hour] || self.hour,
11
+ # options[:min] || (options[:hour] ? 0 : self.min),
12
+ # options[:sec] || ((options[:hour] || options[:min]) ? 0 : self.sec),
13
+ # options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : self.usec)
14
+ # )
15
+
16
+ new_year = options.fetch(:year, year)
17
+ new_month = options.fetch(:month, month)
18
+ new_day = options.fetch(:day, day)
19
+ new_hour = options.fetch(:hour, hour)
20
+ new_min = options.fetch(:min, options[:hour] ? 0 : min)
21
+ new_sec = options.fetch(:sec, (options[:hour] || options[:min]) ? 0 : sec)
22
+
23
+ if new_nsec = options[:nsec]
24
+ raise ArgumentError, "Can't change both :nsec and :usec at the same time: #{options.inspect}" if options[:usec]
25
+ new_usec = Rational(new_nsec, 1000)
26
+ else
27
+ new_usec = options.fetch(:usec, (options[:hour] || options[:min] || options[:sec]) ? 0 : Rational(nsec, 1000))
28
+ end
29
+
30
+ if utc?
31
+ ::Time.utc(new_year, new_month, new_day, new_hour, new_min, new_sec, new_usec)
32
+ elsif zone
33
+ ::Time.local(new_year, new_month, new_day, new_hour, new_min, new_sec, new_usec)
34
+ else
35
+ raise ArgumentError, 'argument out of range' if new_usec > 999999
36
+ ::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec + (new_usec.to_r / 1000000), utc_offset)
37
+ end
38
+
15
39
  end
16
40
 
17
41
  def seconds_since_midnight
@@ -78,24 +78,17 @@ module Versionary
78
78
 
79
79
  # should be able to do eg. : TaxRate.where(owner_id: 1,dealership_id: 2).latest_versions.where(state: 'WA')
80
80
  scope :live_latest_versions, -> {
81
- inner = clone.select("iid, max(version) as version").group(:iid).to_sql
82
- ids = ActiveRecord::Base.connection.execute("select id from (#{inner}) as v inner join #{table_name} as t on t.iid = v.iid and t.version = v.version").to_a
83
- if (adapter = ActiveRecord::Base.configurations[Rails.env]['adapter'])=='postgresql'
84
- ids = ids.map{|i| i['id']}.join(',')
85
- elsif adapter.begins_with? 'mysql'
86
- ids = ids.flatten.join(',')
87
- else
88
- raise "Adapter #{adapter} not supported"
89
- end
90
-
91
- #ids = ActiveRecord::Base.connection.execute("select id from (SELECT iid, max(version) as version FROM `things` GROUP BY iid) as v inner join things as t on t.iid = v.iid and t.version = v.version").to_a.flatten.join(',')
92
- where "id IN (#{ids})"
81
+ live_current_versions(nil)
93
82
  }
94
83
 
95
84
  # Scopes to the current version for all iids at the given timestamp
96
85
  # This and other methods beginning with "live" do not use the ver_current column
86
+ # if the timestamp is nil, it will return the highest available version regardless of current_from
97
87
  scope :live_current_versions, ->(aTimestamp) {
98
- inner = clone.select("iid, max(version) as version").where(["current_from <= ?",aTimestamp]).group(:iid).to_sql
88
+ aTimestamp = aTimestamp.to_ms if aTimestamp && aTimestamp.is_a?(Time)
89
+ inner = clone.select("iid, max(version) as version")
90
+ inner = inner.where(["current_from <= ?",aTimestamp]) if aTimestamp
91
+ inner = inner.group(:iid).to_sql
99
92
  ids = ActiveRecord::Base.connection.execute("select id from (#{inner}) as v inner join #{table_name} as t on t.iid = v.iid and t.version = v.version").to_a
100
93
  if (adapter = ActiveRecord::Base.configurations[Rails.env]['adapter'])=='postgresql'
101
94
  ids = ids.map{|i| i['id']}.join(',')
@@ -126,6 +119,7 @@ module Versionary
126
119
 
127
120
  # Updates the ver_current column, which enables simpler and much faster queries on current versions eg. using current_versions instead of live_current_versions.
128
121
  # Must be run periodically eg. 4am daily
122
+ # !!! probably should do something like this after every create_version!
129
123
  def self.update_all_ver_current
130
124
  self.update_all(ver_current: false)
131
125
  self.live_current_versions(Time.now.to_ms).update_all(ver_current: true)
@@ -161,4 +155,8 @@ module Versionary
161
155
  def current_version
162
156
  self.class.live_current_version(self.iid,KojacUtils.timestamp).first
163
157
  end
158
+
159
+ def versions
160
+ self.class.where(iid: iid).order(:version)
161
+ end
164
162
  end
@@ -93,9 +93,17 @@ module Buzztools
93
93
  path_combine(aBasePath,aPath)
94
94
  end
95
95
 
96
+ def is_root_path?(aPath)
97
+ # if is_windows?
98
+ # (aPath =~ /^[a-zA-Z]\:[\\\/]$/)==0
99
+ # else
100
+ aPath == '/'
101
+ # end
102
+ end
103
+
96
104
  def path_parent(aPath)
97
105
  return nil if is_root_path?(aPath)
98
- append_slash(::File.dirname(remove_slash(expand_path(aPath))))
106
+ append_slash(::File.dirname(remove_slash(::File.expand_path(aPath))))
99
107
  end
100
108
 
101
109
  def simple_dir_name(aPath)
@@ -129,4 +137,4 @@ module Buzztools
129
137
  end
130
138
 
131
139
  end
132
- end
140
+ end
@@ -1,3 +1,3 @@
1
1
  module Buzztools
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: buzztools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gary McGhee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-10 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
+ - ".idea/copyright/profiles_settings.xml"
49
50
  - Gemfile
50
51
  - LICENSE.txt
51
52
  - README.md
@@ -88,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
89
  version: '0'
89
90
  requirements: []
90
91
  rubyforge_project:
91
- rubygems_version: 2.4.6
92
+ rubygems_version: 2.4.8
92
93
  signing_key:
93
94
  specification_version: 4
94
95
  summary: reusable function library