utusemi 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/lib/utusemi.rb +2 -1
- data/lib/utusemi/configuration.rb +6 -3
- data/lib/utusemi/core.rb +57 -29
- data/lib/utusemi/version.rb +1 -1
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0de35704b1f48b29fd9b17d6cfcde7b3a4b58dae
|
4
|
+
data.tar.gz: c45997636abef147456bce3644560253359aed76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aa10b9e42f0b726d46e0cce55d93fecaede375ef93783dd70d3c6a26b7fda39a4ec25a46f899c4c104dffd7743d69f208c1e1079ec8fdca1752c2ae6ff1cfeb5
|
7
|
+
data.tar.gz: 274d391ef5645427c30ff4c8911c3b4978c953842161be256ed88dd085974fb1cf5b6c761bb38437b90480dffe0286020be859249b25b0813bc8254b7c37e458
|
data/MIT-LICENSE
CHANGED
data/lib/utusemi.rb
CHANGED
@@ -29,6 +29,7 @@ module Utusemi
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def include_to_activerecord_base
|
32
|
+
# TODO: Organize name spaces
|
32
33
|
ActiveRecord::Base.send(:include, Core::InstanceMethods)
|
33
34
|
end
|
34
35
|
|
@@ -42,7 +43,7 @@ module Utusemi
|
|
42
43
|
end
|
43
44
|
|
44
45
|
def prepend_to_activerecord_eigenclass
|
45
|
-
activerecord_eigenclass.send(:prepend, Core::ActiveRecord::
|
46
|
+
activerecord_eigenclass.send(:prepend, Core::ActiveRecord::Base::ClassMethods)
|
46
47
|
# for rails 3.x
|
47
48
|
activerecord_eigenclass.send(:prepend, Core::ActiveRecord::RelationMethod) if Rails::VERSION::MAJOR == 3
|
48
49
|
# for association
|
@@ -5,6 +5,7 @@ module Utusemi
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def map(name, *args, &block)
|
8
|
+
name = (name || '').to_sym
|
8
9
|
return map_get(name, *args) unless block_given?
|
9
10
|
options = args.shift if args.first.is_a? Hash
|
10
11
|
map_set(name, options, &block)
|
@@ -13,12 +14,14 @@ module Utusemi
|
|
13
14
|
private
|
14
15
|
|
15
16
|
def map_set(name, options, &block)
|
16
|
-
@maps[name
|
17
|
+
@maps[name] = {}
|
18
|
+
@maps[name].update(options) if options
|
19
|
+
@maps[name].update(block: block)
|
17
20
|
end
|
18
21
|
|
19
22
|
def map_get(name, *args)
|
20
|
-
map = @maps[name
|
21
|
-
block = map.delete(:block)
|
23
|
+
map = @maps[name].try(:dup) || {}
|
24
|
+
block = map.delete(:block)
|
22
25
|
definition = Definition.new(map)
|
23
26
|
definition.exec(*args, &block)
|
24
27
|
end
|
data/lib/utusemi/core.rb
CHANGED
@@ -132,19 +132,21 @@ module Utusemi
|
|
132
132
|
# #=> [<products.titleが"test"であるレコード>]
|
133
133
|
#
|
134
134
|
module ActiveRecord
|
135
|
-
module
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
135
|
+
module Base
|
136
|
+
module ClassMethods
|
137
|
+
include Utusemi::Core::Base
|
138
|
+
|
139
|
+
case Rails::VERSION::MAJOR
|
140
|
+
when 4
|
141
|
+
delegate :utusemi, to: :all
|
142
|
+
when 3
|
143
|
+
delegate :utusemi, to: :scoped
|
144
|
+
end
|
143
145
|
end
|
144
146
|
end
|
145
147
|
|
146
148
|
module QueryMethods
|
147
|
-
include Base
|
149
|
+
include Utusemi::Core::Base
|
148
150
|
|
149
151
|
def utusemi!(obj = nil, options = {})
|
150
152
|
super.tap { warning_checker unless Rails.env.production? }
|
@@ -264,6 +266,25 @@ module Utusemi
|
|
264
266
|
utusemi!(utusemi_values[:type], utusemi_values[:options]) if utusemi_values[:flag]
|
265
267
|
super
|
266
268
|
end
|
269
|
+
|
270
|
+
# 用途
|
271
|
+
# cloneでは浅いコピーしか行われず@utusemi_valuesの内容が
|
272
|
+
# 書き変わってしまうので、これを解決するために@utusemi_valuesもdupする
|
273
|
+
def initialize_copy(original_obj)
|
274
|
+
@utusemi_values = original_obj.utusemi_values.dup
|
275
|
+
super
|
276
|
+
end
|
277
|
+
|
278
|
+
# 用途
|
279
|
+
# association_cacheの影響でAssociation#ownerでclone前のインスタンスしか取得できないため
|
280
|
+
# 別経路から実際の呼び出し元インスタンスを参照できるようにし、utusemi_valuesを取り出せるようにする
|
281
|
+
def association(name)
|
282
|
+
truthly_owner = self
|
283
|
+
association = super
|
284
|
+
eigenclass = class << association; self; end
|
285
|
+
eigenclass.send(:define_method, :truthly_owner) { truthly_owner }
|
286
|
+
association
|
287
|
+
end
|
267
288
|
end
|
268
289
|
|
269
290
|
# 用途
|
@@ -280,35 +301,29 @@ module Utusemi
|
|
280
301
|
#
|
281
302
|
module Associations
|
282
303
|
def scope(*args)
|
283
|
-
utusemi_values =
|
304
|
+
utusemi_values = truthly_owner.utusemi_values
|
284
305
|
return super unless utusemi_values[:flag]
|
285
306
|
super.utusemi!(@reflection.name.to_s.singularize, utusemi_values[:options])
|
286
307
|
end
|
308
|
+
|
309
|
+
def load_target(*args)
|
310
|
+
utusemi_values = truthly_owner.utusemi_values
|
311
|
+
return super unless utusemi_values[:flag]
|
312
|
+
super.each { |record| record.utusemi!(@reflection.name.to_s.singularize, utusemi_values[:options]) }
|
313
|
+
end
|
287
314
|
end
|
288
315
|
|
289
316
|
module AssociationMethods
|
290
|
-
def belongs_to(name,
|
291
|
-
|
292
|
-
utusemi_flag = scope.try(:delete, :utusemi)
|
293
|
-
scope = utusemi_association_scope(:belongs_to, name, scope) if utusemi_flag
|
294
|
-
super if !utusemi_flag || !method_defined?(name)
|
295
|
-
define_utusemi_association_reader(name, utusemi_flag => true)
|
317
|
+
def belongs_to(name, *args)
|
318
|
+
utusemi_association(:belongs_to, name, *args) { |*a| super(*a) }
|
296
319
|
end
|
297
320
|
|
298
|
-
def has_one(name,
|
299
|
-
|
300
|
-
utusemi_flag = scope.try(:delete, :utusemi)
|
301
|
-
scope = utusemi_association_scope(:has_one, name, scope) if utusemi_flag
|
302
|
-
super if !utusemi_flag || !method_defined?(name)
|
303
|
-
define_utusemi_association_reader(name, utusemi_flag => true)
|
321
|
+
def has_one(name, *args)
|
322
|
+
utusemi_association(:has_one, name, *args) { |*a| super(*a) }
|
304
323
|
end
|
305
324
|
|
306
|
-
def has_many(name,
|
307
|
-
|
308
|
-
utusemi_flag = scope.try(:delete, :utusemi)
|
309
|
-
scope = utusemi_association_scope(:has_many, name, scope) if utusemi_flag
|
310
|
-
super if !utusemi_flag || !method_defined?(name)
|
311
|
-
define_utusemi_association_reader(name, utusemi_flag => true)
|
325
|
+
def has_many(name, *args)
|
326
|
+
utusemi_association(:has_many, name, *args) { |*a| super(*a) }
|
312
327
|
end
|
313
328
|
|
314
329
|
private
|
@@ -320,7 +335,20 @@ module Utusemi
|
|
320
335
|
Rails.logger.warn "[Utusemi:WARNING] \"#{association_type} :#{name}\" is duplicated in #{self.name}."
|
321
336
|
end
|
322
337
|
|
323
|
-
def
|
338
|
+
def utusemi_association(association_type, name, *args)
|
339
|
+
if args.empty?
|
340
|
+
yield name, *args
|
341
|
+
return define_utusemi_association_reader(name)
|
342
|
+
end
|
343
|
+
scope = args.shift
|
344
|
+
check_deplicated_association_warning(association_type, name, scope)
|
345
|
+
utusemi_flag = scope.try(:delete, :utusemi)
|
346
|
+
scope = utusemi_association_scope(association_type, name, scope) if utusemi_flag
|
347
|
+
yield name, scope, *args if !utusemi_flag || !method_defined?(name)
|
348
|
+
define_utusemi_association_reader(name, utusemi_flag => true)
|
349
|
+
end
|
350
|
+
|
351
|
+
def utusemi_association_scope(method_name, name, scope)
|
324
352
|
utusemi_map = Utusemi.config.map(name.to_s.singularize)
|
325
353
|
default_scope = { class_name: utusemi_map.class_name }
|
326
354
|
default_scope[:foreign_key] = utusemi_map.foreign_key if method_name == :belongs_to
|
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.2
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: byebug
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry-rails
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - '>='
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
111
139
|
description: Providing a flexible alias for column names in ActiveRecord.
|
112
140
|
email:
|
113
141
|
- hyoshida@appirits.com
|