active_any 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_any.rb +0 -1
- data/lib/active_any/adapters/abstract_adapter.rb +7 -1
- data/lib/active_any/attribute.rb +2 -2
- data/lib/active_any/base.rb +17 -12
- data/lib/active_any/relation/where_clause.rb +5 -3
- data/lib/active_any/version.rb +1 -1
- metadata +1 -2
- data/lib/active_any/adapter.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8f0f6be0c590ca667a1c62e6b24c2354597201c
|
4
|
+
data.tar.gz: 8895030ab834a80199bfd73dce24d33b86a21ad6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b003bd481d71a28fff409b1bf50148ee1a1b026bc9a404570de84ded22769e42fadf81c96b5006e82b4ee68a254e15cf477a976feef36da68e3514e6f2032218
|
7
|
+
data.tar.gz: dfbf059cd768d49f45a23aa1bc36af8f2048067616b832e41d99d404fb712820914cb69f9009e51c40022f4ef54d38e742071208a234450f4c73833f9d528b68
|
data/lib/active_any.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveAny
|
4
|
-
class AbstractAdapter
|
4
|
+
class AbstractAdapter
|
5
|
+
attr_reader :klass
|
6
|
+
|
7
|
+
def initialize(klass)
|
8
|
+
@klass = klass
|
9
|
+
end
|
10
|
+
|
5
11
|
%i[base_hander regexp_handler range_handler array_handler].each do |method|
|
6
12
|
define_method method do |_record, _key, value|
|
7
13
|
raise NotImplementedError.new, "#{self.class.name} can not handle for #{value.class}"
|
data/lib/active_any/attribute.rb
CHANGED
@@ -59,12 +59,12 @@ module ActiveAny
|
|
59
59
|
|
60
60
|
def define_reader_method(name)
|
61
61
|
define_method name do
|
62
|
-
attributes.fetch(name)
|
62
|
+
attributes.fetch(name, nil)
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
def has_attribute?(attribute)
|
67
|
-
attribute_names.
|
67
|
+
attribute_names.include?(attribute)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
end
|
data/lib/active_any/base.rb
CHANGED
@@ -14,8 +14,10 @@ module ActiveAny
|
|
14
14
|
end
|
15
15
|
|
16
16
|
class Object < Base
|
17
|
+
self.abstract_class = true
|
18
|
+
|
17
19
|
def self.inherited(child)
|
18
|
-
child.abstract_class =
|
20
|
+
child.abstract_class = false
|
19
21
|
end
|
20
22
|
|
21
23
|
class << self
|
@@ -28,9 +30,7 @@ module ActiveAny
|
|
28
30
|
end
|
29
31
|
|
30
32
|
class Hash < Base
|
31
|
-
|
32
|
-
child.abstract_class = true
|
33
|
-
end
|
33
|
+
self.abstract_class = true
|
34
34
|
|
35
35
|
class << self
|
36
36
|
attr_reader :data
|
@@ -50,28 +50,33 @@ module ActiveAny
|
|
50
50
|
end
|
51
51
|
|
52
52
|
class CSV < Base
|
53
|
-
|
54
|
-
child.abstract_class = true
|
55
|
-
end
|
53
|
+
self.abstract_class = true
|
56
54
|
|
57
55
|
class MissingFileError; end
|
58
56
|
|
59
57
|
class << self
|
60
|
-
|
58
|
+
attr_reader :file
|
59
|
+
|
60
|
+
def file=(file)
|
61
|
+
csv = ::CSV.new(file, headers: true)
|
62
|
+
headers = csv.first
|
63
|
+
headers.each { |header| attribute header }
|
64
|
+
end
|
61
65
|
|
62
66
|
def data
|
63
67
|
@data ||= begin
|
64
68
|
raise MissingFileError unless file
|
65
69
|
|
66
70
|
table = ::CSV.table(file)
|
67
|
-
table.headers.each do |header|
|
68
|
-
attribute header
|
69
|
-
end
|
70
|
-
|
71
71
|
table.map { |row| new(row.to_h) }
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
+
def reload
|
76
|
+
@data = nil
|
77
|
+
data
|
78
|
+
end
|
79
|
+
|
75
80
|
def adapter
|
76
81
|
@adapter ||= ObjectAdapter.new(self)
|
77
82
|
end
|
@@ -16,7 +16,7 @@ module ActiveAny
|
|
16
16
|
register_handler(Array, :array_handler)
|
17
17
|
end
|
18
18
|
|
19
|
-
def evaluate(adapter, record)
|
19
|
+
def evaluate(adapter, record = nil)
|
20
20
|
adapter.public_send(handle_for(value), record, key, value)
|
21
21
|
end
|
22
22
|
|
@@ -65,8 +65,10 @@ module ActiveAny
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
|
69
|
-
|
68
|
+
include Enumerable
|
69
|
+
|
70
|
+
def each(&block)
|
71
|
+
conditions.each(&block)
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
data/lib/active_any/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_any
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yuemori
|
@@ -199,7 +199,6 @@ files:
|
|
199
199
|
- bin/console
|
200
200
|
- bin/setup
|
201
201
|
- lib/active_any.rb
|
202
|
-
- lib/active_any/adapter.rb
|
203
202
|
- lib/active_any/adapters/abstract_adapter.rb
|
204
203
|
- lib/active_any/adapters/object_adapter.rb
|
205
204
|
- lib/active_any/association_relation.rb
|