webink 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rfcgi CHANGED
@@ -48,6 +48,9 @@ FCGI.each_cgi do |cgi|
48
48
  control[:config] = Ink::Beauty.load_config script
49
49
  control[:time] = time
50
50
  control[:cgi] = cgi
51
+ control[:env] = ENV
52
+ control[:is_production] = is_production
53
+ control[:use_errors] = use_errors
51
54
  if cgi.env_table['REQUEST_METHOD'] == 'POST'
52
55
  control[:post] = Hash.new
53
56
  cgi.params.each do |k,v|
@@ -75,7 +78,7 @@ FCGI.each_cgi do |cgi|
75
78
  fhandle.close
76
79
 
77
80
  rescue LoadError => bang
78
- if not is_production
81
+ if is_production
79
82
  puts cgi.header({"Location" => "/status-404.html"}) if use_errors
80
83
  error cgi, "NOT_FOUND" if not use_errors
81
84
  else
@@ -84,7 +87,7 @@ FCGI.each_cgi do |cgi|
84
87
  end
85
88
 
86
89
  rescue NotImplementedError => bang
87
- if not is_production
90
+ if is_production
88
91
  puts cgi.header({"Location" => "/status-500.html"}) if use_errors
89
92
  error cgi, "SERVER_ERROR" if not use_errors
90
93
  else
@@ -93,7 +96,7 @@ FCGI.each_cgi do |cgi|
93
96
  end
94
97
 
95
98
  rescue ArgumentError => bang
96
- if not is_production
99
+ if is_production
97
100
  puts cgi.header({"Location" => "/status-500.html"}) if use_errors
98
101
  error cgi, "SERVER_ERROR" if not use_errors
99
102
  else
@@ -102,7 +105,7 @@ FCGI.each_cgi do |cgi|
102
105
  end
103
106
 
104
107
  rescue RuntimeError => bang
105
- if not is_production
108
+ if is_production
106
109
  puts cgi.header({"Location" => "/status-500.html"}) if use_errors
107
110
  error cgi, "SERVER_ERROR" if not use_errors
108
111
  else
@@ -111,7 +114,7 @@ FCGI.each_cgi do |cgi|
111
114
  end
112
115
 
113
116
  rescue NameError => bang
114
- if not is_production
117
+ if is_production
115
118
  puts cgi.header({"Location" => "/status-500.html"}) if use_errors
116
119
  error cgi, "SERVER_ERROR" if not use_errors
117
120
  else
@@ -120,7 +123,7 @@ FCGI.each_cgi do |cgi|
120
123
  end
121
124
 
122
125
  rescue Exception, StandardError => bang
123
- if not is_production
126
+ if is_production
124
127
  puts cgi.header({"Location" => "/status-500.html"}) if use_errors
125
128
  error cgi, "SERVER_ERROR" if not use_errors
126
129
  else
File without changes
File without changes
@@ -6,12 +6,13 @@ module Ink
6
6
  #
7
7
  # Controllers handle incoming requests and decide what to do
8
8
  # with them. A controller has access to all incoming data, like
9
- # POST and GET as well as the config.
9
+ # POST and GET (through @params[:get] and @params[:post] as
10
+ # well as the config.
10
11
  #
11
12
  # class App < Ink::Controller
12
13
  #
13
14
  # def index
14
- # redirect_to :controller => "app", :module => "feed", :id => 29382374
15
+ # redirect_to :controller => "my_app", :module => "feed", :id => 29382374
15
16
  # end
16
17
  #
17
18
  # def feed
@@ -27,9 +28,11 @@ module Ink
27
28
  #
28
29
  # end
29
30
  #
30
- # A controller named App should have the filename app.rb and be
31
- # placed inside the project controller folder. It can have instance
32
- # methods that are usually refered to as modules.
31
+ # A controller named App should have the filename app.rb (note
32
+ # that underscores are not allowed: "app".capitalize must be
33
+ # the loadable classname) and be placed inside the project
34
+ # controller folder. It can have instance methods that are
35
+ # usually refered to as modules.
33
36
  # So a route should contain at least a :controller and a :module.
34
37
  #
35
38
  # In the sample above there are three modules, index redirects
@@ -211,8 +214,7 @@ module Ink
211
214
  # [returns:] Hyperlink
212
215
  def link_to(*args)
213
216
  raise ArgumentError.new("Expects an array.") if not args.instance_of? Array and args.length < 2
214
- href = "#{@params[:root]}#{(@params[:root][@params[:root].length-1].chr == "/") ? "" : "/"}" if @params[:root].length > 0
215
- href = "/" if @params[:root].length == 0
217
+ href = (@params[:root].length == 0) ? "/" : "#{@params[:root]}#{(@params[:root][@params[:root].length-1].chr == "/") ? "" : "/"}"
216
218
  a = "<a "
217
219
  name = args[0]
218
220
  for i in 1...args.length
@@ -238,8 +240,7 @@ module Ink
238
240
  # [param args:] Array of Strings or String
239
241
  # [returns:] path
240
242
  def path_to(*args)
241
- href = "#{@params[:root]}#{(@params[:root][@params[:root].length-1].chr == "/") ? "" : "/"}" if @params[:root].length > 0
242
- href = "/" if @params[:root].length == 0
243
+ href = (@params[:root].length == 0) ? "/" : "#{@params[:root]}#{(@params[:root][@params[:root].length-1].chr == "/") ? "" : "/"}"
243
244
 
244
245
  if args.is_a? Array
245
246
  for i in 0...args.length
@@ -39,14 +39,20 @@ module Ink
39
39
  # This is the most basic query, it returns an Array of results,
40
40
  # and each element contains a Hash of column_name => column_entry.
41
41
  #
42
- # Ink::Database.database.find "apples", "WHERE id < 10 GROUP BY color"
43
- # => self.query("SELECT * FROM apples WHERE id < 10 GROUP BY color;")
42
+ # The following methods are convenience methods to access data for
43
+ # models. As example a model Apple and its n:1 relation to Tree
44
+ # are used. Please note that both class and database table name can
45
+ # be used to call the find and related methods. The table name for
46
+ # Apple would be "apple"; for MyApple would be "my_apple".
47
+ #
48
+ # Ink::Database.database.find "apple", "WHERE id < 10 GROUP BY color"
49
+ # => self.query("SELECT * FROM apple WHERE id < 10 GROUP BY color;")
44
50
  #
45
51
  # This is different from the query method, because it returns an Array
46
52
  # of Objects, created by the information stored in the database. So this
47
53
  # find() will return you a set of Apple-instances.
48
54
  #
49
- # Ink::Database.database.find_union "apple", 5, "tree", ""
55
+ # Ink::Database.database.find_union "apple", 5, "tree", "AND tree_id>1"
50
56
  #
51
57
  # find_union allows you to retrieve data through a many_many reference.
52
58
  # When you define a many_many relationship, a helper-table is created
@@ -56,16 +62,30 @@ module Ink
56
62
  # by the alphabetically first, and then second classname. The last quotes
57
63
  # allow additional query informations to be passed along (like group by)
58
64
  #
59
- # Ink::Database.database.find_reference "tree", 1, "apple", ""
65
+ # Ink::Database.database.find_references Tree, 1, Apple, "AND tree_id>1"
60
66
  #
61
- # find_reference is similar to find_union, only that it handles all
67
+ # find_references is similar to find_union, only that it handles all
62
68
  # other relationships. This statement above requires one Tree to have many
63
69
  # Apples, so it will return an Array of Apples, all those that belong to
64
70
  # the Tree with primary key 1
65
71
  #
72
+ # Ink::Database.database.find_reference Apple, 5, Tree, ""
73
+ #
74
+ # find_reference is essentially equal to find_references, yet it returns
75
+ # one result of a Tree or nil. This is used when Apple-Tree is a many_one
76
+ # or one_one relationship. It saves the need for the result Array from
77
+ # find_references.
78
+ #
66
79
  # Please close the dbinstance once you are done. This is automatically
67
80
  # inserted in the init.rb of a project.
68
81
  #
82
+ # == Convenience methods
83
+ #
84
+ # Database.format_date(Time.now)
85
+ #
86
+ # This will return a date in the form of 2012-11-20 10:00:02 and takes a Time
87
+ # instance.
88
+ #
69
89
  #
70
90
  #
71
91
  class Database
@@ -12,7 +12,7 @@ module Ink
12
12
  # The constructor checks, if there are class methods 'fields'
13
13
  # and 'foreign' defined. If that check is positive, it will
14
14
  # match the parameter Hash to the fields, that are set for
15
- # the database, and thow an exception if fields is lacking
15
+ # the database, and throw an exception if fields is lacking
16
16
  # an entry (excluded the primary key). The other case just
17
17
  # creates an Apple with the Hash as instance variables.
18
18
  #
@@ -22,14 +22,12 @@ module Ink
22
22
  # methods are automatically added for either the Hash, or
23
23
  # the fields and foreign keys.
24
24
  #
25
- # apple.tree = nil
26
25
  # apple.save
27
26
  #
28
27
  # You can save your apple by using the save method. New instances
29
28
  # will create a new row in the database, and update its primary
30
- # key. Old instances just update the fields. Relationships, like
31
- # in the sample below a tree, is set to nil by default, and therefore
32
- # the save method will not touch relationships.
29
+ # key. Old instances just update the fields. Relationships are set
30
+ # to nil by default and will not be touched while nil.
33
31
  #
34
32
  # treeinstance.apple = [1,2,myapple]
35
33
  # treeinstance.save
@@ -47,6 +45,13 @@ module Ink
47
45
  # themselves, so you must fetch all related data, and delete them by
48
46
  # 'hand' if you will.
49
47
  #
48
+ # treeinstance.find_references Apple
49
+ #
50
+ # This convenience method finds all apples for this tree and makes
51
+ # them available in the accessor. If the Tree-Apple relationship is
52
+ # a *_one, then there is only one object in the accessor, otherwise
53
+ # an Array of objects.
54
+ #
50
55
  #
51
56
  # = Fields and foreign sample config
52
57
  #
@@ -78,6 +83,37 @@ module Ink
78
83
  # many_many, many_one]
79
84
  # Obviously the Tree class requires a foreign with "Apple"
80
85
  # mapped to "many_one" to match this schema.
86
+ #
87
+ # You can override the automatically generated getters and
88
+ # setters in any Model class you create by just redefining
89
+ # the methods.
90
+ #
91
+ # == Convenience methods
92
+ #
93
+ # self.primary_key
94
+ # self.foreign_key
95
+ #
96
+ # Both return an Array of length 2, where the second entry
97
+ # is the type and the first for primary_key is the name of
98
+ # the primary key (default "id"). The foreign_key has a
99
+ # combination of "classname"_"primary_key" (i.e. "apple_id")
100
+ #
101
+ # self.class_name
102
+ #
103
+ # Equivalent to class.name
104
+ #
105
+ # self.table_name
106
+ #
107
+ # Generates a table representation of the class. (Apple as
108
+ # "apple" and MyApple as "my_apple")
109
+ #
110
+ # self.str_to_classname(str)
111
+ #
112
+ # Converts a table name to class name. This method takes a string.
113
+ #
114
+ # self.str_to_tablename(str)
115
+ #
116
+ # Converts a class name to table name. This method takes a string.
81
117
  #
82
118
  #
83
119
  #
@@ -93,7 +129,7 @@ module Ink
93
129
  def initialize(data)
94
130
  if self.class.respond_to? :fields
95
131
  self.class.fields.each do |k,v|
96
- raise NameError.new("Model cannot use #{k} as field, it already exists") if self.class.respond_to? k or k.to_s.downcase == "pk"
132
+ raise NameError.new("Model cannot use #{k} as field, it is blocked by primary key") if k.to_s.downcase == "pk"
97
133
  raise LoadError.new("Model cannot be loaded, argument missing: #{k}") if not data.key?(k.to_s) and self.class.primary_key[0] != k
98
134
  entry = nil
99
135
  if data[k.to_s].nil?
@@ -107,21 +143,25 @@ module Ink
107
143
  end
108
144
  instance_variable_set("@#{k}", entry)
109
145
 
110
- self.class.send(:define_method, k) do
111
- instance_variable_get "@#{k}"
146
+ if not self.respond_to? k
147
+ self.class.send(:define_method, k) do
148
+ instance_variable_get "@#{k}"
149
+ end
112
150
  end
113
151
  if self.class.primary_key[0] != k
114
- self.class.send(:define_method, "#{k}=") do |val|
115
- if data[k.to_s].nil?
116
- val = nil
117
- elsif val.is_a? String
118
- val = val.gsub(/'/, '&#39;')
119
- elsif val.is_a? Numeric
120
- val = val
121
- else
122
- val = "\'#{val}\'"
152
+ if not self.respond_to? "#{k}="
153
+ self.class.send(:define_method, "#{k}=") do |val|
154
+ if data[k.to_s].nil?
155
+ val = nil
156
+ elsif val.is_a? String
157
+ val = val.gsub(/'/, '&#39;')
158
+ elsif val.is_a? Numeric
159
+ val = val
160
+ else
161
+ val = "\'#{val}\'"
162
+ end
163
+ instance_variable_set "@#{k}", val
123
164
  end
124
- instance_variable_set "@#{k}", val
125
165
  end
126
166
  else
127
167
  self.class.send(:define_method, "pk") do
@@ -132,13 +172,15 @@ module Ink
132
172
  if self.class.respond_to? :foreign
133
173
  self.class.foreign.each do |k,v|
134
174
  k_table = self.class.str_to_tablename(k)
135
- raise NameError.new("Model cannot use #{k_table} as foreign, it already exists") if self.class.respond_to? k_table.to_sym or k_table == "pk"
136
- instance_variable_set("@#{k_table}", nil)
137
- self.class.send(:define_method, k_table) do
138
- instance_variable_get "@#{k_table}"
139
- end
140
- self.class.send(:define_method, "#{k_table}=") do |val|
141
- instance_variable_set "@#{k_table}", val
175
+ raise NameError.new("Model cannot use #{k_table} as foreign, it already exists") if k_table == "pk"
176
+ if not self.respond_to? k_table
177
+ instance_variable_set("@#{k_table}", nil)
178
+ self.class.send(:define_method, k_table) do
179
+ instance_variable_get "@#{k_table}"
180
+ end
181
+ self.class.send(:define_method, "#{k_table}=") do |val|
182
+ instance_variable_set "@#{k_table}", val
183
+ end
142
184
  end
143
185
  end
144
186
  end
@@ -186,7 +228,7 @@ module Ink
186
228
  if pkvalue
187
229
  response = Ink::Database.database.find self.class, pkvalue
188
230
  if response.length == 1
189
- Ink::Database.database.query "UPDATE #{self.class.table_name} SET #{string * ","} #{pkvalue}"
231
+ Ink::Database.database.query "UPDATE #{self.class.table_name} SET #{string * ","} #{pkvalue};"
190
232
  elsif response.length == 0
191
233
  Ink::Database.database.query "INSERT INTO #{self.class.table_name} (#{keystring * ","}) VALUES (#{valuestring * ","});"
192
234
  pk = Ink::Database.database.last_inserted_pk(self.class)
@@ -219,7 +261,7 @@ module Ink
219
261
  end
220
262
 
221
263
  pkvalue = instance_variable_get "@#{self.class.primary_key[0]}"
222
- Ink::Database.database.remove self.class.name, "WHERE `#{self.class.primary_key[0]}`=#{(pkvalue.is_a?(Numeric)) ? pkvalue : "\'#{pkvalue}\'"};"
264
+ Ink::Database.database.remove self.class.name, "WHERE `#{self.class.primary_key[0]}`=#{(pkvalue.is_a?(Numeric)) ? pkvalue : "\'#{pkvalue}\'"}"
223
265
  end
224
266
 
225
267
  # Instance method
metadata CHANGED
@@ -1,82 +1,85 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: webink
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.3
4
5
  prerelease:
5
- version: 1.3.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Matthias Geier
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2012-10-05 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: fcgi
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
23
21
  version: 0.8.8
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: simple-mmap
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
30
25
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: simple-mmap
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
34
37
  version: 1.1.4
35
38
  type: :runtime
36
- version_requirements: *id002
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.1.4
37
46
  description:
38
47
  email:
39
- executables:
48
+ executables:
40
49
  - webink_database
41
50
  - rfcgi
42
51
  extensions: []
43
-
44
52
  extra_rdoc_files: []
45
-
46
- files:
53
+ files:
47
54
  - lib/webink.rb
48
- - lib/webink/model.rb
55
+ - lib/webink/controller.rb
49
56
  - lib/webink/database.rb
50
57
  - lib/webink/beauty.rb
51
- - lib/webink/controller.rb
52
- - bin/webink_database
58
+ - lib/webink/model.rb
53
59
  - bin/rfcgi
60
+ - bin/webink_database
54
61
  homepage: https://github.com/matthias-geier/WebInk
55
62
  licenses: []
56
-
57
63
  post_install_message:
58
64
  rdoc_options: []
59
-
60
- require_paths:
65
+ require_paths:
61
66
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
67
+ required_ruby_version: !ruby/object:Gem::Requirement
63
68
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
67
72
  version: 1.9.3
68
- required_rubygems_version: !ruby/object:Gem::Requirement
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
74
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- version: "0"
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
74
79
  requirements: []
75
-
76
80
  rubyforge_project:
77
81
  rubygems_version: 1.8.23
78
82
  signing_key:
79
83
  specification_version: 3
80
84
  summary: A minimal web framework.
81
85
  test_files: []
82
-