backframe 0.0.25 → 0.0.26

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: cc3320f6d64afafe3208ac49dc236168f0aa2a94
4
- data.tar.gz: 68b6f22bd6111cab616b14a2df5e79586d635710
3
+ metadata.gz: cfcf5e14728ebdb5a5e975a9965e9760777c5a2c
4
+ data.tar.gz: 48f5456543ca36ef8e959f0a0686320326b7d697
5
5
  SHA512:
6
- metadata.gz: 261fd39a46c53abf6ee19a4b8d059ec5f45d85f75a86945c4df773e676de9031b51bf0f010a1bc30388c57d7fca34c4762ada986d50192b20dad6354911f7037
7
- data.tar.gz: 5b1d411b3fe134d163bf86942aff506ba49c58757a4cc3927c0635f0a8497eb0d17df4db4836340b7f8838e867058f439b256326ca2b86a9c9b78d046a7b6fdc
6
+ metadata.gz: 1e51424f4614b555cb2e26479b39915954db466294892d199cf8edccac048b4642262f920f85c179cd481991d89f7602bd824ab3ccf2df2bf8a1ee3a9da010c1
7
+ data.tar.gz: c1e301e15b94d9306dcde58017895dcf43736a1c0373f9095770eb44288a0a53d60be7356a9590fa327e15aedc53237c9191c0c622657371a5fda9be6f09815a
@@ -52,8 +52,7 @@ module Backframe
52
52
  if @item.respond_to?(:activities)
53
53
  Activity.create!(subject: current_user, text: 'updated {object1}', object1: @item)
54
54
  end
55
-
56
- render json: @item, adapter: Backframe::ActsAsAPI::Adapter
55
+ render json: @item
57
56
  else
58
57
  resource_error_response(@item, 422)
59
58
  end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ module Backframe
4
+ module ActsAsPercent
5
+
6
+ extend ActiveSupport::Concern
7
+
8
+ def self.included(base)
9
+ base.send :extend, ClassMethods
10
+ end
11
+
12
+ module ClassMethods
13
+
14
+ def acts_as_percent(entity)
15
+
16
+ class_eval <<-EOV
17
+
18
+ after_initialize :uncast_percent_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
19
+ before_save :cast_percent_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
20
+ after_save :uncast_percent_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
21
+
22
+ def raw_#{entity}
23
+ self.#{entity} / 100.00
24
+ end
25
+
26
+ private
27
+
28
+ def uncast_percent_#{entity}
29
+ self.#{entity} = self.#{entity} * 100.00
30
+ end
31
+
32
+ def cast_percent_#{entity}
33
+ self.#{entity} = self.#{entity} / 100.00
34
+ end
35
+
36
+ EOV
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+ end
44
+
45
+
46
+
@@ -17,22 +17,24 @@ module Backframe
17
17
 
18
18
  class_eval <<-EOV
19
19
 
20
- after_initialize :extract_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
21
- before_save :compress_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
20
+ after_initialize :uncast_phone_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
21
+ before_save :cast_phone_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
22
+ after_save :uncast_phone_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
23
+
24
+ validate :validates_phone_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
22
25
 
23
- validate :validates_#{entity}, :if => Proc.new { |c| c.#{entity}.present? }
24
26
  private
25
27
 
26
- def extract_#{entity}
28
+ def uncast_phone_#{entity}
27
29
  self.#{entity} = Phony.format(self.#{entity}, :format => '%{ndc}-%{local}')
28
30
  end
29
31
 
30
- def compress_#{entity}
32
+ def cast_phone_#{entity}
31
33
  self.#{entity} = Phony.normalize(self.#{entity})
32
34
  self.#{entity} = '1'+self.#{entity} if (self.#{entity}.length == 10)
33
35
  end
34
36
 
35
- def validates_#{entity}
37
+ def validates_phone_#{entity}
36
38
  testvalue = Phony.normalize(self.#{entity})
37
39
  testvalue = '1'+test if (testvalue.length == 10)
38
40
  if Phony.plausible?(testvalue)
@@ -64,8 +64,9 @@ module Backframe
64
64
  sortfields["#{association_name}.#{column.name}"] = "\"#{association_name}\".\"#{column.name}\""
65
65
  end
66
66
  end
67
- key = (key.present? && sortfields.has_key?(key)) ? key : 'created_at'
68
- order = (order.present?) ? order : 'desc'
67
+
68
+ key = (key.present? && sortfields.has_key?(key)) ? key : default_key
69
+ order = (order.present?) ? order : default_order
69
70
  if parts = key.match(/(\w*)\.(\w*)/)
70
71
  relation = relation.joins(sortjoins[parts[1]])
71
72
  end
@@ -12,6 +12,7 @@ module Backframe
12
12
  ActiveRecord::Base.send(:include, Backframe::ActsAsDistinct)
13
13
  ActiveRecord::Base.send(:include, Backframe::ActsAsEnum)
14
14
  ActiveRecord::Base.send(:include, Backframe::ActsAsOrderable)
15
+ ActiveRecord::Base.send(:include, Backframe::ActsAsPercent)
15
16
  ActiveRecord::Base.send(:include, Backframe::ActsAsPhone)
16
17
  ActiveRecord::Base.send(:include, Backframe::ActsAsUser)
17
18
  ActiveRecord::Base.send(:include, Backframe::DefaultValues)
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Backframe
4
- VERSION = '0.0.25'
4
+ VERSION = '0.0.26'
5
5
  end
data/lib/backframe.rb CHANGED
@@ -14,6 +14,7 @@ require 'backframe/activerecord/acts_as_activable'
14
14
  require 'backframe/activerecord/acts_as_distinct'
15
15
  require 'backframe/activerecord/acts_as_enum'
16
16
  require 'backframe/activerecord/acts_as_orderable'
17
+ require 'backframe/activerecord/acts_as_percent'
17
18
  require 'backframe/activerecord/acts_as_phone'
18
19
  require 'backframe/activerecord/acts_as_user'
19
20
  require 'backframe/activerecord/default_values'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: backframe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.25
4
+ version: 0.0.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Greg Kops
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-17 00:00:00.000000000 Z
12
+ date: 2016-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: write_xlsx
@@ -123,6 +123,7 @@ files:
123
123
  - lib/backframe/activerecord/acts_as_distinct.rb
124
124
  - lib/backframe/activerecord/acts_as_enum.rb
125
125
  - lib/backframe/activerecord/acts_as_orderable.rb
126
+ - lib/backframe/activerecord/acts_as_percent.rb
126
127
  - lib/backframe/activerecord/acts_as_phone.rb
127
128
  - lib/backframe/activerecord/acts_as_user.rb
128
129
  - lib/backframe/activerecord/default_values.rb