ar_doc_store 0.2.1 → 1.0.0

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: 389dfcb42c57c087c024326589ff09ca183bd224
4
- data.tar.gz: ad6f5ac50966c3e2d8979cda69383c28dcaa0908
3
+ metadata.gz: 119e03286bb8ecf36dfa1d089075188a1979b1cb
4
+ data.tar.gz: fc1841751d938d5152c6b902c8925c5c25eac98e
5
5
  SHA512:
6
- metadata.gz: 4416430c4d7d03f97294e0b9fb31b3d03af2bb220d097975ff7ecd4104c27dfe8909125039c09c278dbefc633ebf5a303e95cf6f84e2a95fda10e1907a5d5dcd
7
- data.tar.gz: bc49e9c3ed777a4f7fe140f6811ede9ba42123968545c602d121c4a86ad05e307791b21a2bc537eeee25958756d806592bc39d33bd855929cec62d494a4fab44
6
+ metadata.gz: fb2485d03e362542372b0a41e2fb4cde66c385731fefd3d437553e82f8c3637bca84ff63b46893a3ccef9be08de23bd299e1abfdac5356120fda85ffab411003
7
+ data.tar.gz: 4a0023a148212b537f2b07500641f138ecc870540bbe61c6c79e06ded4e3161fe8528d747ed5989809439399406997cb82550b603c89ad579ead55dd17911c8f
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
- ruby '2.2.2'
2
1
  source 'https://rubygems.org'
3
2
 
4
3
  # Specify your gem's dependencies in ar_doc_store.gemspec
data/README.md CHANGED
@@ -65,12 +65,12 @@ Now there are several ways to play but all boil down to one method on the model:
65
65
  class Building < ActiveRecord::Base
66
66
  include ArDocStore::Model
67
67
 
68
- attribute :name, :string
69
- attribute :width, :float
70
- attribute :height, as: :float # the :as is optional but if you like the consistency with SimpleForm
71
- attribute :storeys, :integer
72
- attribute :finished, :boolean
73
- attribute :construction_type, :enumeration,
68
+ json_attribute :name, :string
69
+ json_attribute :width, :float
70
+ json_attribute :height, as: :float # the :as is optional but if you like the consistency with SimpleForm
71
+ json_attribute :storeys, :integer
72
+ json_attribute :finished, :boolean
73
+ json_attribute :construction_type, :enumeration,
74
74
  values: %w{wood plaster mud brick},
75
75
  multiple: true,
76
76
  strict: true
@@ -90,7 +90,7 @@ You noticed the enumeration type on the construction_type takes an array. That's
90
90
 
91
91
  ```ruby
92
92
  class Building ...
93
- attribute :construction_type,
93
+ json_attribute :construction_type,
94
94
  :enumeration,
95
95
  values: %w{wood plaster mud brick},
96
96
  multiple: true,
@@ -114,17 +114,17 @@ class Door
114
114
  enumerates :door_type,
115
115
  multiple: true,
116
116
  values: %w{single double french sliding push pull}
117
- attribute :open_handle,
117
+ json_attribute :open_handle,
118
118
  as: :enumeration,
119
119
  multiple: true,
120
120
  values: %w{push pull plate knob handle}
121
- attribute :close_handle,
121
+ json_attribute :close_handle,
122
122
  as: :enumeration,
123
123
  multiple: true,
124
124
  values: %w{push pull plate knob handle}
125
- attribute :clear_distance, as: :integer
126
- attribute :opening_force, as: :integer
127
- attribute :clear_space, as: :integer
125
+ json_attribute :clear_distance, as: :integer
126
+ json_attribute :opening_force, as: :integer
127
+ json_attribute :clear_space, as: :integer
128
128
  end
129
129
  ```
130
130
 
@@ -177,9 +177,9 @@ You can also embeds_many. It works the same way:
177
177
  ```ruby
178
178
  class Room
179
179
  include ArDocStore::EmbeddableModel
180
- attribute :length, as: :float
181
- attribute :width, as: :float
182
- attribute :height, as: :float
180
+ json_attribute :length, as: :float
181
+ json_attribute :width, as: :float
182
+ json_attribute :height, as: :float
183
183
  enumerates :light_switch_type, %w{flip knob switchplate clapper}
184
184
  end
185
185
 
data/ar_doc_store.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "activerecord", "~> 4.0"
21
+ spec.add_dependency "activerecord" #, "~> 4.0"
22
22
  spec.add_dependency "pg", "~> 0.17"
23
23
  # spec.add_dependency "hashie", ">=3.4.0"
24
24
  spec.add_development_dependency "bundler", "~> 1.7"
data/lib/ar_doc_store.rb CHANGED
@@ -31,7 +31,7 @@ module ArDocStore
31
31
  def self.mappings
32
32
  @mappings
33
33
  end
34
-
34
+
35
35
  def self.convert_boolean(bool)
36
36
  if bool.is_a?(String)
37
37
  return true if bool == true || bool =~ (/^(true|t|yes|y|1)$/i)
@@ -46,5 +46,12 @@ module ArDocStore
46
46
  return nil
47
47
  end
48
48
  end
49
- end
50
49
 
50
+ def self.clobber_attribute_method!
51
+ ArDocStore::Storage::ClassMethods.module_eval do
52
+ def attribute(*args)
53
+ json_attribute *args
54
+ end
55
+ end
56
+ end
57
+ end
@@ -101,7 +101,7 @@ module ArDocStore
101
101
  def create_embeds_many_validation(assn_name)
102
102
  model.class_eval do
103
103
  validate_method = "validate_embedded_record_for_#{assn_name}"
104
- define_method validate_method, -> { validate_embeds_many assn_name }
104
+ define_method validate_method.to_s, -> { validate_embeds_many assn_name }
105
105
  validate validate_method
106
106
  end
107
107
  end
@@ -2,7 +2,7 @@ module ArDocStore
2
2
  module AttributeTypes
3
3
 
4
4
  class EnumerationAttribute < BaseAttribute
5
-
5
+
6
6
  def build
7
7
  key = attribute.to_sym
8
8
  dictionary = options[:values]
@@ -10,9 +10,9 @@ module ArDocStore
10
10
  strict = options[:strict]
11
11
  default_value = default
12
12
  model.class_eval do
13
-
13
+
14
14
  if multiple
15
- attribute key, as: :array, default: default_value
15
+ json_attribute key, as: :array, default: default_value
16
16
  if strict
17
17
  define_method "validate_#{key}" do
18
18
  value = public_send(key)
@@ -21,7 +21,7 @@ module ArDocStore
21
21
  validate "validate_#{key}".to_sym
22
22
  end
23
23
  else
24
- attribute key, as: :string, default: default_value
24
+ json_attribute key, as: :string, default: default_value
25
25
  if strict
26
26
  validates_inclusion_of key, in: dictionary, allow_blank: true
27
27
  end
@@ -24,7 +24,11 @@ module ArDocStore
24
24
 
25
25
  delegate :as_json, to: :attributes
26
26
 
27
- attribute :id, :uuid
27
+ json_attribute :id, :uuid
28
+
29
+ def self.attribute(name, *args)
30
+ json_attribute name, *args
31
+ end
28
32
 
29
33
  end
30
34
 
@@ -1,25 +1,25 @@
1
1
  module ArDocStore
2
2
  module Embedding
3
3
  def self.included(mod)
4
- mod.send :extend, ClassMethods
4
+ mod.send :extend, ClassMethods
5
5
  mod.send :include, InstanceMethods
6
6
  end
7
-
7
+
8
8
  module ClassMethods
9
9
 
10
10
  def embeds_many(assn_name, *args)
11
- attribute assn_name, :embeds_many, *args
11
+ json_attribute assn_name, :embeds_many, *args
12
12
  end
13
13
 
14
14
  def embeds_one(assn_name, *args)
15
- attribute assn_name, :embeds_one, *args
15
+ json_attribute assn_name, :embeds_one, *args
16
16
  end
17
17
 
18
18
  end
19
-
20
-
19
+
20
+
21
21
  module InstanceMethods
22
-
22
+
23
23
  # Returns whether or not the association is valid and applies any errors to
24
24
  # the parent, <tt>self</tt>, if it wasn't. Skips any <tt>:autosave</tt>
25
25
  # enabled records if they're marked_for_destruction? or destroyed.
@@ -67,7 +67,7 @@ module ArDocStore
67
67
 
68
68
  module ClassMethods
69
69
 
70
- def attribute(name, *args)
70
+ def json_attribute(name, *args)
71
71
  type = args.shift if args.first.is_a?(Symbol)
72
72
  options = args.extract_options!
73
73
  type ||= options.delete(:as) || :string
@@ -120,28 +120,28 @@ module ArDocStore
120
120
  # Allows you to define several string attributes at once. Deprecated.
121
121
  def string_attributes(*args)
122
122
  args.each do |arg|
123
- attribute arg, as: :string
123
+ json_attribute arg, as: :string
124
124
  end
125
125
  end
126
126
 
127
127
  # Allows you to define several float attributes at once. Deprecated.
128
128
  def float_attributes(*args)
129
129
  args.each do |arg|
130
- attribute arg, as: :float
130
+ json_attribute arg, as: :float
131
131
  end
132
132
  end
133
133
 
134
134
  # Allows you to define several integer attributes at once. Deprecated.
135
135
  def integer_attributes(*args)
136
136
  args.each do |arg|
137
- attribute arg, as: :integer
137
+ json_attribute arg, as: :integer
138
138
  end
139
139
  end
140
140
 
141
141
  # Allows you to define several boolean attributes at once. Deprecated.
142
142
  def boolean_attributes(*args)
143
143
  args.each do |arg|
144
- attribute arg, as: :boolean
144
+ json_attribute arg, as: :boolean
145
145
  end
146
146
  end
147
147
 
@@ -150,7 +150,7 @@ module ArDocStore
150
150
  def enumerates(field, *args)
151
151
  options = args.extract_options!
152
152
  options[:as] = :enumeration
153
- attribute field, options
153
+ json_attribute field, options
154
154
  end
155
155
 
156
156
 
@@ -1,3 +1,3 @@
1
1
  module ArDocStore
2
- VERSION = "0.2.1"
2
+ VERSION = "1.0.0"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -27,7 +27,7 @@ class ARDuck
27
27
  @attributes = HashWithIndifferentAccess.new
28
28
  unless attrs.nil?
29
29
  attrs.each { |key, value|
30
- @attributes[key] = public_send("#{key}=", value)
30
+ @jattributes[key] = public_send("#{key}=", value)
31
31
  }
32
32
  end
33
33
  @_initialized = true
@@ -54,7 +54,7 @@ class ARDuck
54
54
  end
55
55
 
56
56
  def write_store_attribute(store, key, value)
57
- #changed_attributes[key] = read_store_attribute(:data, key) if @_initialized
57
+ #changed_json_attributes[key] = read_store_json_attribute(:data, key) if @_initialized
58
58
  @attributes[key] = value
59
59
  end
60
60
 
@@ -71,36 +71,36 @@ end
71
71
 
72
72
  class EmbeddableA < ARDuck
73
73
  include ArDocStore::EmbeddableModel
74
- attribute :name
74
+ json_attribute :name
75
75
  end
76
76
 
77
77
  class EmbeddableB < EmbeddableA
78
- attribute :gender
78
+ json_attribute :gender
79
79
  end
80
80
 
81
81
  class Dimensions
82
82
  include ArDocStore::EmbeddableModel
83
- attribute :length, :float
84
- attribute :width, :float
83
+ json_attribute :length, :float
84
+ json_attribute :width, :float
85
85
  end
86
86
 
87
87
  class Route
88
88
  include ArDocStore::EmbeddableModel
89
- attribute :is_route_unobstructed, as: :boolean
90
- attribute :is_route_lighted, as: :boolean
91
- attribute :route_surface, as: :string
92
- attribute :route_slope_percent, as: :integer
93
- attribute :route_min_width, as: :integer
89
+ json_attribute :is_route_unobstructed, as: :boolean
90
+ json_attribute :is_route_lighted, as: :boolean
91
+ json_attribute :route_surface, as: :string
92
+ json_attribute :route_slope_percent, as: :integer
93
+ json_attribute :route_min_width, as: :integer
94
94
  end
95
95
 
96
96
  class Door
97
97
  include ArDocStore::EmbeddableModel
98
98
  enumerates :door_type, multiple: true, values: %w{single double french sliding push pull}
99
- attribute :open_handle, as: :enumeration, multiple: true, values: %w{push pull plate knob handle}
100
- attribute :close_handle, as: :enumeration, multiple: true, values: %w{push pull plate knob handle}
101
- attribute :clear_distance, as: :integer
102
- attribute :opening_force, as: :integer
103
- attribute :clear_space, as: :integer
99
+ json_attribute :open_handle, as: :enumeration, multiple: true, values: %w{push pull plate knob handle}
100
+ json_attribute :close_handle, as: :enumeration, multiple: true, values: %w{push pull plate knob handle}
101
+ json_attribute :clear_distance, as: :integer
102
+ json_attribute :opening_force, as: :integer
103
+ json_attribute :clear_space, as: :integer
104
104
  end
105
105
 
106
106
  class Entrance
@@ -116,8 +116,8 @@ class Restroom
116
116
 
117
117
  enumerates :restroom_type, values: %w{single double dirty nasty clean}
118
118
 
119
- attribute :is_restroom_provided, as: :boolean
120
- attribute :is_signage_clear, as: :boolean
119
+ json_attribute :is_restroom_provided, as: :boolean
120
+ json_attribute :is_signage_clear, as: :boolean
121
121
 
122
122
  embeds_one :stall_area_dimensions, class_name: 'Dimensions'
123
123
  embeds_one :sink_area_dimensions, class_name: 'Dimensions'
@@ -128,16 +128,16 @@ end
128
128
 
129
129
  class Building < ActiveRecord::Base
130
130
  include ArDocStore::Model
131
- attribute :name, :string
132
- attribute :comments, as: :string
133
- attribute :finished, :boolean
134
- attribute :stories, as: :integer
135
- attribute :height, as: :float
136
- attribute :architects, as: :array
137
- attribute :construction, as: :enumeration, values: %w{concrete wood brick plaster steel}
138
- attribute :multiconstruction, as: :enumeration, values: %w{concrete wood brick plaster steel}, multiple: true
139
- attribute :strict_enumeration, as: :enumeration, values: %w{happy sad glad bad}, strict: true
140
- attribute :strict_multi_enumeration, as: :enumeration, values: %w{happy sad glad bad}, multiple: true, strict: true
131
+ json_attribute :name, :string
132
+ json_attribute :comments, as: :string
133
+ json_attribute :finished, :boolean
134
+ json_attribute :stories, as: :integer
135
+ json_attribute :height, as: :float
136
+ json_attribute :architects, as: :array
137
+ json_attribute :construction, as: :enumeration, values: %w{concrete wood brick plaster steel}
138
+ json_attribute :multiconstruction, as: :enumeration, values: %w{concrete wood brick plaster steel}, multiple: true
139
+ json_attribute :strict_enumeration, as: :enumeration, values: %w{happy sad glad bad}, strict: true
140
+ json_attribute :strict_multi_enumeration, as: :enumeration, values: %w{happy sad glad bad}, multiple: true, strict: true
141
141
  embeds_many :entrances
142
142
  embeds_many :restrooms
143
143
  end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ar_doc_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Furber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-26 00:00:00.000000000 Z
11
+ date: 2016-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '4.0'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '4.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubyforge_project:
131
- rubygems_version: 2.4.6
131
+ rubygems_version: 2.5.1
132
132
  signing_key:
133
133
  specification_version: 4
134
134
  summary: A document storage gem meant for ActiveRecord PostgresQL JSON storage.