active_house 0.1.2 → 0.1.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: 750a4b2223da7e48d6385f1295885788cd09a44d
4
- data.tar.gz: 4a0211b8f81d576046032494d776dc9370bb1356
3
+ metadata.gz: 1881c335facd03315b054272bda63feb0dad94bc
4
+ data.tar.gz: 3ff3163f387c26d522c21ada86e53e428af96e6b
5
5
  SHA512:
6
- metadata.gz: 6ea35d2e76cd912abf8502448fb8c4a3f5685358f62e005c5d1671eac42102063e77cb142aab814a405ea6f8660e1a5592f2d8f5512c741f9b50be9f8ad77854
7
- data.tar.gz: eeeb5c7905db62293d8943f9cd8390fa2404902eb8866203460d5e6c46c7424f2d9b39778d24ad2d19e4b52f1d1ddb6efe5db8267cc5c5e7735acf9ffe520493
6
+ metadata.gz: 1c3855225c06b94397b6ab83ccd9eb016a49db843a423e0ccd8205c8c88a9eb41a55e56d952e68b34651ae6de5aa7eeb45244945eb95014e136b083900631e62
7
+ data.tar.gz: f95934da0a72bc53c9a95d026ae33a476eacc7718653585f44c83d5d7634a1dd125b6bd6a682c49094c207b20b7c2aa74abb6679cbc2cc7160cb0fd0394c1212
@@ -27,7 +27,7 @@ module ActiveHouse
27
27
 
28
28
  def fetch_collection
29
29
  result = connection.select_rows(to_query.squish)
30
- result.map { |row| model_class.new(row) }
30
+ result.map { |row| model_class.load!(row) }
31
31
  end
32
32
  end
33
33
  end
@@ -18,7 +18,7 @@ module ActiveHouse
18
18
  end
19
19
 
20
20
  def attribute_method?(name, is_setter, *args)
21
- (_attribute_opts.key?(name) || @_attributes.key?(name)) && (is_setter ? args.size.one? : true)
21
+ (_attribute_opts.key?(name) || @_attributes.key?(name)) && (is_setter ? args.size == 1 : true)
22
22
  end
23
23
 
24
24
  def get_attribute(name)
@@ -40,11 +40,17 @@ module ActiveHouse
40
40
  options = names.extract_options!
41
41
  names.each { |name| attributes(name, options.dup) }
42
42
  end
43
+
44
+ def load!(params)
45
+ new.tap do |model|
46
+ params.each { |name, value| model[name] = value }
47
+ end
48
+ end
43
49
  end
44
50
 
45
51
  def initialize(params = {})
46
52
  @_attributes = {}
47
- assign_attributes(params)
53
+ assign_attributes(params) unless params.nil?
48
54
  end
49
55
 
50
56
  def as_json(*_args)
@@ -59,6 +65,16 @@ module ActiveHouse
59
65
  @_attributes[key.to_sym]
60
66
  end
61
67
 
68
+ def []=(key, value)
69
+ @_attributes[key.to_sym] = value
70
+ end
71
+
72
+ def assign_attributes(params)
73
+ params.each do |key, val|
74
+ public_send("#{key}=", val)
75
+ end
76
+ end
77
+
62
78
  def respond_to_missing?(method_name, *args)
63
79
  name, is_setter = parse_attribute_method_name(method_name)
64
80
  attribute_method?(name, is_setter, *args)
@@ -12,7 +12,7 @@ module ActiveHouse
12
12
  end
13
13
 
14
14
  def connection
15
- model_klass.connection
15
+ model_class.connection
16
16
  end
17
17
 
18
18
  include ActiveHouse::Chainable
@@ -17,7 +17,8 @@ module ActiveHouse
17
17
  end
18
18
 
19
19
  def apply_default_scope
20
- apply_scope(model_class._default_scope) unless model_class._default_scope.nil?
20
+ return if model_class._default_scope.nil?
21
+ apply_scope(model_class._default_scope)
21
22
  end
22
23
  end
23
24
 
@@ -11,8 +11,8 @@ module ActiveHouse
11
11
  end
12
12
 
13
13
  class_methods do
14
- def default_scope(&block)
15
- self._default_scope = block
14
+ def default_scope(name)
15
+ self._default_scope = name.to_sym
16
16
  end
17
17
 
18
18
  def scope(name, block)
@@ -1,3 +1,3 @@
1
1
  module ActiveHouse
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_house
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Talakevich