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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 279b90c6e9b262972d592a694e11c2c4cdf647d3
4
- data.tar.gz: 0354d6970255d9a02d01f55cb96f39908f0a36ed
3
+ metadata.gz: e8f0f6be0c590ca667a1c62e6b24c2354597201c
4
+ data.tar.gz: 8895030ab834a80199bfd73dce24d33b86a21ad6
5
5
  SHA512:
6
- metadata.gz: 593c783a30b4d63159dde062157b6c3fce66ab9f766c113c30c24eba4b35a7b9b90e75929a99a2ed57f91c7540b83dd9a7cf30ac87962eb5b767cd437b1504f2
7
- data.tar.gz: 645c5cbdc4b3458f7df80dbef582d47d90523a0f707362c5110ee973f729c66fd8949731acdba30cab8a07b3e8821bf1608011b1f975d8c0256643fa3b337126
6
+ metadata.gz: b003bd481d71a28fff409b1bf50148ee1a1b026bc9a404570de84ded22769e42fadf81c96b5006e82b4ee68a254e15cf477a976feef36da68e3514e6f2032218
7
+ data.tar.gz: dfbf059cd768d49f45a23aa1bc36af8f2048067616b832e41d99d404fb712820914cb69f9009e51c40022f4ef54d38e742071208a234450f4c73833f9d528b68
@@ -15,7 +15,6 @@ require 'active_any/finders'
15
15
  require 'active_any/core'
16
16
  require 'active_any/base'
17
17
  require 'active_any/subscriber'
18
- require 'active_any/adapter'
19
18
  require 'active_any/adapters/abstract_adapter'
20
19
  require 'active_any/adapters/object_adapter'
21
20
 
@@ -1,7 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveAny
4
- class AbstractAdapter < Adapter
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}"
@@ -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.key?(attribute)
67
+ attribute_names.include?(attribute)
68
68
  end
69
69
  end
70
70
  end
@@ -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 = true
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
- def self.inherited(child)
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
- def self.inherited(child)
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
- attr_accessor :file
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
- def all?(&block)
69
- conditions.all?(&block)
68
+ include Enumerable
69
+
70
+ def each(&block)
71
+ conditions.each(&block)
70
72
  end
71
73
  end
72
74
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveAny
4
- VERSION = '0.0.3'
4
+ VERSION = '0.0.4'
5
5
  end
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.3
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
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveAny
4
- class Adapter
5
- def initialize(klass)
6
- @klass = klass
7
- end
8
-
9
- def query(_where_clause, _limit_value)
10
- raise NotImplementedError
11
- end
12
- end
13
- end