hanami-model 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +44 -0
- data/README.md +54 -420
- data/hanami-model.gemspec +9 -6
- data/lib/hanami/entity.rb +107 -191
- data/lib/hanami/entity/schema.rb +236 -0
- data/lib/hanami/model.rb +52 -138
- data/lib/hanami/model/association.rb +37 -0
- data/lib/hanami/model/associations/belongs_to.rb +19 -0
- data/lib/hanami/model/associations/dsl.rb +29 -0
- data/lib/hanami/model/associations/has_many.rb +200 -0
- data/lib/hanami/model/configuration.rb +52 -224
- data/lib/hanami/model/configurator.rb +62 -0
- data/lib/hanami/model/entity_name.rb +35 -0
- data/lib/hanami/model/error.rb +37 -24
- data/lib/hanami/model/mapping.rb +29 -35
- data/lib/hanami/model/migration.rb +31 -0
- data/lib/hanami/model/migrator.rb +111 -88
- data/lib/hanami/model/migrator/adapter.rb +39 -16
- data/lib/hanami/model/migrator/connection.rb +23 -11
- data/lib/hanami/model/migrator/mysql_adapter.rb +38 -17
- data/lib/hanami/model/migrator/postgres_adapter.rb +20 -19
- data/lib/hanami/model/migrator/sqlite_adapter.rb +9 -8
- data/lib/hanami/model/plugins.rb +25 -0
- data/lib/hanami/model/plugins/mapping.rb +55 -0
- data/lib/hanami/model/plugins/schema.rb +55 -0
- data/lib/hanami/model/plugins/timestamps.rb +118 -0
- data/lib/hanami/model/relation_name.rb +24 -0
- data/lib/hanami/model/sql.rb +161 -0
- data/lib/hanami/model/sql/console.rb +41 -0
- data/lib/hanami/model/sql/consoles/abstract.rb +33 -0
- data/lib/hanami/model/sql/consoles/mysql.rb +63 -0
- data/lib/hanami/model/sql/consoles/postgresql.rb +68 -0
- data/lib/hanami/model/sql/consoles/sqlite.rb +46 -0
- data/lib/hanami/model/sql/entity/schema.rb +125 -0
- data/lib/hanami/model/sql/types.rb +95 -0
- data/lib/hanami/model/sql/types/schema/coercions.rb +198 -0
- data/lib/hanami/model/types.rb +99 -0
- data/lib/hanami/model/version.rb +1 -1
- data/lib/hanami/repository.rb +287 -723
- metadata +77 -40
- data/EXAMPLE.md +0 -213
- data/lib/hanami/entity/dirty_tracking.rb +0 -74
- data/lib/hanami/model/adapters/abstract.rb +0 -281
- data/lib/hanami/model/adapters/file_system_adapter.rb +0 -288
- data/lib/hanami/model/adapters/implementation.rb +0 -111
- data/lib/hanami/model/adapters/memory/collection.rb +0 -132
- data/lib/hanami/model/adapters/memory/command.rb +0 -113
- data/lib/hanami/model/adapters/memory/query.rb +0 -653
- data/lib/hanami/model/adapters/memory_adapter.rb +0 -179
- data/lib/hanami/model/adapters/null_adapter.rb +0 -24
- data/lib/hanami/model/adapters/sql/collection.rb +0 -287
- data/lib/hanami/model/adapters/sql/command.rb +0 -88
- data/lib/hanami/model/adapters/sql/console.rb +0 -33
- data/lib/hanami/model/adapters/sql/consoles/mysql.rb +0 -49
- data/lib/hanami/model/adapters/sql/consoles/postgresql.rb +0 -48
- data/lib/hanami/model/adapters/sql/consoles/sqlite.rb +0 -26
- data/lib/hanami/model/adapters/sql/query.rb +0 -788
- data/lib/hanami/model/adapters/sql_adapter.rb +0 -296
- data/lib/hanami/model/coercer.rb +0 -74
- data/lib/hanami/model/config/adapter.rb +0 -116
- data/lib/hanami/model/config/mapper.rb +0 -45
- data/lib/hanami/model/mapper.rb +0 -124
- data/lib/hanami/model/mapping/attribute.rb +0 -85
- data/lib/hanami/model/mapping/coercers.rb +0 -314
- data/lib/hanami/model/mapping/collection.rb +0 -490
- data/lib/hanami/model/mapping/collection_coercer.rb +0 -79
@@ -1,79 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
module Model
|
3
|
-
module Mapping
|
4
|
-
# Translates values from/to the database with the corresponding Ruby type.
|
5
|
-
#
|
6
|
-
# @api private
|
7
|
-
# @since 0.1.0
|
8
|
-
class CollectionCoercer
|
9
|
-
# Initialize a coercer for the given collection.
|
10
|
-
#
|
11
|
-
# @param collection [Hanami::Model::Mapping::Collection] the collection
|
12
|
-
#
|
13
|
-
# @api private
|
14
|
-
# @since 0.1.0
|
15
|
-
def initialize(collection)
|
16
|
-
@collection = collection
|
17
|
-
_compile!
|
18
|
-
end
|
19
|
-
|
20
|
-
# Translates the given entity into a format compatible with the database.
|
21
|
-
#
|
22
|
-
# @param entity [Object] the entity
|
23
|
-
#
|
24
|
-
# @return [Hash]
|
25
|
-
#
|
26
|
-
# @api private
|
27
|
-
# @since 0.1.0
|
28
|
-
def to_record(entity)
|
29
|
-
end
|
30
|
-
|
31
|
-
# Translates the given record into a Ruby object.
|
32
|
-
#
|
33
|
-
# @param record [Hash]
|
34
|
-
#
|
35
|
-
# @return [Object]
|
36
|
-
#
|
37
|
-
# @api private
|
38
|
-
# @since 0.1.0
|
39
|
-
def from_record(record)
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
# Compile itself for performance boost.
|
44
|
-
#
|
45
|
-
# @api private
|
46
|
-
# @since 0.1.0
|
47
|
-
def _compile!
|
48
|
-
code = @collection.attributes.map do |_,attr|
|
49
|
-
%{
|
50
|
-
def deserialize_#{ attr.mapped }(value)
|
51
|
-
#{ attr.load_coercer }(value)
|
52
|
-
end
|
53
|
-
}
|
54
|
-
end.join("\n")
|
55
|
-
|
56
|
-
instance_eval <<-EVAL, __FILE__, __LINE__
|
57
|
-
def to_record(entity)
|
58
|
-
if entity.id
|
59
|
-
Hash[#{ @collection.attributes.map{|name,attr| ":#{ attr.mapped },#{ attr.dump_coercer }(entity.#{name})"}.join(',') }]
|
60
|
-
else
|
61
|
-
Hash[].tap do |record|
|
62
|
-
#{ @collection.attributes.reject{|name,_| name == @collection.identity }.map{|name,attr| "value = #{ attr.dump_coercer }(entity.#{name}); record[:#{attr.mapped}] = value unless value.nil?"}.join('; ') }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def from_record(record)
|
68
|
-
::#{ @collection.entity }.new(
|
69
|
-
Hash[#{ @collection.attributes.map{|name,attr| ":#{name},#{attr.load_coercer}(record[:#{attr.mapped}])"}.join(',') }]
|
70
|
-
)
|
71
|
-
end
|
72
|
-
|
73
|
-
#{ code }
|
74
|
-
EVAL
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|