tiny_core 0.0.1 → 0.0.2

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.
@@ -1,5 +1,14 @@
1
1
  # require all necessary files here
2
2
 
3
+ require File.dirname(__FILE__) + '/tiny_core/application'
4
+ require File.dirname(__FILE__) + '/tiny_core/build'
5
+ require File.dirname(__FILE__) + '/tiny_core/config'
6
+ require File.dirname(__FILE__) + '/tiny_core/core_ext/dir'
7
+ require File.dirname(__FILE__) + '/tiny_core/core_ext/i18n'
8
+ require File.dirname(__FILE__) + '/tiny_core/helpers/action_list_helper'
3
9
  require File.dirname(__FILE__) + '/tiny_core/helpers/bread_crumb_helper'
4
10
  require File.dirname(__FILE__) + '/tiny_core/helpers/tabs_helper'
5
- require File.dirname(__FILE__) + '/tiny_core/build'
11
+ require File.dirname(__FILE__) + '/tiny_core/rails_ext/attr_protection'
12
+ require File.dirname(__FILE__) + '/tiny_core/rails_ext/dirty_after_save'
13
+ require File.dirname(__FILE__) + '/tiny_core/search_filter'
14
+ require File.dirname(__FILE__) + '/tiny_core/tableless_model'
@@ -0,0 +1,5 @@
1
+ module TinyCore
2
+ module Application
3
+ mattr_accessor :name
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module TinyCore
2
+ class Config
3
+ def self.method_missing(method)
4
+ if config.has_key?(method.to_s)
5
+ config[method.to_s]
6
+ else
7
+ super
8
+ end
9
+ end
10
+
11
+ def self.config
12
+ YAML.load(File.read("#{RAILS_ROOT}/config/config.yml"))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ class Dir
2
+ @@creation_number = 0;
3
+
4
+ # Creates a temp dir in location and performs the supplied code block
5
+ def self.create_tmp_dir(name, location)
6
+ @@creation_number += 1
7
+ pid = Process.pid # This doesn't work on some platforms, according to the docs. A better way to get it would be nice.
8
+ random_number = Kernel.rand(1000000000).to_s # This is to avoid a possible symlink attack vulnerability in the creation of temporary files.
9
+ complete_dir_name = "#{location}/#{name}.#{pid}.#{random_number}.#{@@creation_number}"
10
+
11
+ yield_result = Object.new
12
+
13
+ self.mkdir(complete_dir_name)
14
+
15
+ # Changing dirs must be done in a block. When you call chdir normally, really weird
16
+ # stuff starts to happen. Functions fail silently, exceptions are ignored, etc...
17
+ self.chdir(complete_dir_name) do
18
+ begin
19
+ yield_result = yield
20
+ rescue
21
+ raise
22
+ ensure
23
+ FileUtils.rmtree(["#{complete_dir_name}"])
24
+ end
25
+ end
26
+
27
+ return yield_result
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ module I18n
2
+ class << self
3
+ def with_locale(new_locale, &block)
4
+ old_locale = self.locale
5
+ self.locale = new_locale
6
+
7
+ yield
8
+ ensure
9
+ self.locale = old_locale
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ module TinyCore
2
+ module ActionListHelper
3
+ def action_list(&block)
4
+ yield builder = ActionListBuilder.new(self)
5
+ concat(builder.build!)
6
+ end
7
+
8
+ class ActionListBuilder
9
+ def initialize(template)
10
+ @template = template
11
+ @items = []
12
+ end
13
+
14
+ def method_missing(method, *args)
15
+ if @template.respond_to?(method)
16
+ @items << @template.send(method, *args)
17
+ else
18
+ super
19
+ end
20
+ end
21
+
22
+ def build!
23
+ @items.join(' | ')
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ ActionController::Base.send :helper, TinyCore::ActionListHelper
@@ -0,0 +1,25 @@
1
+ module TinyCore
2
+ module RailsExt
3
+ module AttrProtection
4
+ module ClassMethods
5
+
6
+ end
7
+
8
+ module InstanceMethods
9
+ def update_attributes_without_attr_protected(attributes)
10
+ attributes.each do |key, value|
11
+ self.send("#{key}=", value)
12
+ end
13
+ save
14
+ end
15
+ end
16
+
17
+ def self.included(receiver)
18
+ receiver.extend ClassMethods
19
+ receiver.send :include, InstanceMethods
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ ActiveRecord::Base.send :include, TinyCore::RailsExt::AttrProtection
@@ -0,0 +1,27 @@
1
+ module TinyCore
2
+ module RailsExt
3
+ module DirtyAfterSave
4
+ DIRTY_AFTER_SAVE_SUFFIXES = ['_changed_before_save?', '_change_before_save']
5
+
6
+ def self.included(base)
7
+ base.class_eval do
8
+ attr_accessor :changed_attributes_before_save
9
+ before_save { |build| build.changed_attributes_before_save = build.changes }
10
+
11
+ attribute_method_suffix *DIRTY_AFTER_SAVE_SUFFIXES
12
+ end
13
+ end
14
+
15
+ private
16
+ def attribute_changed_before_save?(attr)
17
+ changed_attributes_before_save.include?(attr)
18
+ end
19
+
20
+ def attribute_change_before_save(attr)
21
+ [changed_attributes_before_save[attr], __send__(attr)] if attribute_changed_before_save?(attr)
22
+ end
23
+ end
24
+ end
25
+ end
26
+
27
+ ActiveRecord::Base.send :include, TinyCore::RailsExt::DirtyAfterSave
@@ -0,0 +1,17 @@
1
+ class SearchFilter
2
+ attr_accessor :query
3
+
4
+ def initialize(attributes = {})
5
+ return if attributes.nil?
6
+
7
+ @query = attributes[:query]
8
+ end
9
+
10
+ def empty?
11
+ query.blank?
12
+ end
13
+
14
+ def id
15
+ 1
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ # Port me to ActiveModel in Rails 3
2
+ module TinyCore
3
+ class TablelessModel < ActiveRecord::Base
4
+ self.abstract_class = true
5
+
6
+ class_inheritable_array :columns
7
+ self.columns = []
8
+
9
+ def create_or_update # :nodoc:
10
+ errors.empty?
11
+ end
12
+
13
+ # Prevent AR from associating to this record by ID; we should be serialized instead.
14
+ private :quoted_id
15
+
16
+ class << self
17
+ def column(name, sql_type = nil, default = nil, null = true) # :nodoc:
18
+ columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
19
+ reset_column_information
20
+ end
21
+
22
+ # Do not reset @columns
23
+ def reset_column_information # :nodoc:
24
+ generated_methods.each { |name| undef_method(name) }
25
+ @column_names = @columns_hash = @content_columns = @dynamic_methods_hash = @generated_methods = nil
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ TinyCore::Application.name = '<%= class_name %>'
@@ -0,0 +1,10 @@
1
+ module <%= class_name %>
2
+ module Version
3
+ include TinyCore::Build
4
+ extend self
5
+
6
+ def version
7
+ '0.0.1'
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ class TinyCoreGenerator < Rails::Generator::NamedBase
2
+ def manifest
3
+ record do |m|
4
+ m.directory 'config/initializers'
5
+ m.directory File.join('lib', file_name)
6
+
7
+ m.template "application.rb", 'config/initializers/application.rb'
8
+ m.template "version.rb", File.join('lib', file_name, 'version.rb')
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_core
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Thomas Kadauke
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-19 00:00:00 +02:00
18
+ date: 2010-08-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -28,11 +28,22 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
 
30
30
  files:
31
- - bin/tiny_core
31
+ - lib/tiny_core/application.rb
32
32
  - lib/tiny_core/build.rb
33
+ - lib/tiny_core/config.rb
34
+ - lib/tiny_core/core_ext/dir.rb
35
+ - lib/tiny_core/core_ext/i18n.rb
36
+ - lib/tiny_core/helpers/action_list_helper.rb
33
37
  - lib/tiny_core/helpers/bread_crumb_helper.rb
34
38
  - lib/tiny_core/helpers/tabs_helper.rb
39
+ - lib/tiny_core/rails_ext/attr_protection.rb
40
+ - lib/tiny_core/rails_ext/dirty_after_save.rb
41
+ - lib/tiny_core/search_filter.rb
42
+ - lib/tiny_core/tableless_model.rb
35
43
  - lib/tiny_core.rb
44
+ - rails_generators/tiny_core/templates/application.rb
45
+ - rails_generators/tiny_core/templates/version.rb
46
+ - rails_generators/tiny_core/tiny_core_generator.rb
36
47
  has_rdoc: true
37
48
  homepage:
38
49
  licenses: []
@@ -66,6 +77,6 @@ rubyforge_project:
66
77
  rubygems_version: 1.3.7
67
78
  signing_key:
68
79
  specification_version: 3
69
- summary: Insert description here
80
+ summary: Common parts for building Tiny Applications
70
81
  test_files: []
71
82
 
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'tiny_core'
5
-
6
- # insert command code here