utusemi 0.0.4 → 0.0.5
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.
- checksums.yaml +4 -4
- data/lib/utusemi.rb +5 -11
- data/lib/utusemi/core.rb +16 -9
- data/lib/utusemi/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d2f1842ad1590bc9ffd7d86284f73621e09dc98
|
4
|
+
data.tar.gz: 879c977d5859077234e3cf4cab9f1f0e404bab36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21680f17fc9aec12a3ff2c82afcdd3ef7ebe15008e35c4d9c399d56df6ad9987f3badb1ee132d244f48e13394ef2de9dad290da2e0bd80faf1935c937a315c7d
|
7
|
+
data.tar.gz: b40a9ac874264953470c9ca404012c0370fd84d211f8a3197b011ca3bdb37c97fe0f11fb95626ec0ccd504a14cb400a4ac3201e0252f0a0ad8b24d1ca867039c
|
data/lib/utusemi.rb
CHANGED
@@ -15,7 +15,7 @@ module Utusemi
|
|
15
15
|
# for model and relation
|
16
16
|
this.prepend_to_activerecord_base
|
17
17
|
this.prepend_to_activerecord_relation
|
18
|
-
this.
|
18
|
+
this.prepend_to_activerecord_singleton_class
|
19
19
|
this.prepend_to_activerecord_associations_hasmanyassociation
|
20
20
|
this.prepend_to_activerecord_associations_collectionproxy
|
21
21
|
end
|
@@ -43,12 +43,12 @@ module Utusemi
|
|
43
43
|
ActiveRecord::Relation.send(:prepend, Core::ActiveRecord::Relation)
|
44
44
|
end
|
45
45
|
|
46
|
-
def
|
47
|
-
|
46
|
+
def prepend_to_activerecord_singleton_class
|
47
|
+
ActiveRecord::Base.singleton_class.send(:prepend, Core::ActiveRecord::Base::ClassMethods)
|
48
48
|
# for rails 3.x
|
49
|
-
|
49
|
+
ActiveRecord::Base.singleton_class.send(:prepend, Core::ActiveRecord::RelationMethod) if Rails::VERSION::MAJOR == 3
|
50
50
|
# for association
|
51
|
-
|
51
|
+
ActiveRecord::Base.singleton_class.send(:prepend, Core::ActiveRecord::AssociationMethods)
|
52
52
|
end
|
53
53
|
|
54
54
|
def prepend_to_activerecord_associations_hasmanyassociation
|
@@ -58,11 +58,5 @@ module Utusemi
|
|
58
58
|
def prepend_to_activerecord_associations_collectionproxy
|
59
59
|
ActiveRecord::Associations::CollectionProxy.send(:prepend, Core::ActiveRecord::CollectionProxy) if Rails::VERSION::MAJOR == 3
|
60
60
|
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def activerecord_eigenclass
|
65
|
-
ActiveRecord::Base.class_eval { class << self; self; end }
|
66
|
-
end
|
67
61
|
end
|
68
62
|
end
|
data/lib/utusemi/core.rb
CHANGED
@@ -15,7 +15,9 @@ module Utusemi
|
|
15
15
|
#
|
16
16
|
module Base
|
17
17
|
def utusemi_values
|
18
|
-
@utusemi_values
|
18
|
+
utusemi_values = @utusemi_values || {}
|
19
|
+
utusemi_values = klass_utusemi_values unless utusemi_values[:flag]
|
20
|
+
utusemi_values
|
19
21
|
end
|
20
22
|
|
21
23
|
def utusemi(obj = nil, options = {})
|
@@ -24,10 +26,11 @@ module Utusemi
|
|
24
26
|
|
25
27
|
def utusemi!(obj = nil, options = {})
|
26
28
|
obj = true if obj.nil?
|
27
|
-
utusemi_values
|
28
|
-
utusemi_values[:
|
29
|
-
utusemi_values[:type]
|
30
|
-
utusemi_values[:
|
29
|
+
@utusemi_values ||= {}
|
30
|
+
@utusemi_values[:flag] = obj ? true : false
|
31
|
+
@utusemi_values[:type] = obj.to_sym if obj.class.in? [Symbol, String]
|
32
|
+
@utusemi_values[:type] ||= default_utusemi_type
|
33
|
+
@utusemi_values[:options] = options
|
31
34
|
warning_checker unless Rails.env.production?
|
32
35
|
self
|
33
36
|
end
|
@@ -70,6 +73,13 @@ module Utusemi
|
|
70
73
|
self
|
71
74
|
end
|
72
75
|
end
|
76
|
+
|
77
|
+
def klass_utusemi_values
|
78
|
+
return {} unless @klass
|
79
|
+
utusemi_values = @klass.instance_variable_get(:@utusemi_values) || {}
|
80
|
+
return {} unless utusemi_values[:flag]
|
81
|
+
utusemi_values
|
82
|
+
end
|
73
83
|
end
|
74
84
|
|
75
85
|
# 用途
|
@@ -265,8 +275,6 @@ module Utusemi
|
|
265
275
|
# #=> true (= products.title)
|
266
276
|
#
|
267
277
|
def to_a
|
268
|
-
utusemi_values = self.utusemi_values
|
269
|
-
utusemi_values = @klass.utusemi_values unless utusemi_values[:flag]
|
270
278
|
return super unless utusemi_values[:flag]
|
271
279
|
super.each { |record| record.utusemi!(utusemi_values[:type], utusemi_values[:options]) }
|
272
280
|
end
|
@@ -309,8 +317,7 @@ module Utusemi
|
|
309
317
|
def association(name)
|
310
318
|
truthly_owner = self
|
311
319
|
association = super
|
312
|
-
|
313
|
-
eigenclass.send(:define_method, :truthly_owner) { truthly_owner }
|
320
|
+
association.singleton_class.send(:define_method, :truthly_owner) { truthly_owner }
|
314
321
|
association
|
315
322
|
end
|
316
323
|
end
|
data/lib/utusemi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utusemi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YOSHIDA Hiroki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|