active_any 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7c70ba8be173563a70f75ae70628ddddb8dc66b9
4
- data.tar.gz: 3b21c6608095ba05c84b2ab1256771434a567a75
3
+ metadata.gz: 279b90c6e9b262972d592a694e11c2c4cdf647d3
4
+ data.tar.gz: 0354d6970255d9a02d01f55cb96f39908f0a36ed
5
5
  SHA512:
6
- metadata.gz: 7e7c7311ed6633a140b529ce3acdadd7858e728322f15707c45a93a2980d14f271b3fd23e8f385604a1f9a3512dea1451ff00c93037d31c172762e3912c9951a
7
- data.tar.gz: d3eccc65ad03a3b637bfd49ceb52f87702a36ffc58e5b74b3c11cadf65085f2ee381b671b6fba517e01f582589b185d5367f61449aabbd20ba9d350c942a4992
6
+ metadata.gz: 593c783a30b4d63159dde062157b6c3fce66ab9f766c113c30c24eba4b35a7b9b90e75929a99a2ed57f91c7540b83dd9a7cf30ac87962eb5b767cd437b1504f2
7
+ data.tar.gz: 645c5cbdc4b3458f7df80dbef582d47d90523a0f707362c5110ee973f729c66fd8949731acdba30cab8a07b3e8821bf1608011b1f975d8c0256643fa3b337126
data/README.md CHANGED
@@ -28,7 +28,7 @@ Or install it yourself as:
28
28
 
29
29
  ```ruby
30
30
  class User < ActiveAny::Object
31
- attr_accessor :id, :name, :age
31
+ attributes :id, :name, :age
32
32
 
33
33
  self.data = [
34
34
  new(id: 1, name: 'alice', age: 20),
@@ -9,4 +9,4 @@ require_relative '../test/data'
9
9
 
10
10
  include TestData
11
11
 
12
- Pry.start(__FILE__)
12
+ Pry.start
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'csv'
4
+ require 'pathname'
5
+
3
6
  module ActiveAny
4
7
  class Base
5
8
  include Core
@@ -12,7 +15,7 @@ module ActiveAny
12
15
 
13
16
  class Object < Base
14
17
  def self.inherited(child)
15
- child.abstract_class = false
18
+ child.abstract_class = true
16
19
  end
17
20
 
18
21
  class << self
@@ -26,7 +29,7 @@ module ActiveAny
26
29
 
27
30
  class Hash < Base
28
31
  def self.inherited(child)
29
- child.abstract_class = false
32
+ child.abstract_class = true
30
33
  end
31
34
 
32
35
  class << self
@@ -45,4 +48,33 @@ module ActiveAny
45
48
  end
46
49
  end
47
50
  end
51
+
52
+ class CSV < Base
53
+ def self.inherited(child)
54
+ child.abstract_class = true
55
+ end
56
+
57
+ class MissingFileError; end
58
+
59
+ class << self
60
+ attr_accessor :file
61
+
62
+ def data
63
+ @data ||= begin
64
+ raise MissingFileError unless file
65
+
66
+ table = ::CSV.table(file)
67
+ table.headers.each do |header|
68
+ attribute header
69
+ end
70
+
71
+ table.map { |row| new(row.to_h) }
72
+ end
73
+ end
74
+
75
+ def adapter
76
+ @adapter ||= ObjectAdapter.new(self)
77
+ end
78
+ end
79
+ end
48
80
  end
@@ -51,7 +51,7 @@ module ActiveAny
51
51
  elsif other.respond_to?(:to_proc)
52
52
  instance_exec(&other)
53
53
  else
54
- raise ArgumentError, "#{other.inspect} is not an ActiveRecord::Relation"
54
+ raise ArgumentError, "#{other.inspect} is not an ActiveAny::Relation"
55
55
  end
56
56
  end
57
57
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveAny
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
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.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - yuemori