lux-fw 0.1.17 → 0.1.35

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/bin/cli/am +38 -29
  4. data/bin/cli/assets +8 -4
  5. data/bin/cli/exceptions +6 -6
  6. data/bin/cli/generate +0 -0
  7. data/bin/cli/get +0 -0
  8. data/bin/cli/nginx +11 -5
  9. data/bin/cli/routes +0 -0
  10. data/bin/cli/systemd +36 -0
  11. data/bin/forever +0 -0
  12. data/bin/job_que +0 -0
  13. data/bin/lux +1 -0
  14. data/lib/common/base32.rb +0 -0
  15. data/lib/common/class_attributes.rb +13 -4
  16. data/lib/common/crypt.rb +6 -10
  17. data/lib/common/dynamic_class.rb +23 -0
  18. data/lib/common/generic_model.rb +0 -0
  19. data/lib/common/hash_with_indifferent_access.rb +352 -0
  20. data/lib/common/method_attr.rb +69 -0
  21. data/lib/lux/api/api.rb +26 -27
  22. data/lib/lux/api/lib/application_api.rb +26 -7
  23. data/lib/lux/api/lib/doc_builder.rb +18 -17
  24. data/lib/lux/api/lib/dsl.rb +23 -41
  25. data/lib/lux/api/lib/error.rb +3 -0
  26. data/lib/lux/api/lib/model_api.rb +22 -20
  27. data/lib/lux/api/lib/rescue.rb +5 -15
  28. data/lib/lux/api/lib/response.rb +46 -0
  29. data/lib/lux/cache/cache.rb +13 -6
  30. data/lib/lux/cell/cell.rb +3 -14
  31. data/lib/lux/config/config.rb +4 -3
  32. data/lib/lux/controller/controller.rb +3 -3
  33. data/lib/lux/controller/lib/nav.rb +6 -2
  34. data/lib/lux/error/error.rb +15 -14
  35. data/lib/lux/helper/helper.rb +5 -5
  36. data/lib/lux/helper/lib/html_tag.rb +67 -0
  37. data/lib/lux/html/lib/input_types.rb +26 -16
  38. data/lib/lux/lib/lux.rb +51 -0
  39. data/lib/lux/lux.rb +5 -52
  40. data/lib/lux/page/lib/response.rb +178 -0
  41. data/lib/lux/page/page.rb +72 -51
  42. data/lib/lux/rescue_from/rescue_from.rb +8 -6
  43. data/lib/lux/template/template.rb +1 -0
  44. data/lib/lux-fw.rb +2 -0
  45. data/lib/overload/array.rb +4 -0
  46. data/lib/overload/date.rb +2 -0
  47. data/lib/overload/hash.rb +19 -10
  48. data/lib/overload/it.rb +29 -0
  49. data/lib/overload/object.rb +3 -19
  50. data/lib/overload/r.rb +53 -0
  51. data/lib/overload/string.rb +5 -6
  52. data/lib/overload/string_inflections.rb +4 -3
  53. data/lib/plugins/assets/assets_plug.rb +9 -4
  54. data/lib/plugins/assets/helper_module_adapter.rb +4 -2
  55. data/lib/plugins/db_helpers/link_plugin.rb +2 -2
  56. data/lib/plugins/db_logger/init.rb +1 -1
  57. data/lib/vendor/mini_assets/lib/asset/css.rb +19 -0
  58. data/lib/vendor/mini_assets/lib/asset/js.rb +17 -0
  59. data/lib/vendor/mini_assets/lib/asset.rb +71 -0
  60. data/lib/vendor/mini_assets/lib/base/javascript.rb +13 -0
  61. data/lib/vendor/mini_assets/lib/base/stylesheet.rb +5 -0
  62. data/lib/vendor/mini_assets/lib/base.rb +69 -0
  63. data/lib/vendor/mini_assets/lib/manifest.rb +18 -0
  64. data/lib/vendor/mini_assets/lib/opts.rb +16 -0
  65. data/lib/vendor/mini_assets/mini_assets.rb +74 -0
  66. metadata +23 -10
  67. data/lib/common/class_method_params.rb +0 -94
  68. data/lib/overload/hash_wia.rb +0 -282
  69. data/lib/overload/inflections.rb +0 -199
  70. data/lib/vendor/mini_assets/mini_asset/base.rb +0 -167
  71. data/lib/vendor/mini_assets/mini_asset/css.rb +0 -38
  72. data/lib/vendor/mini_assets/mini_asset/js.rb +0 -38
  73. data/lib/vendor/mini_assets/mini_asset.rb +0 -31
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cf39a83b84a57cdc4523101a880a856a274723a
4
- data.tar.gz: 850600181673ff261e0180dd862993060d153b26
3
+ metadata.gz: 8da4e12f599558882464c2d4adaf26f4368c541d
4
+ data.tar.gz: cb2320787caf49b7b48308d5915fe2abf8945101
5
5
  SHA512:
6
- metadata.gz: d47ecd1b0aac507cb33613bcdb2b2aaa1d8ff11952a5ae8a2bd40d54c8c60108d3b176a7db79c2108bbcb2cf74e1aaf52bc7b3a54139e15f09c44eab454df864
7
- data.tar.gz: 5eb42b08476252ea35d45d06f7cc40702f9626e8f26a44b155c815b65417030ca68ddb05b93d493c66ae650208b1ddb2c9a9038fdd81500cd5f2588e3434870d
6
+ metadata.gz: 0c3f4d5c4cf8e072ec3559bd9b385454aab6dc914be9aa6a15b1d442e8ab255d548d0d0fb86285af9cdc6d489589a18e7a5baeaedeb7cb743d9ee52a8a43baaa
7
+ data.tar.gz: 0222f98dc1a343a2dd2077f0f88a077c8bd19bcb3c0ca0a08543d003a767bf3d7f816c69fdac95b68d4b7f60fe918c82001918c54b50d3f86b4c4437121392c7
data/.version CHANGED
@@ -1 +1 @@
1
- 0.1.17
1
+ 0.1.35
data/bin/cli/am CHANGED
@@ -10,32 +10,27 @@ class AutoMigrate
10
10
  class << self
11
11
  def table(table_name)
12
12
  die "table [#{table_name}] not in plural -> expected [#{table_name.to_s.pluralize}]" unless table_name.to_s.pluralize == table_name.to_s
13
- klass = table_name.to_s.classify
14
- unless Object.const_defined?(klass)
15
- puts "model #{klass} not defiend for table #{table_name}".red
16
- exit
17
- end
18
13
 
19
14
  unless DB.table_exists?(table_name.to_s)
20
15
  # http://sequel.jeremyevans.net/rdoc/files/doc/schema_modification_rdoc.html
21
16
  DB.create_table table_name do
22
17
  primary_key :id, Integer
23
- index :id, :unique=>true
18
+ index :id, unique: true
24
19
  end
25
20
  end
26
21
 
27
- t = new(table_name)
28
- yield(t)
22
+ t = new table_name
23
+ yield t
29
24
  t.fix_fields
30
25
  t.update
31
26
  end
32
27
 
33
- def migrate(&block)
34
- instance_eval(&block)
28
+ def migrate &block
29
+ instance_eval &block
35
30
  end
36
31
 
37
- def enable_extension(name)
38
- DB.run "CREATE EXTENSION IF NOT EXISTS #{name};"
32
+ def enable_extension name
33
+ DB.run 'CREATE EXTENSION IF NOT EXISTS %s;' % name
39
34
  end
40
35
 
41
36
  def transaction_do text
@@ -51,13 +46,13 @@ class AutoMigrate
51
46
 
52
47
  ###
53
48
 
54
- def initialize(table_name)
49
+ def initialize table_name
55
50
  @table_name = table_name
56
51
  @fields = {}
57
52
  end
58
53
 
59
- def log_run(what)
60
- puts " #{what.green}"
54
+ def log_run what
55
+ puts ' %s' % what.green
61
56
  self.class.transaction_do what
62
57
  end
63
58
 
@@ -76,16 +71,16 @@ class AutoMigrate
76
71
  end
77
72
  end
78
73
 
79
- def get_db_column_type(field)
74
+ def get_db_column_type field
80
75
  type, opts = @fields[field]
81
76
  db_type = type
82
77
  db_type = :varchar if type == :string
83
78
  db_type = Time if type == :datetime
84
79
  if opts[:array]
85
- db_type = "#{db_type}(#{opts[:limit]})" if type == :string
86
- db_type = "#{db_type}[]"
80
+ db_type = '%s(%s)' % [db_type, opts[:limit]] if type == :string
81
+ db_type = '%s[]' % db_type
87
82
  else
88
- db_type = "varchar(#{opts[:limit]})" if opts[:limit]
83
+ db_type = 'varchar(%s)' % opts[:limit] if opts[:limit]
89
84
  end
90
85
  db_type
91
86
  end
@@ -96,14 +91,13 @@ class AutoMigrate
96
91
  o = obj.new
97
92
  rescue
98
93
  puts "Object #{@table_name.to_s.classify.red} does not exist, yet table #{@table_name.to_s.red} exists!"
99
- # puts $!.message
100
94
  return
101
95
  end
102
96
 
103
97
  # remove extra fields
104
98
  existing_fields = o.attributes.keys - ['id']
105
99
  for field in (existing_fields - @fields.keys.map(&:to_s))
106
- print "Remove colum #{@table_name}.#{field} (y/N): ".blue
100
+ print "Remove colum #{@table_name}.#{field} (y/N): ".light_blue
107
101
  if STDIN.gets.chomp.downcase.index('y')
108
102
  DB.drop_column @table_name, field
109
103
  puts " drop_column #{field}".green
@@ -112,6 +106,7 @@ class AutoMigrate
112
106
 
113
107
  puts "Table #{@table_name.to_s.yellow}, #{@fields.keys.length} fields"
114
108
 
109
+ # loop trough defined fileds in schema
115
110
  for field, opts_in in @fields
116
111
  type = opts_in[0]
117
112
  opts = opts_in[1]
@@ -133,7 +128,12 @@ class AutoMigrate
133
128
  end
134
129
 
135
130
  if current = obj.db_schema[field.to_sym]
136
- # limit changed
131
+ # unhandled db schema changes will not happen
132
+ # ---
133
+ # field - field name
134
+ # current - current db_schema
135
+ # type - new proposed type in schema
136
+ # opts - new proposed types
137
137
 
138
138
  # if we have type set as array and in db it is not array, fix that
139
139
  if opts[:array] && !current[:db_type].include?('[]')
@@ -159,12 +159,13 @@ class AutoMigrate
159
159
  puts " Coverted #{@table_name}.#{field}[] to non array type".red
160
160
  end
161
161
 
162
- # ap "#{@table_name}, #{field}, #{db_type}, #{current[:max_length]}, #{opts[:limit]}" if field == 'description'
162
+ # if varchar limit size has changed
163
163
  if type == :string && current[:max_length] != opts[:limit]
164
164
  self.class.transaction_do "ALTER TABLE #{@table_name} ALTER COLUMN #{field} TYPE varchar(#{opts[:limit]});"
165
165
  puts " #{field} limit, #{current[:max_length]}-> #{opts[:limit]}".green
166
166
  end
167
167
 
168
+ # covert from varchar to text
168
169
  if type == :text && current[:max_length]
169
170
  self.class.transaction_do "ALTER TABLE #{@table_name} ALTER COLUMN #{field} SET DATA TYPE text"
170
171
  puts " #{field} limit from #{current[:max_length]} to no limit (text type)".green
@@ -176,6 +177,13 @@ class AutoMigrate
176
177
  log_run "ALTER TABLE #{@table_name} ALTER COLUMN #{to_run}"
177
178
  end
178
179
 
180
+ # covert string to date
181
+ if current[:type] == :string && [:date, :datetime].include?(type)
182
+ log_run "ALTER TABLE #{@table_name} ALTER COLUMN #{field} TYPE #{type.to_s.upcase} using #{field}::#{type};"
183
+ end
184
+
185
+ #ap [current, field, type, opts] if current[:type] == :string && @table_name == :informators
186
+
179
187
  # field default changed
180
188
  if current[:default].to_s != opts[:default].to_s
181
189
  # skip for arrays
@@ -198,9 +206,8 @@ class AutoMigrate
198
206
 
199
207
  end
200
208
 
201
- def add_index(field)
209
+ def add_index field
202
210
  type = @table_name.to_s.classify.constantize.new.db_schema[field][:db_type] rescue nil
203
- # puts "#{field.to_s.yellow} (#{type})"
204
211
 
205
212
  begin
206
213
  if type.index('[]')
@@ -213,9 +220,10 @@ class AutoMigrate
213
220
  rescue; end
214
221
  end
215
222
 
216
- def rename(field_old, field_new)
223
+ def rename field_old, field_new
217
224
  existing_fields = @table_name.to_s.classify.constantize.new.attributes.keys.map(&:to_sym)
218
- if existing_fields.index(field_old) && ! existing_fields.index(field_new)
225
+
226
+ if existing_fields.index(field_old.to_sym) && ! existing_fields.index(field_new.to_sym)
219
227
  DB.rename_column(@table_name, field_old, field_new)
220
228
  puts " * renamed #{@table_name}.#{field_old} to #{@table_name}.#{field_new}"
221
229
  puts ' * please run auto migration again'
@@ -223,9 +231,10 @@ class AutoMigrate
223
231
  end
224
232
  end
225
233
 
226
- def method_missing(type, *args)
234
+ def method_missing type, *args
227
235
  name = args[0]
228
236
  opts = args[1] || {}
237
+
229
238
  if [:string, :integer, :text, :boolean, :datetime, :date, :jsonb].index(type)
230
239
  @fields[name] = [type, opts]
231
240
  elsif [:decimal].index(type)
@@ -235,7 +244,7 @@ class AutoMigrate
235
244
  elsif type == :timestamps
236
245
  opts[:null] ||= false
237
246
  @fields[:created_at] = [:datetime, opts]
238
- @fields[:created_by] = [:integer, opts.merge(index: true)]
247
+ @fields[:created_by] = [:integer, opts]
239
248
  @fields[:updated_at] = [:datetime, opts]
240
249
  @fields[:updated_by] = [:integer, opts]
241
250
  elsif type == :polymorphic
data/bin/cli/assets CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ ENV['RACK_ENV'] = 'production'
4
+
3
5
  if ARGV[0] == 'help'
4
6
  puts 'lux assets rm gzip s3://assets'
5
7
  puts ' rm - remove local cached folder for assets'
@@ -15,7 +17,7 @@ end
15
17
 
16
18
  require './config/application'
17
19
 
18
- assets = Dir['./app/assets/*/index.*'].map { |el| el.sub('./app/assets/','') }
20
+ assets = Dir['./app/assets/**/index.*'].map { |el| el.sub('./app/assets/','') }
19
21
 
20
22
  Lux.config.assets_precompile = true
21
23
 
@@ -23,9 +25,11 @@ speed = Lux.speed do
23
25
  # tpool is not showing compile errors
24
26
  # tpool(assets) do |file|
25
27
  for file in assets
26
- asset = MiniAsset.create file
27
- asset.compile ARGV
28
- puts "Generated #{file.green} -> #{asset.production_file}"
28
+ assets = MiniAssets.new file
29
+
30
+ # asset = MiniAsset.create file
31
+ # asset.compile ARGV
32
+ puts "Generated #{file.green} -> #{assets.render}"
29
33
  end
30
34
  end
31
35
 
data/bin/cli/exceptions CHANGED
@@ -22,13 +22,13 @@ show = ARGV[0] ? ARGV[0].to_i : nil
22
22
  error_folders = Dir['%s/*' % ERROR_FOLDER].sort_by { |x| File.mtime(x) }
23
23
 
24
24
  if error_folders.length == 0
25
- puts 'Nothing found in %s'.blue % ERROR_FOLDER
25
+ puts 'Nothing found in %s'.light_blue % ERROR_FOLDER
26
26
  exit
27
27
  end
28
28
 
29
29
  cnt = 0
30
30
 
31
- puts 'Add error number as last argument to show full erros'.blue
31
+ puts 'Add error number as last argument to show full erros'.light_blue
32
32
 
33
33
  error_folders.each do |error_folder|
34
34
  cnt += 1
@@ -41,13 +41,13 @@ error_folders.each do |error_folder|
41
41
  last_update = (Time.now - File.mtime(file)).to_i
42
42
 
43
43
  if last_update < 60
44
- print '%s sec ago - ' % last_update.to_s.blue
44
+ print '%s sec ago - ' % last_update.to_s.light_blue
45
45
  elsif last_update < 60*60
46
- print '%s mins ago - ' % (last_update/60).to_i.to_s.blue
46
+ print '%s mins ago - ' % (last_update/60).to_i.to_s.light_blue
47
47
  elsif last_update < 60*60*24
48
- print '%s hours ago - ' % (last_update/(60*60)).to_i.to_s.blue
48
+ print '%s hours ago - ' % (last_update/(60*60)).to_i.to_s.light_blue
49
49
  else
50
- print '%s days ago - ' % (last_update/(60*60*24)).to_i.to_s.blue
50
+ print '%s days ago - ' % (last_update/(60*60*24)).to_i.to_s.light_blue
51
51
  end
52
52
 
53
53
  puts file.split('/').last
data/bin/cli/generate CHANGED
File without changes
data/bin/cli/get CHANGED
File without changes
data/bin/cli/nginx CHANGED
@@ -2,15 +2,21 @@
2
2
 
3
3
  command = ARGV[0]
4
4
 
5
- @local_conf = './config/nginx.conf'
6
- @nginx_conf = '/etc/nginx/sites-enabled/%s.conf' % Dir.pwd.split('/').last
5
+ ROOT = Dir.pwd
6
+ FOLDER = Dir.pwd.split('/').last
7
+
8
+ @local_conf = './config/nginx.conf'
9
+ @target_conf = '/etc/nginx/sites-enabled/%s.conf' % FOLDER
7
10
 
8
11
  def build_conf
9
12
  conf = File.read(@local_conf) rescue LuxCli.die('Local conf %s not found' % @local_conf)
10
13
 
11
14
  LuxCli.die('$ROOT not found in config') unless conf.include?('$ROOT')
12
15
 
13
- conf.gsub('$ROOT', Dir.pwd)
16
+ conf = conf.gsub(/`([^`]+)`/) { `#{$1}`.chomp }
17
+ conf = conf.gsub('$ROOT', ROOT)
18
+ conf = conf.gsub('$FOLDER', FOLDER)
19
+ conf
14
20
  end
15
21
 
16
22
  case command
@@ -20,9 +26,9 @@ case command
20
26
  File.write './tmp/nginx.conf', build_conf
21
27
  puts '# run this manualy'
22
28
  puts
23
- puts 'sudo cp ./tmp/nginx.conf %s && sudo nginx -t' % @nginx_conf
29
+ puts 'sudo cp ./tmp/nginx.conf %s && sudo nginx -t' % @target_conf
24
30
  else
25
31
  puts ' show # show rendered config'
26
- puts ' install # install config/nginx.conf to %s' % @nginx_conf
32
+ puts ' install # install config/nginx.conf to %s' % @target_conf
27
33
  end
28
34
 
data/bin/cli/routes CHANGED
File without changes
data/bin/cli/systemd ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ROOT = Dir.pwd
4
+ FOLDER = Dir.pwd.split('/').last.split('.').first
5
+
6
+ command = ARGV[0]
7
+
8
+ @local_conf = './config/systemd.service'
9
+ @target_conf = '/etc/systemd/system/%s.service' % FOLDER
10
+
11
+ def build_conf
12
+ conf = File.read(@local_conf) rescue LuxCli.die('Local conf %s not found' % @local_conf)
13
+
14
+ LuxCli.die('$ROOT not found in config') unless conf.include?('$ROOT')
15
+
16
+ conf = conf.gsub(/`([^`]+)`/) { `#{$1}`.chomp }
17
+ conf = conf.gsub('$ROOT', ROOT)
18
+ conf = conf.gsub('$FOLDER', FOLDER)
19
+ conf
20
+ end
21
+
22
+ case command
23
+ when 'show'
24
+ puts build_conf
25
+ when 'install'
26
+ File.write './tmp/systemd.conf', build_conf
27
+ puts '# run this manualy'
28
+ puts
29
+ puts 'sudo cp ./tmp/systemd.conf %s && sudo systemd -t' % @target_conf
30
+ else
31
+ puts ' show # show rendered config'
32
+ puts ' install # install %s to %s' % [@local_conf, @target_conf]
33
+ puts ' ---'
34
+ puts ' sudo service %s start/stop/restart'.yellow % FOLDER
35
+ end
36
+
data/bin/forever CHANGED
File without changes
data/bin/job_que CHANGED
File without changes
data/bin/lux CHANGED
@@ -56,6 +56,7 @@ commands['nginx'] = 'parse and install config/nginx.conf'
56
56
  commands['production'] = 'run puma in production mode'
57
57
  commands['routes'] = 'list routes'
58
58
  commands['server'] = 'run puma development server'
59
+ commands['systemd'] = 'parse and install config/systemd.conf'
59
60
  commands['stat'] = 'goaccess stat to public/goaccess.html'
60
61
 
61
62
  command = ARGV.shift
data/lib/common/base32.rb CHANGED
File without changes
@@ -35,17 +35,18 @@ module ClassAttributes
35
35
 
36
36
  ::ClassAttributes::CA_DEFAULTS[name] = { 'Object'=>default }
37
37
 
38
- klass.class.send(:define_method, name) do |*args|
38
+ klass.define_singleton_method('%s=' % name) { |*args| send name, *args}
39
+ klass.define_singleton_method(name) do |*args|
39
40
  root = ::ClassAttributes::CA_DEFAULTS[name]
40
41
 
41
42
  # set and return if argument defined
42
- return root[self.to_s] = args[0] if args.length > 0
43
+ return root[to_s] = args[0] if args.length > 0
43
44
 
44
45
  # find value and return
45
- self.ancestors.map(&:to_s).each do |el|
46
+ ancestors.map(&:to_s).each do |el|
46
47
  value = root[el]
47
48
  if value || el == 'Object'
48
- value = self.instance_exec(&value) if value.is_a?(Proc)
49
+ value = instance_exec(&value) if value.is_a?(Proc)
49
50
  return value
50
51
  end
51
52
  end
@@ -53,8 +54,10 @@ module ClassAttributes
53
54
  end
54
55
 
55
56
  # defines class variable in current lux thread
57
+ # User.current = @user
56
58
  def current klass, name
57
59
  klass.class.send(:define_method, name) do |*args|
60
+ Thread.current[:lux] ||= {}
58
61
  Thread.current[:lux]['%s-%s' % [klass, name]]
59
62
  end
60
63
 
@@ -64,3 +67,9 @@ module ClassAttributes
64
67
  end
65
68
  end
66
69
  end
70
+
71
+ class Object
72
+ def class_attribute name, default=nil, &block
73
+ ClassAttributes.define self, name, default, &block
74
+ end
75
+ end
data/lib/common/crypt.rb CHANGED
@@ -41,25 +41,21 @@ module Crypt
41
41
  # Crypt.encrypt('secret')
42
42
  # Crypt.encrypt('secret', ttl:1.hour, password:'pa$$w0rd')
43
43
  def encrypt(data, opts={})
44
- diff = opts.keys - [:ttl, :password]
45
- raise 'Unallowed key(s) found %s' % diff.join(', ') if diff.length > 0
44
+ opts = opts.to_opts!(:ttl, :password)
46
45
 
47
46
  payload = { data:data }
48
- payload[:ttl] = Time.now.to_i + opts[:ttl] if opts[:ttl]
49
- hmac_secret = "#{secret}#{opts.delete(:password)}"
50
- JWT.encode payload, hmac_secret, ALGORITHM
47
+ payload[:ttl] = Time.now.to_i + opts.ttl if opts.ttl
48
+ JWT.encode payload, secret+opts.password.to_s, ALGORITHM
51
49
  end
52
50
 
53
51
  # Crypt.decrypt('secret')
54
52
  # Crypt.decrypt('secret', password:'pa$$w0rd')
55
53
  def decrypt(token, opts={})
56
- diff = opts.keys - [:password]
57
- raise 'Unallowed key(s) found %s' % diff.join(', ') if diff.length > 0
54
+ opts = opts.to_opts!(:password)
58
55
 
59
- hmac_secret = "#{secret}#{opts.delete(:password)}"
60
- token_data = JWT.decode token, hmac_secret, true, { :algorithm => ALGORITHM }
56
+ token_data = JWT.decode token, secret+opts.password.to_s, true, { :algorithm => ALGORITHM }
61
57
  data = token_data[0]
62
- raise "Crpted data expired before #{Time.now.to_i - data['ttl']} seconds" if data['ttl'] && data['ttl'] < Time.now.to_i
58
+ raise "Crypted data expired before #{Time.now.to_i - data.ttl} seconds" if data['ttl'] && data['ttl'] < Time.now.to_i
63
59
  data['data']
64
60
  end
65
61
 
@@ -0,0 +1,23 @@
1
+ # o = DynamicClass.new a: 'b'
2
+ # o.a -> 'b'
3
+ # o.b -> raises error
4
+ class DynamicClass
5
+ def initialize data, &block
6
+ @data = data
7
+ @block = block if block
8
+ end
9
+
10
+ def method_missing m, *args, &block
11
+ key = m.to_s.sub('=','').to_sym
12
+
13
+ unless @data.has_key?(key)
14
+ raise ArgumentError.new('Key :%s not found in DynamicOptions' % key)
15
+ end
16
+
17
+ if m.to_s.include?('=')
18
+ @data[key] = args[0]
19
+ else
20
+ @data[key]
21
+ end
22
+ end
23
+ end
File without changes