slim-attributes 0.6.6 → 0.7.1

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/Rakefile CHANGED
@@ -12,8 +12,10 @@ begin
12
12
  s.authors = ["Stephen Sykes"]
13
13
  s.files = FileList["[A-Z]*", "{ext,lib,test}/**/*"]
14
14
  s.extensions = "ext/extconf.rb"
15
+ s.rubyforge_project = 'slim-attributes'
15
16
  end
16
17
  Jeweler::GemcutterTasks.new
18
+ Jeweler::RubyforgeTasks.new
17
19
  rescue LoadError
18
20
  puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://
19
21
  gems.github.com"
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 6
4
- :patch: 6
3
+ :minor: 7
4
+ :patch: 1
@@ -0,0 +1,157 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = /usr/local/lib/ruby/1.8/i686-darwin10.0.0
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir):$(topdir):$(hdrdir)
10
+ exec_prefix = $(prefix)
11
+ prefix = $(DESTDIR)/usr/local
12
+ sharedstatedir = $(prefix)/com
13
+ mandir = $(datarootdir)/man
14
+ psdir = $(docdir)
15
+ oldincludedir = $(DESTDIR)/usr/include
16
+ localedir = $(datarootdir)/locale
17
+ bindir = $(exec_prefix)/bin
18
+ libexecdir = $(exec_prefix)/libexec
19
+ sitedir = $(libdir)/ruby/site_ruby
20
+ htmldir = $(docdir)
21
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
22
+ includedir = $(prefix)/include
23
+ infodir = $(datarootdir)/info
24
+ vendorlibdir = $(vendordir)/$(ruby_version)
25
+ sysconfdir = $(prefix)/etc
26
+ libdir = $(exec_prefix)/lib
27
+ sbindir = $(exec_prefix)/sbin
28
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
29
+ docdir = $(datarootdir)/doc/$(PACKAGE)
30
+ dvidir = $(docdir)
31
+ vendordir = $(libdir)/ruby/vendor_ruby
32
+ datarootdir = $(prefix)/share
33
+ pdfdir = $(docdir)
34
+ archdir = $(rubylibdir)/$(arch)
35
+ sitearchdir = $(sitelibdir)/$(sitearch)
36
+ datadir = $(datarootdir)
37
+ localstatedir = $(prefix)/var
38
+ sitelibdir = $(sitedir)/$(ruby_version)
39
+
40
+ CC = gcc
41
+ LIBRUBY = $(LIBRUBY_A)
42
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
43
+ LIBRUBYARG_SHARED =
44
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
45
+
46
+ RUBY_EXTCONF_H =
47
+ CFLAGS = -fno-common -g -O2 -pipe -fno-common $(cflags) -Wall
48
+ INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
49
+ DEFS =
50
+ CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE $(DEFS) $(cppflags) -I/usr/local/mysql/include -g -Os -arch i386 -fno-common -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT -DDONT_DECLARE_CXA_PURE_VIRTUAL
51
+ CXXFLAGS = $(CFLAGS)
52
+ ldflags = -L.
53
+ dldflags =
54
+ archflag =
55
+ DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
56
+ LDSHARED = cc -dynamic -bundle -undefined suppress -flat_namespace
57
+ AR = ar
58
+ EXEEXT =
59
+
60
+ RUBY_INSTALL_NAME = ruby
61
+ RUBY_SO_NAME = ruby
62
+ arch = i686-darwin10.0.0
63
+ sitearch = i686-darwin10.0.0
64
+ ruby_version = 1.8
65
+ ruby = /usr/local/bin/ruby
66
+ RUBY = $(ruby)
67
+ RM = rm -f
68
+ MAKEDIRS = mkdir -p
69
+ INSTALL = /usr/bin/install -c
70
+ INSTALL_PROG = $(INSTALL) -m 0755
71
+ INSTALL_DATA = $(INSTALL) -m 644
72
+ COPY = cp
73
+
74
+ #### End of system configuration section. ####
75
+
76
+ preload =
77
+
78
+ libpath = . $(libdir)
79
+ LIBPATH = -L. -L$(libdir)
80
+ DEFFILE =
81
+
82
+ CLEANFILES = mkmf.log
83
+ DISTCLEANFILES =
84
+
85
+ extout =
86
+ extout_prefix =
87
+ target_prefix =
88
+ LOCAL_LIBS =
89
+ LIBS = -L/usr/local/mysql/lib -lmysqlclient -lz -lm -lmygcc -ldl -lobjc
90
+ SRCS = slim_attrib_ext.c
91
+ OBJS = slim_attrib_ext.o
92
+ TARGET = slim_attrib_ext
93
+ DLLIB = $(TARGET).bundle
94
+ EXTSTATIC =
95
+ STATIC_LIB =
96
+
97
+ BINDIR = $(bindir)
98
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
99
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
100
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
101
+
102
+ TARGET_SO = $(DLLIB)
103
+ CLEANLIBS = $(TARGET).bundle $(TARGET).il? $(TARGET).tds $(TARGET).map
104
+ CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
105
+
106
+ all: $(DLLIB)
107
+ static: $(STATIC_LIB)
108
+
109
+ clean:
110
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
111
+
112
+ distclean: clean
113
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
114
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
115
+
116
+ realclean: distclean
117
+ install: install-so install-rb
118
+
119
+ install-so: $(RUBYARCHDIR)
120
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
121
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
122
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
123
+ install-rb: pre-install-rb install-rb-default
124
+ install-rb-default: pre-install-rb-default
125
+ pre-install-rb: Makefile
126
+ pre-install-rb-default: Makefile
127
+ $(RUBYARCHDIR):
128
+ $(MAKEDIRS) $@
129
+
130
+ site-install: site-install-so site-install-rb
131
+ site-install-so: install-so
132
+ site-install-rb: install-rb
133
+
134
+ .SUFFIXES: .c .m .cc .cxx .cpp .C .o
135
+
136
+ .cc.o:
137
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
138
+
139
+ .cxx.o:
140
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
141
+
142
+ .cpp.o:
143
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
144
+
145
+ .C.o:
146
+ $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
147
+
148
+ .c.o:
149
+ $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
150
+
151
+ $(DLLIB): $(OBJS) Makefile
152
+ @-$(RM) $@
153
+ $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
154
+
155
+
156
+
157
+ $(OBJS): ruby.h defines.h
@@ -18,7 +18,8 @@
18
18
  #define GetCharStarPtr(obj) (Check_Type(obj, T_DATA), (char**)DATA_PTR(obj))
19
19
 
20
20
  VALUE cRowHash, cClass;
21
- ID pointers_id, row_info_id, field_indexes_id, real_hash_id, to_hash_id;
21
+ ID pointers_id, row_info_id, field_indexes_id, real_hash_id, to_hash_id, sq_parens_id,
22
+ sq_parens_equal_id, has_key_id;
22
23
 
23
24
  #define MAX_CACHED_COLUMN_IDS 40
24
25
  ID column_ids[MAX_CACHED_COLUMN_IDS];
@@ -30,8 +31,8 @@ struct mysql_res {
30
31
  };
31
32
 
32
33
  // row info
33
- #define SLIM_IS_NULL (char)0x01
34
- #define SLIM_IS_SET (char)0x02
34
+ #define SLIM_IS_NULL 0x01
35
+ #define SLIM_IS_SET 0x02
35
36
 
36
37
  #define GET_COL_IV_ID(str, cnum) (cnum < MAX_CACHED_COLUMN_IDS ? column_ids[cnum] : (sprintf(str, "@col_%ld", cnum), rb_intern(str)))
37
38
 
@@ -103,7 +104,7 @@ static VALUE fetch_by_index(VALUE obj, VALUE index) {
103
104
  long col_number = FIX2LONG(index);
104
105
  unsigned int length;
105
106
  row_info = GetCharPtr(rb_ivar_get(obj, row_info_id)) + col_number; // flags for this column
106
- if (*row_info == SLIM_IS_NULL) return Qnil; // return nil if null from db
107
+ if (*row_info & SLIM_IS_NULL) return Qnil; // return nil if null from db
107
108
  col_id = GET_COL_IV_ID(col_name, col_number);
108
109
  if (*row_info == SLIM_IS_SET) return rb_ivar_get(obj, col_id); // was made to a string already
109
110
  pointers = GetCharStarPtr(rb_ivar_get(obj, pointers_id)); // find the data and make ruby string
@@ -118,12 +119,16 @@ static VALUE fetch_by_index(VALUE obj, VALUE index) {
118
119
  // This is the [] method of the row data object.
119
120
  // It checks for a real hash, but if none exists it will call fetch_by_index
120
121
  static VALUE slim_fetch(VALUE obj, VALUE name) {
121
- VALUE field_indexes, hash_lookup;
122
+ VALUE field_indexes, hash_lookup, real_hash;
122
123
 
123
- if (REAL_HASH_EXISTS) return rb_hash_aref(rb_ivar_get(obj, real_hash_id), name);
124
+ if (REAL_HASH_EXISTS) return rb_funcall(rb_ivar_get(obj, real_hash_id), sq_parens_id, 1, name);
124
125
 
125
126
  hash_lookup = rb_hash_aref(field_indexes, name);
126
- if (NIL_P(hash_lookup)) return Qnil;
127
+ if (NIL_P(hash_lookup)) {
128
+ real_hash = rb_ivar_get(obj, real_hash_id);
129
+ if (NIL_P(real_hash)) return Qnil;
130
+ return rb_funcall(real_hash, sq_parens_id, 1, name);
131
+ }
127
132
  return fetch_by_index(obj, hash_lookup);
128
133
  }
129
134
 
@@ -136,10 +141,10 @@ static VALUE set_element(VALUE obj, VALUE name, VALUE val) {
136
141
  char col_name[16];
137
142
  ID col_id;
138
143
 
139
- if (REAL_HASH_EXISTS) return rb_hash_aset(rb_ivar_get(obj, real_hash_id), name, val);
144
+ if (REAL_HASH_EXISTS) return rb_funcall(rb_ivar_get(obj, real_hash_id), sq_parens_equal_id, 2, name, val);
140
145
 
141
146
  hash_lookup = rb_hash_aref(field_indexes, name);
142
- if (NIL_P(hash_lookup)) return rb_hash_aset(rb_funcall(obj, to_hash_id, 0), name, val);
147
+ if (NIL_P(hash_lookup)) return rb_funcall(rb_funcall(obj, to_hash_id, 0), sq_parens_equal_id, 2, name, val);
143
148
  col_number = FIX2LONG(hash_lookup);
144
149
  col_id = GET_COL_IV_ID(col_name, col_number);
145
150
  rb_ivar_set(obj, col_id, val);
@@ -184,15 +189,20 @@ static VALUE slim_dup(VALUE obj) {
184
189
  // Calls to model property methods in AR cause a call to has_key?, so it
185
190
  // is implemented here in C for speed.
186
191
  static VALUE has_key(VALUE obj, VALUE name) {
187
- VALUE field_indexes;
192
+ VALUE field_indexes, real_hash;
188
193
 
189
194
  #ifdef RHASH_TBL
190
195
  if (REAL_HASH_EXISTS) return (st_lookup(RHASH_TBL(rb_ivar_get(obj, real_hash_id)), name, 0) ? Qtrue : Qfalse);
191
- else return (st_lookup(RHASH_TBL(field_indexes), name, 0) ? Qtrue : Qfalse);
196
+ else if (st_lookup(RHASH_TBL(field_indexes), name, 0)) return Qtrue;
192
197
  #else
193
198
  if (REAL_HASH_EXISTS) return (st_lookup(RHASH(rb_ivar_get(obj, real_hash_id))->tbl, name, 0) ? Qtrue : Qfalse);
194
- else return (st_lookup(RHASH(field_indexes)->tbl, name, 0) ? Qtrue : Qfalse);
199
+ else if (st_lookup(RHASH(field_indexes)->tbl, name, 0)) return Qtrue;
195
200
  #endif
201
+ else {
202
+ real_hash = rb_ivar_get(obj, real_hash_id);
203
+ if (NIL_P(real_hash)) return Qfalse;
204
+ return rb_funcall(real_hash, has_key_id, 1, name);
205
+ }
196
206
  }
197
207
 
198
208
  void Init_slim_attrib_ext() {
@@ -210,13 +220,18 @@ void Init_slim_attrib_ext() {
210
220
  rb_define_method(cRowHash, "[]", (VALUE(*)(ANYARGS))slim_fetch, 1);
211
221
  rb_define_method(cRowHash, "[]=", (VALUE(*)(ANYARGS))set_element, 2);
212
222
  rb_define_method(cRowHash, "dup", (VALUE(*)(ANYARGS))slim_dup, 0);
213
- rb_define_method(cRowHash, "has_key?", (VALUE(*)(ANYARGS))has_key, 1);
223
+ rb_define_method(cRowHash, "has_key?", (VALUE(*)(ANYARGS))has_key, 1);
224
+ rb_define_method(cRowHash, "accessed_keys", (VALUE(*)(ANYARGS))accessed_keys, 0);
225
+
214
226
  // set up some symbols that we will need
215
227
  pointers_id = rb_intern("@pointers");
216
228
  row_info_id = rb_intern("@row_info");
217
229
  field_indexes_id = rb_intern("@field_indexes");
218
230
  real_hash_id = rb_intern("@real_hash");
219
231
  to_hash_id = rb_intern("to_hash");
232
+ sq_parens_id = rb_intern("[]");
233
+ sq_parens_equal_id = rb_intern("[]=");
234
+ has_key_id = rb_intern("has_key?");
220
235
  for(i=0; i < MAX_CACHED_COLUMN_IDS; i++) {
221
236
  sprintf(col_name, "@col_%d", i);
222
237
  column_ids[i] = rb_intern(col_name);
Binary file
@@ -9,6 +9,8 @@ require 'slim_attrib_ext'
9
9
 
10
10
  class Mysql::Result
11
11
  class RowHash
12
+ attr_accessor :real_hash
13
+
12
14
  def marshal_dump
13
15
  to_hash
14
16
  end
@@ -28,8 +30,8 @@ class Mysql::Result
28
30
  # This should be the exception though, and the efficiencies of using slim-attributes
29
31
  # are lost when this happens.
30
32
  def to_hash
31
- return @real_hash if @real_hash
32
- @real_hash = {}
33
+ return @real_hash unless @field_indexes
34
+ @real_hash ||= {}
33
35
  @field_indexes.each_pair {|name, index| @real_hash[name] = fetch_by_index(index)}
34
36
  @field_indexes = nil
35
37
  @real_hash
@@ -46,7 +48,7 @@ class Mysql::Result
46
48
  to_hash.freeze
47
49
  regular_freeze
48
50
  end
49
-
51
+
50
52
  def method_missing(name, *args, &block)
51
53
  to_hash.send(name, *args, &block)
52
54
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim-attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Sykes
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-10 00:00:00 +03:00
12
+ date: 2009-10-20 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,8 +28,11 @@ files:
28
28
  - README
29
29
  - Rakefile
30
30
  - VERSION.yml
31
+ - ext/Makefile
31
32
  - ext/extconf.rb
33
+ - ext/slim_attrib_ext.bundle
32
34
  - ext/slim_attrib_ext.c
35
+ - ext/slim_attrib_ext.o
33
36
  - lib/slim_attributes.rb
34
37
  - test/benchmark.rb
35
38
  - test/database.yml
@@ -59,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
62
  version:
60
63
  requirements: []
61
64
 
62
- rubyforge_project:
65
+ rubyforge_project: slim-attributes
63
66
  rubygems_version: 1.3.5
64
67
  signing_key:
65
68
  specification_version: 3