@@ -2,58 +2,48 @@ module RedmineGtt
2
2
module Patches
3
3
4
4
module UserPatch
5
- def self . included ( base )
6
- base . extend ( ClassMethods )
7
- base . send ( :include , InstanceMethods )
8
- base . class_eval do
9
- unloadable
5
+ def self . apply
6
+ User . prepend self unless User < self
7
+ User . class_eval do
10
8
safe_attributes "geom"
11
9
end
12
10
end
13
11
14
- module ClassMethods
15
- end
16
-
17
- module InstanceMethods
18
- def geojson
19
- unless self . geom . nil?
20
- factory = RGeo ::GeoJSON ::EntityFactory . instance
21
- wkb = RGeo ::WKRep ::WKBParser . new (
22
- :support_ewkb => true ,
23
- :default_srid => 4326
24
- ) . parse ( self . geom )
25
- properties = self . as_json ( { except : [
26
- :hashed_password , :hashed_password , :salt , :must_change_passwd ,
27
- :passwd_changed_on , :auth_source_id , :geom
28
- ] } )
29
- RGeo ::GeoJSON . encode factory . feature ( wkb , self . id , properties )
30
- else
31
- nil
32
- end
12
+ def geojson
13
+ unless self . geom . nil?
14
+ factory = RGeo ::GeoJSON ::EntityFactory . instance
15
+ wkb = RGeo ::WKRep ::WKBParser . new (
16
+ :support_ewkb => true ,
17
+ :default_srid => 4326
18
+ ) . parse ( self . geom )
19
+ properties = self . as_json ( { except : [
20
+ :hashed_password , :hashed_password , :salt , :must_change_passwd ,
21
+ :passwd_changed_on , :auth_source_id , :geom
22
+ ] } )
23
+ RGeo ::GeoJSON . encode factory . feature ( wkb , self . id , properties )
24
+ else
25
+ nil
33
26
end
27
+ end
34
28
35
- def geom = ( g )
36
- # Turn geometry attribute into WKB for database use
37
- if ( g . present? )
38
- geojson = JSON . parse ( g )
39
- feature = RGeo ::GeoJSON . decode ( geojson , json_parser : :json )
29
+ def geom = ( g )
30
+ # Turn geometry attribute into WKB for database use
31
+ if ( g . present? )
32
+ geojson = JSON . parse ( g )
33
+ feature = RGeo ::GeoJSON . decode ( geojson , json_parser : :json )
40
34
41
- ewkb = RGeo ::WKRep ::WKBGenerator . new (
42
- :type_format => :ewkb ,
43
- :emit_ewkb_srid => true ,
44
- :hex_format => true
45
- )
46
- self [ :geom ] = ewkb . generate ( feature . geometry )
47
- else
48
- self [ :geom ] = nil
49
- end
35
+ ewkb = RGeo ::WKRep ::WKBGenerator . new (
36
+ :type_format => :ewkb ,
37
+ :emit_ewkb_srid => true ,
38
+ :hex_format => true
39
+ )
40
+ self [ :geom ] = ewkb . generate ( feature . geometry )
41
+ else
42
+ self [ :geom ] = nil
50
43
end
51
44
end
52
45
53
46
end
54
47
end
55
48
end
56
49
57
- unless User . included_modules . include? ( RedmineGtt ::Patches ::UserPatch )
58
- User . send ( :include , RedmineGtt ::Patches ::UserPatch )
59
- end
0 commit comments