activerecord-hstore_properties 0.0.2.alpha → 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.
data/README.textile CHANGED
@@ -29,12 +29,16 @@ end
29
29
 
30
30
  h2. Usage
31
31
 
32
+ h3. Retrieving values
33
+
32
34
  By default, all your properties are of type String. There are number of other property types available though...
33
35
 
34
- # string
35
- # boolean
36
- # number
37
- # counter
36
+ * string
37
+ * boolean
38
+ * number
39
+ * counter
40
+
41
+ More will come in near future...
38
42
 
39
43
  All properties can be retrieved just as they are written into hstore column, by suffixing them with @_property@, i.e.
40
44
 
@@ -53,24 +57,37 @@ What is more, it is possible to bump counter properties, i.e. following line wil
53
57
  @User.last.comments_bump!@
54
58
 
55
59
 
56
- h2. Updating through forms
60
+ h3. Updating through forms
61
+
62
+ You obviously need to add @:properties@ to yours @attr_accessible@
63
+
64
+ Below is an example of building appropriate fields dynamically with formtastic
57
65
 
58
- bc. <%= f.fields_for :properties, OpenStruct.new(@user.properties) do |builder| %>
59
- <% User.properties.each do |property| %>
60
- <%= builder.input property.name, property.formtastic_options %>
66
+ bc.. <%= semantic_form_for @user do |f| %>
67
+ <%= f.first_name %>
68
+ <%= f.fields_for :properties, OpenStruct.new(@user.properties) do |builder| %>
69
+ <% User.properties.each do |property| %>
70
+ <%= builder.input property.name, property.formtastic_options %>
71
+ <% end %>
61
72
  <% end %>
73
+ <%= f.submit %>
62
74
  <% end %>
63
75
 
64
-
65
76
  h2. Further customization
66
77
 
67
- If most of your properties are of the same type, but other than string, you can overwrite @default_proeprty_klass@ to make other type default, i.e.
78
+ If most of your properties are of the same type, but other than string, you can overwrite @default_property_klass@ to make other type default, i.e.
68
79
 
69
80
  bc.
70
81
  class User < ActiveRecord::Base
71
82
  #...
72
- def default_property_klass
83
+ def self.default_property_klass
73
84
  ActiveRecord::Properties::BooleanProperty
74
85
  end
75
86
  end
76
87
 
88
+ h2. When to use?
89
+
90
+ * If you consider adding redundant column to your table, that will only sometimes store any data
91
+ * If you would like to make particular model "configurable"
92
+ * If you will not likely perform queries on specific field but mostly read from it directly
93
+
@@ -11,7 +11,7 @@ module ActiveRecord
11
11
  extend ActiveSupport::Concern
12
12
 
13
13
  included do
14
- include ActiveRecord::Properties::Extensions::Booleans
14
+ include ActiveRecord::Properties::Extensions::Booleans
15
15
  include ActiveRecord::Properties::Extensions::Counters
16
16
 
17
17
  serialize :properties, ::ActiveRecord::Coders::Hstore
@@ -31,6 +31,15 @@ module ActiveRecord
31
31
  end
32
32
 
33
33
  module ClassMethods
34
+ def properties_set(*args)
35
+ self._properties.dup.tap do |all_properties|
36
+ unless args.blank?
37
+ all_properties.select! { |property| args.include?(property.name) }
38
+ end
39
+ all_properties.reject! { |property| property.name.to_s.starts_with?('_') }
40
+ end
41
+ end
42
+
34
43
  def properties(*args)
35
44
  if args.blank?
36
45
  self._properties ||= []
@@ -1,5 +1,5 @@
1
1
  module Activerecord
2
2
  module HstoreProperties
3
- VERSION = "0.0.2.alpha"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-hstore_properties
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.alpha
5
- prerelease: 6
4
+ version: 0.0.3
5
+ prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - stevo
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-10 00:00:00.000000000 Z
12
+ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -70,9 +70,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  none: false
72
72
  requirements:
73
- - - ! '>'
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.3.1
75
+ version: '0'
76
76
  requirements: []
77
77
  rubyforge_project:
78
78
  rubygems_version: 1.8.24