ixtlan-core 0.2.0 → 0.4.0

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.
@@ -20,7 +20,7 @@ module Ixtlan
20
20
  end
21
21
 
22
22
  if defined? ::Ixtlan::Errors
23
- args << "errors_keep_dumps:integer"
23
+ args << "errors_keep_dump:integer"
24
24
  args << "errors_dir:string"
25
25
  args << "errors_from:string"
26
26
  args << "errors_to:string"
@@ -4,11 +4,12 @@
4
4
  # -------------------
5
5
  # CONFIGURATION = Configuration
6
6
  # config.configuration_model = CONFIGURATION
7
- <% if defined? DataMapper -%>
8
- # config_instance = CONFIGURATION.get(1) || CONFIGURATION.new
9
- <% else -%>
10
- # config_instance = CONFIGURATION.find(1) || CONFIGURATION.new
11
- <%end -%>
7
+ begin
8
+ config_instance = CONFIGURATION.instance
9
+ rescue
10
+ # allow rake tasks to work without configuration migrated
11
+ return
12
+ end
12
13
 
13
14
  # notification email on errors and dump directory for the system dump
14
15
  # the error dumps will be cleanup after the days to keeps dump expired
@@ -17,7 +18,7 @@
17
18
  # Rails.configuration.error_dumper.dump_dir = config.errors_dir
18
19
  # Rails.configuration.error_dumper.email_from = config.errors_from
19
20
  # Rails.configuration.error_dumper.email_to = config.errors_to
20
- # Rails.configuration.error_dumper.keep_dumps = config.errors_keep_dumps # days
21
+ # Rails.configuration.error_dumper.keep_dumps = config.errors_keep_dump # days
21
22
  # end
22
23
 
23
24
  # idle session timeout configuration (in minutes)
@@ -0,0 +1,40 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveRecord
4
+ module Generators
5
+ class ModelGenerator < Base
6
+ include ::Ixtlan::Core::Singleton
7
+
8
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
9
+
10
+ check_class_collision
11
+
12
+ class_option :migration, :type => :boolean
13
+ class_option :timestamps, :type => :boolean
14
+ class_option :parent, :type => :string, :desc => "The parent class for the generated model"
15
+
16
+ def create_migration_file
17
+ return unless options[:migration] && options[:parent].nil?
18
+ migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
19
+ end
20
+
21
+ def create_model_file
22
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
23
+ end
24
+
25
+ def create_module_file
26
+ return if class_path.empty?
27
+ template 'module.rb', File.join('app/models', "#{class_path.join('/')}.rb") if behavior == :invoke
28
+ end
29
+
30
+ hook_for :test_framework
31
+
32
+ protected
33
+
34
+ def parent_class_name
35
+ options[:parent] || "ActiveRecord::Base"
36
+ end
37
+
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ require 'rails/generators/erb'
2
+ require 'rails/generators/resource_helpers'
3
+
4
+ module Erb
5
+ module Generators
6
+ class ScaffoldGenerator < Base
7
+ include Rails::Generators::ResourceHelpers
8
+
9
+ class_option :optimistic, :type => :boolean, :default => false
10
+ class_option :singleton, :type => :boolean, :default => false
11
+ class_option :timestamps, :type => :boolean, :default => true
12
+
13
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
14
+
15
+ def create_root_folder
16
+ empty_directory File.join("app/views", controller_file_path)
17
+ end
18
+
19
+ def copy_view_files
20
+ available_views.each do |view|
21
+ filename = filename_with_extensions(view)
22
+ template filename, File.join("app/views", controller_file_path, filename)
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def available_views
29
+ if options[:singleton]
30
+ %w(edit show _form)
31
+ else
32
+ %w(index edit show new _form)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -20,6 +20,9 @@
20
20
  </div><!-- end - <%= attribute.name %> -->
21
21
  <% end -%>
22
22
  <div class="actions">
23
+ <% if options[:optimistic] && options[:timestamps] -%>
24
+ <%%= f.hidden_field :updated_at %>
25
+ <% end -%>
23
26
  <%%= f.submit %>
24
27
  </div>
25
28
  <%% end %>
@@ -28,7 +28,9 @@
28
28
  <%% end %>
29
29
  <%% if allowed?(:<%= table_name %>, :destroy) %>
30
30
  <% end -%>
31
- <td><%%= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete %></td>
31
+ <td><% if options[:optimistic] && options[:timestamps] -%>
32
+ <%%= link_to 'Destroy', <%= singular_table_name %>_path(<%= singular_table_name %>) + "?<%= singular_table_name %>[updated_at]=#{<%= singular_table_name %>.updated_at.utc.strftime('%Y-%m-%d %H:%M:%S.%N')}", :confirm => 'Are you sure?', :method => :delete %><% else -%><%%= link_to 'Destroy', <%= singular_table_name %>, :confirm => 'Are you sure?', :method => :delete %>
33
+ <% end -%></td>
32
34
  <% if defined? ::Ixtlan::Guard -%>
33
35
  <%% end %>
34
36
  <% end -%>
@@ -61,7 +61,23 @@ class <%= controller_class_name %>Controller < ApplicationController
61
61
  # PUT <%= route_url %>/1.xml
62
62
  # PUT <%= route_url %>/1.json
63
63
  def update
64
+ <% if options[:optimistic] && options[:timestamps] -%>
65
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "(params[:#{singular_table_name}]||[]).delete(:updated_at), params[:id]").sub(/\.(get|find)/, '.optimistic_\1') %>
66
+
67
+ if @<%= singular_table_name %>.nil?
68
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
69
+ respond_to do |format|
70
+ format.html { render :action => "edit" }
71
+ format.xml { render :xml => nil, :status => :conflict }
72
+ format.json { render :json => nil, :status => :conflict }
73
+ end
74
+ return
75
+ end
76
+ <% else -%>
64
77
  @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
78
+ (params[:<%= singular_table_name %>]||[]).delete(:updated_at)
79
+ <% end -%>
80
+ (params[:<%= singular_table_name %>]||[]).delete(:id)
65
81
  <% if options[:modified_by] -%>
66
82
  @<%= singular_table_name %>.current_user = current_user
67
83
  <% end -%>
@@ -83,7 +99,21 @@ class <%= controller_class_name %>Controller < ApplicationController
83
99
  # DELETE <%= route_url %>/1.xml
84
100
  # DELETE <%= route_url %>/1.json
85
101
  def destroy
102
+ <% if options[:optimistic] && options[:timestamps] -%>
103
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "(params[:#{singular_table_name}]||[]).delete(:updated_at), params[:id]").sub(/\.(get|find)/, '.optimistic_\1') %>
104
+
105
+ if @<%= singular_table_name %>.nil?
106
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
107
+ respond_to do |format|
108
+ format.html { render :action => "edit" }
109
+ format.xml { render :xml => nil, :status => :conflict }
110
+ format.json { render :json => nil, :status => :conflict }
111
+ end
112
+ return
113
+ end
114
+ <% else -%>
86
115
  @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
116
+ <% end -%>
87
117
  <% if options[:modified_by] -%>
88
118
  @<%= singular_table_name %>.current_user = current_user
89
119
  <% end -%>
@@ -15,6 +15,10 @@ module Rails
15
15
  hook_for :resty, :type => :boolean, :default => true
16
16
  end
17
17
 
18
+ if defined? ::Ixtlan::Guard
19
+ hook_for :guard, :type => :boolean, :default => true
20
+ end
21
+
18
22
  def add_resource_route
19
23
  return if options[:actions].present?
20
24
  route_config = class_path.collect{|namespace| "namespace :#{namespace} do " }.join(" ")
@@ -6,14 +6,14 @@ module ScaffoldController
6
6
  class ScaffoldControllerGenerator < ::Rails::Generators::NamedBase
7
7
  include ::Rails::Generators::ResourceHelpers
8
8
 
9
- source_root File.expand_path('../templates', __FILE__)
10
-
11
9
  check_class_collision :suffix => "Controller"
12
10
 
13
11
  class_option :orm, :banner => "NAME", :type => :string, :required => true,
14
12
  :desc => "ORM to generate the controller for"
15
13
 
16
14
  class_option :singleton, :type => :boolean, :default => false
15
+ class_option :optimistic, :type => :boolean, :default => false
16
+ class_option :timestamps, :type => :boolean, :default => true
17
17
 
18
18
  def create_controller_files
19
19
  if options[:singleton]
@@ -29,20 +29,6 @@ module ScaffoldController
29
29
  hook_for :helper, :as => :scaffold, :in => :rails do |invoked|
30
30
  invoke invoked, [ controller_name ]
31
31
  end
32
-
33
- if defined? ::Resty
34
- # resty gwt controller
35
- hook_for :resty, :type => :boolean, :default => true do |controller|
36
- invoke controller, [class_name]
37
- end
38
- end
39
-
40
- if defined? ::Ixtlan::Guard
41
- # allow the ixtlan guards to be generated
42
- hook_for :guard, :type => :boolean, :default => true do |controller|
43
- invoke controller, [class_name]
44
- end
45
- end
46
32
  end
47
33
  end
48
34
  end
@@ -0,0 +1,17 @@
1
+ module Ixtlan
2
+ module Core
3
+ module OptimisticActiveRecord
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ def self.optimistic_find(updated_at, *args)
8
+ updated_at_date = new(:updated_at => updated_at).updated_at
9
+ # try different ways to use the date
10
+ first(:conditions => ["id = ? and updated_at = ?", args[0], updated_at_date]) || first(:conditions => ["id = ? and updated_at = ?", args[0], updated_at])
11
+ # TODO make it work with different PKs
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ module Ixtlan
2
+ module Core
3
+ module OptimisticDataMapper
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ def optimistic_find(updated_at, *args)
8
+ updated_at = new(:updated_at => updated_at).updated_at
9
+ # TODO make it work with different PKs
10
+ first(:id => args[0], :updated_at => updated_at)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,36 +1,41 @@
1
1
  require 'ixtlan/core/extra_headers'
2
2
  require 'ixtlan/core/cache_headers'
3
3
  require 'ixtlan/core/x_frame_headers'
4
+ require 'ixtlan/core/optimistic_active_record'
5
+ require 'ixtlan/core/optimistic_data_mapper'
4
6
  require 'ixtlan/core/configuration_rack'
5
7
  require 'ixtlan/core/configuration_manager'
6
-
7
8
  module Ixtlan
8
9
  module Core
9
- class Railtie < Rails::Railtie
10
- config.generators do
11
- require 'rails/generators'
12
-
13
- templates = File.expand_path('../../../generators/rails/templates', __FILE__)
14
-
15
- require 'rails/generators/erb/scaffold/scaffold_generator'
16
- Erb::Generators::ScaffoldGenerator.source_paths.insert(0, templates)
17
- Erb::Generators::ScaffoldGenerator.class_option :singleton, :type => :boolean, :default => false
18
- Erb::Generators::ScaffoldGenerator.class_eval do
10
+
11
+ module Singleton
12
+
13
+ def self.included(base)
14
+ base.class_eval do
15
+ class_option :singleton, :type => :boolean, :default => false
16
+
17
+ if self.class.to_s =~ /ScaffoldGenerator$/
19
18
 
20
- protected
21
- alias :available_views_old :available_views
22
- def available_views
23
- if options[:singleton]
24
- %w(edit show _form)
25
- else
26
- available_views_old
19
+ protected
20
+ alias :available_views_old :available_views
21
+ def available_views
22
+ if options[:singleton]
23
+ %w(new create edit show destroy _form)
24
+ else
25
+ available_views_old
26
+ end
27
27
  end
28
+
28
29
  end
29
30
  end
31
+ end
32
+ end
33
+
34
+ class Railtie < Rails::Railtie
35
+ config.generators do |config|
36
+
37
+ config.templates << File.expand_path('../../../generators/rails', __FILE__)
30
38
 
31
- require 'rails/generators/active_record/model/model_generator'
32
- ActiveRecord::Generators::ModelGenerator.source_paths.insert(0, templates)
33
- ActiveRecord::Generators::ModelGenerator.class_option :singleton, :type => :boolean, :default => false
34
39
  end
35
40
 
36
41
  config.before_configuration do |app|
@@ -54,6 +59,19 @@ module Ixtlan
54
59
 
55
60
  app.config.middleware.use Ixtlan::Core::ConfigurationRack
56
61
  end
62
+ config.after_initialize do |app|
63
+ if defined? DataMapper
64
+
65
+ ::DataMapper::Resource.send(:include,
66
+ Ixtlan::Core::OptimisticDataMapper)
67
+
68
+ elsif defined? ActiveRecord
69
+
70
+ ::ActiveRecord::Base.send(:include,
71
+ Ixtlan::Core::OptimisticActiveRecord)
72
+
73
+ end
74
+ end
57
75
  end
58
76
  end
59
77
  end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ixtlan-core
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
4
+ prerelease:
5
+ version: 0.4.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - mkristian
@@ -14,27 +10,20 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2011-04-03 00:00:00 +05:30
13
+ date: 2011-07-23 00:00:00 +05:30
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
17
  name: slf4r
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
24
21
  requirements:
25
22
  - - ">="
26
23
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 4
30
- - 2
31
24
  version: 0.4.2
32
25
  - - <
33
26
  - !ruby/object:Gem::Version
34
- segments:
35
- - 0
36
- - 4
37
- - 99999
38
27
  version: 0.4.99999
39
28
  type: :runtime
40
29
  version_requirements: *id001
@@ -42,41 +31,32 @@ dependencies:
42
31
  name: rails
43
32
  prerelease: false
44
33
  requirement: &id002 !ruby/object:Gem::Requirement
34
+ none: false
45
35
  requirements:
46
36
  - - "="
47
37
  - !ruby/object:Gem::Version
48
- segments:
49
- - 3
50
- - 0
51
- - 5
52
- version: 3.0.5
38
+ version: 3.0.9
53
39
  type: :development
54
40
  version_requirements: *id002
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rspec
57
43
  prerelease: false
58
44
  requirement: &id003 !ruby/object:Gem::Requirement
45
+ none: false
59
46
  requirements:
60
47
  - - "="
61
48
  - !ruby/object:Gem::Version
62
- segments:
63
- - 2
64
- - 4
65
- - 0
66
- version: 2.4.0
49
+ version: 2.6.0
67
50
  type: :development
68
51
  version_requirements: *id003
69
52
  - !ruby/object:Gem::Dependency
70
53
  name: cucumber
71
54
  prerelease: false
72
55
  requirement: &id004 !ruby/object:Gem::Requirement
56
+ none: false
73
57
  requirements:
74
58
  - - "="
75
59
  - !ruby/object:Gem::Version
76
- segments:
77
- - 0
78
- - 9
79
- - 4
80
60
  version: 0.9.4
81
61
  type: :development
82
62
  version_requirements: *id004
@@ -84,19 +64,11 @@ dependencies:
84
64
  name: ruby-maven
85
65
  prerelease: false
86
66
  requirement: &id005 !ruby/object:Gem::Requirement
67
+ none: false
87
68
  requirements:
88
69
  - - "="
89
70
  - !ruby/object:Gem::Version
90
- segments:
91
- - 0
92
- - 8
93
- - 3
94
- - 0
95
- - 2
96
- - 0
97
- - 26
98
- - 0
99
- version: 0.8.3.0.2.0.26.0
71
+ version: 0.8.3.0.3.0.28.3
100
72
  type: :development
101
73
  version_requirements: *id005
102
74
  description: base for some gems related to protect privacy and increase security along some other utils
@@ -113,35 +85,39 @@ files:
113
85
  - lib/ixtlan-core.rb
114
86
  - lib/generators/model/model_generator.rb
115
87
  - lib/generators/scaffold/scaffold_generator.rb
88
+ - lib/generators/scaffold_controller/scaffold_controller_generator.rb
89
+ - lib/generators/rails/erb/erb_generator.rb
90
+ - lib/generators/rails/erb/scaffold/new.html.erb
91
+ - lib/generators/rails/erb/scaffold/_form.html.erb
92
+ - lib/generators/rails/erb/scaffold/index.html.erb
93
+ - lib/generators/rails/erb/scaffold/show.html.erb
94
+ - lib/generators/rails/erb/scaffold/edit.html.erb
95
+ - lib/generators/rails/scaffold_controller/scaffold_controller/controller.rb
96
+ - lib/generators/rails/scaffold_controller/scaffold_controller/singleton_controller.rb
97
+ - lib/generators/rails/active_record/active_record_generator.rb
98
+ - lib/generators/rails/active_record/model/model.rb
99
+ - lib/generators/rails/active_record/model/migration.rb
116
100
  - lib/generators/ixtlan/base.rb
117
101
  - lib/generators/ixtlan/configuration_scaffold/configuration_scaffold_generator.rb
118
102
  - lib/generators/ixtlan/setup/setup_generator.rb
119
- - lib/generators/ixtlan/setup/templates/gitignore
103
+ - lib/generators/ixtlan/setup/templates/database.yml.example
120
104
  - lib/generators/ixtlan/setup/templates/error_with_session.html.erb
121
- - lib/generators/ixtlan/setup/templates/production.yml.example
122
- - lib/generators/ixtlan/setup/templates/preinitializer.rb
123
105
  - lib/generators/ixtlan/setup/templates/error.html.erb
124
- - lib/generators/ixtlan/setup/templates/database.yml.example
125
106
  - lib/generators/ixtlan/setup/templates/application_layout.html.erb
107
+ - lib/generators/ixtlan/setup/templates/preinitializer.rb
126
108
  - lib/generators/ixtlan/setup/templates/initializer.rb
109
+ - lib/generators/ixtlan/setup/templates/gitignore
127
110
  - lib/generators/ixtlan/setup/templates/stale.html.erb
111
+ - lib/generators/ixtlan/setup/templates/production.yml.example
128
112
  - lib/generators/ixtlan/configuration_model/configuration_model_generator.rb
129
- - lib/generators/scaffold_controller/scaffold_controller_generator.rb
130
- - lib/generators/scaffold_controller/templates/controller.rb
131
- - lib/generators/scaffold_controller/templates/singleton_controller.rb
132
- - lib/generators/rails/templates/index.html.erb
133
- - lib/generators/rails/templates/new.html.erb
134
- - lib/generators/rails/templates/model.rb
135
- - lib/generators/rails/templates/show.html.erb
136
- - lib/generators/rails/templates/edit.html.erb
137
- - lib/generators/rails/templates/migration.rb
138
- - lib/generators/rails/templates/_form.html.erb
139
- - lib/ixtlan/core/extra_headers.rb
140
113
  - lib/ixtlan/core/x_frame_headers.rb
114
+ - lib/ixtlan/core/optimistic_data_mapper.rb
115
+ - lib/ixtlan/core/configuration_rack.rb
116
+ - lib/ixtlan/core/optimistic_active_record.rb
117
+ - lib/ixtlan/core/extra_headers.rb
118
+ - lib/ixtlan/core/cache_headers.rb
141
119
  - lib/ixtlan/core/railtie.rb
142
120
  - lib/ixtlan/core/configuration_manager.rb
143
- - lib/ixtlan/core/cache_headers.rb
144
- - lib/ixtlan/core/configuration_rack.rb
145
121
  - lib/ixtlan/core/controllers/configuration_controller.rb
146
122
  - spec/configuration_manager_spec.rb
147
123
  has_rdoc: true
@@ -155,23 +131,21 @@ rdoc_options:
155
131
  require_paths:
156
132
  - lib
157
133
  required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
158
135
  requirements:
159
136
  - - ">="
160
137
  - !ruby/object:Gem::Version
161
- segments:
162
- - 0
163
138
  version: "0"
164
139
  required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
165
141
  requirements:
166
142
  - - ">="
167
143
  - !ruby/object:Gem::Version
168
- segments:
169
- - 0
170
144
  version: "0"
171
145
  requirements: []
172
146
 
173
147
  rubyforge_project:
174
- rubygems_version: 1.3.6
148
+ rubygems_version: 1.5.1
175
149
  signing_key:
176
150
  specification_version: 3
177
151
  summary: cache header control, dynamic configuration, and rails generator templates