actic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,29 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in actic.gemspec
4
+ gemspec
5
+
6
+ #gem "rails", "3.0.0"
7
+ if File.exist? File.expand_path('../../rails', __FILE__)
8
+ #gem "rails", "3.0.0", :path => "../rails"
9
+ else
10
+ #gem "rails", "3.0.0", :git => "git://github.com/rails/rails.git"
11
+ end
12
+
13
+ platforms :jruby do
14
+ #gem 'activerecord-jdbcsqlite3-adapter'
15
+ end
16
+
17
+ platforms :ruby do
18
+ #gem "sqlite3-ruby"
19
+ if RUBY_VERSION < '1.9'
20
+ #gem "ruby-debug", ">= 0.10.3"
21
+ end
22
+ group :mongoid do
23
+ #gem "mongo"
24
+ #gem "mongoid", :git => "git://github.com/durran/mongoid.git"
25
+ #gem "bson_ext"
26
+ end
27
+ end
28
+
29
+ gem 'ri_cal', :require => 'ri_cal', :git => "git@github.com:tevio/ri_cal.git"
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "actic/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "actic"
7
+ s.version = Actic::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Steve A Martin"]
10
+ s.email = ["steve@shakewell.co.uk"]
11
+ s.homepage = "http://rubygems.org/gems/actic"
12
+ s.summary = %q{A fusion of ORM and ical}
13
+ s.description = %q{This gem includes the actic orm wrapperb and a series of generators, it is purely for rails 3}
14
+
15
+ s.rubyforge_project = "actic"
16
+
17
+ #s.add_dependency('rical', '>= 0.8.7')
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,180 @@
1
+ # Every active record model that implements the interface must
2
+ # have a string variable either in the DB or initialized in memory called "ical"
3
+
4
+ require 'ri_cal'
5
+ require 'active_support/dependencies'
6
+ require 'set'
7
+ #require 'actic/models/calendar'
8
+ #require 'actic/railtie'
9
+ module Actic
10
+ require 'actic/railtie' if defined?(Rails)
11
+ require 'actic/engine' if defined?(Rails)
12
+
13
+ def ic_respond
14
+ true
15
+ end
16
+ module Event
17
+
18
+ def ic_component
19
+ true
20
+ end
21
+
22
+ module ClassMethods; end
23
+
24
+ def self.included(base)
25
+ base.extend(ClassMethods)
26
+ base.send :after_initialize, :si
27
+ end
28
+
29
+ def ievent
30
+ @ic ? @ic : @ic = RiCal.parse_string(self.ical).first
31
+ end
32
+
33
+ def description=(desc)
34
+ ievent.description=desc; si(@ic)
35
+ end
36
+
37
+ def description
38
+ ievent.description
39
+ end
40
+
41
+ def start_time=(start)
42
+ ievent.dtstart=start; si(@ic)
43
+ end
44
+
45
+ def start_time
46
+ ievent.start_time
47
+ end
48
+
49
+ def end_time=(endt)
50
+ ievent.dtend=endt; si(@ic)
51
+ end
52
+
53
+ def end_time
54
+ ievent.end_time
55
+ end
56
+
57
+ def recurrence=(rec)
58
+ ievent.rrule=rec; si(@ic)
59
+ end
60
+
61
+ ## e.recurs :freq => :daily, :count => 10
62
+ ## e.recurs :string => "FREQ=WEEKLY;COUNT=10;"
63
+ ## NOTE - if specifying :string, all other options are overridden
64
+ def recurs(opts = {})
65
+ rec = ""
66
+
67
+ unless opts[:freq].nil?
68
+ #p "Frequency Present"
69
+ rec += "FREQ=#{opts[:freq].to_s.upcase};"
70
+ end
71
+ unless opts[:count].nil?
72
+ #p "Count Present"
73
+ rec += "COUNT=#{opts[:count].to_i};"
74
+ end
75
+ unless opts[:string].nil?
76
+ #p "String Present"
77
+ rec = opts[:string]
78
+ end
79
+ ievent.rrule=rec; si(@ic)
80
+ #rec
81
+ end
82
+
83
+ def occurrences(*oc)
84
+ ievent.occurrences(*oc);
85
+ end
86
+
87
+ private
88
+
89
+ def set_ievent(ic = nil)
90
+ if !ical.nil? && ic.nil?
91
+ if @ic
92
+ @ic
93
+ else
94
+ @ic = RiCal.parse_string(self.ical).first
95
+ end
96
+ elsif ic.nil?
97
+ self.ical = RiCal.Event.to_rfc2445_string
98
+ else
99
+ @ic = ic; self.ical = @ic.to_rfc2445_string
100
+ end
101
+ end
102
+
103
+ alias si set_ievent
104
+ end
105
+
106
+ module Calendar
107
+ module ClassMethods; end
108
+
109
+ def self.included(base)
110
+ base.extend(ClassMethods)
111
+ base.send :after_initialize, :si
112
+ end
113
+
114
+ def icalendar
115
+ @ic ? @ic : @ic = RiCal.parse_string(self.ical).first
116
+ end
117
+
118
+ ## Can add a subcomponent as a String, Actic enabled Model, or a RiCal component
119
+ ## If the argument is a Actic Model, attempt to create an association (currently only works with has_many)
120
+ def add_subcomponent(comp)
121
+ i = icalendar
122
+ if comp.is_a? String
123
+ i.add_subcomponent(RiCal.parse_string(comp).first)
124
+ elsif comp.respond_to? "ic_component"
125
+ #p "Item is a subcomponent"
126
+ assoc = comp.class.to_s.downcase.pluralize.to_sym
127
+ if self.class.reflect_on_association assoc
128
+ #p "Item has association - #{assoc.to_s} on #{self.class.to_s} "
129
+ eval "#{assoc.to_s} << comp"
130
+ else
131
+ p "Item has no association on self"
132
+ end
133
+ i.add_subcomponent(RiCal.parse_string(comp.ievent.to_rfc2445_string).first)
134
+ else
135
+ i.add_subcomponent(RiCal.parse_string(comp.to_rfc2445_string).first)
136
+ end
137
+ si(@ic)
138
+ end
139
+
140
+ # def add_subcomponent(comp)
141
+ # i = icalendar
142
+ # if comp.is_a? String
143
+ # i.add_subcomponent(RiCal.parse_string(comp).first)
144
+ # ## This is not dry enough, possibly make a method specifically as a tag,
145
+ # # which all actic Model objects implement
146
+ # elsif comp.respond_to? "ic_component"
147
+ # i.add_subcomponent(RiCal.parse_string(comp.ievent.to_rfc2445_string).first)
148
+ # else
149
+ # i.add_subcomponent(RiCal.parse_string(comp.to_rfc2445_string).first)
150
+ # end
151
+ # si(@ic)
152
+ # end
153
+
154
+ def events
155
+ icalendar.events
156
+ end
157
+
158
+ # alias event= add_subcomponent
159
+ #def events=(events)
160
+ # icalendar.events
161
+ #end
162
+
163
+ private
164
+ def set_ical(ic = nil)
165
+ if !ical.nil? && ic.nil?
166
+ if @ic
167
+ @ic
168
+ else
169
+ @ic = RiCal.parse_string(self.ical).first
170
+ end
171
+ elsif ic.nil?
172
+ self.ical = RiCal.Calendar.to_rfc2445_string
173
+ else
174
+ @ic = ic; self.ical = @ic.to_rfc2445_string
175
+ end
176
+ end
177
+
178
+ alias si set_ical
179
+ end
180
+ end
@@ -0,0 +1,7 @@
1
+ module Actic
2
+ class Engine < Rails::Engine
3
+ #engine_name :actic
4
+
5
+ config.autoload_paths << File.expand_path("../models", __FILE__)
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ class ActicCalendar < ActiveRecord::Base
2
+ include Actic::Calendar
3
+ has_many :subcomponents
4
+
5
+ def responds_to_actical?
6
+ true
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Actic
2
+ class Event < SubComponent
3
+ belongs_to :calendar
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Actic
2
+ class SubComponent < ActiveRecord::Base
3
+ #Code here
4
+ end
5
+ end
@@ -0,0 +1,62 @@
1
+ require 'actic'
2
+ require 'rails'
3
+ module Actic
4
+ class Railtie < Rails::Railtie
5
+ #railtie_name :actic
6
+
7
+ initializer "actic_railtie.configure_rails_initialization" do
8
+ end
9
+
10
+ # initializer "actic_railtie.configure_rails_initialization",
11
+ # :before => "actice_railtie.blah_init" do
12
+ #
13
+ # end
14
+ #config.autoload_paths += %W(models/calendar)
15
+
16
+ config.after_initialize do
17
+ #require "models/calendar"
18
+ #require "models/event"
19
+ #require "models/sub_component"
20
+ ## inject actic methods into active record
21
+ end
22
+
23
+
24
+ config.before_eager_load do
25
+ #SomeClass.set_important_value = "RoboCop"
26
+ end
27
+
28
+ # Production only
29
+ config.to_prepare do
30
+ # MyRailtie.setup!
31
+ end
32
+
33
+ console do
34
+ # Foo.con_thing!
35
+ end
36
+
37
+ generators do
38
+
39
+ #require '../../generators/actic/actic_generator'
40
+ #require '../../generators/actic_calendar/actic_calendar_generator'
41
+ #require '../../generators/actic_subcomponent/actic_subcomponent_generator'
42
+
43
+ end
44
+
45
+ rake_tasks do
46
+ # require 'path/to/railtie.tasks'
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ # after_initialize
53
+ # app_middleware
54
+ # before_configuration
55
+ # before_eager_load
56
+ # before_initialize
57
+ # generators
58
+ # method_missing
59
+ # new
60
+ # respond_to?
61
+ # to_prepare
62
+ # to_prepare_blocks
@@ -0,0 +1,3 @@
1
+ module Actic
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate actic Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,3 @@
1
+ class ActicGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate actic_calendar Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,51 @@
1
+ require 'rails/generators/migration'
2
+ class ActicCalendarGenerator < Rails::Generators::Base
3
+ include Rails::Generators::Migration
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ argument :name, :type => :string, :default => "calendar"
7
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type", :required => false
8
+
9
+
10
+ def self.next_migration_number(dirname)
11
+ if ActiveRecord::Base.timestamped_migrations
12
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
13
+ else
14
+ "%.3d" % (current_migration_number(dirname) + 1)
15
+ end
16
+ end
17
+
18
+ def create_migration_file
19
+ migration_template 'migration.rb.txt', "db/migrate/create_#{table_name}.rb"
20
+ end
21
+
22
+ def generate_model
23
+ if name.include? ":"
24
+ self.attributes = name
25
+ self.name = "calendar"
26
+ self.attributes = format_attributes(self.attributes)
27
+ end
28
+ template "actic_calendar.rb.txt", "app/models/#{file_name}.rb"
29
+ end
30
+
31
+ private
32
+ def file_name
33
+ name.underscore
34
+ end
35
+
36
+ def table_name
37
+ name.tableize
38
+ end
39
+
40
+ def format_attributes(attrs)
41
+ fat = []
42
+ a = attrs
43
+ b = a.split
44
+ b.each {|c|
45
+ d = c.split(':')
46
+ e = {:name => d[0], :type => d[1] }
47
+ fat << e
48
+ }
49
+ fat
50
+ end
51
+ end
@@ -0,0 +1,4 @@
1
+ class <%= name.classify %> < ActicCalendar
2
+ set_table_name :<%= table_name %>
3
+ #Code here
4
+ end
@@ -0,0 +1,20 @@
1
+ class Create<%= table_name.camelize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table(:<%= table_name %>) do |t|
4
+ t.string :ical
5
+
6
+ <% if attributes %>
7
+ <% for attribute in attributes -%>
8
+ t.<%= attribute[:type] %> :<%= attribute[:name] %>
9
+ <% end -%>
10
+ <% end -%>
11
+
12
+ t.timestamps
13
+ end
14
+
15
+ end
16
+
17
+ def self.down
18
+ drop_table :<%= table_name %>
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate actic_subcomponent Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,13 @@
1
+ class ActicSubcomponentGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :subcomponent, :type => :string, :default => "event"
4
+ argument :actic_calendar, :type => :string, :default => "calendar"
5
+
6
+ # the generator will generate different sub components based on the 'subcomponent' argument
7
+ def generate_subcomponent
8
+ if subcomponent == "event"
9
+ elsif subcomponent == "journal"
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,2 @@
1
+ class <%= name.classify %> < Actic::Subcomponent::Event
2
+ end
@@ -0,0 +1,2 @@
1
+ class <%= name.classify %> < Actic::Subcomponent::Event
2
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: actic
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Steve A Martin
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-30 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: This gem includes the actic orm wrapperb and a series of generators, it is purely for rails 3
22
+ email:
23
+ - steve@shakewell.co.uk
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - .idea/.rakeTasks
33
+ - .idea/actic.iml
34
+ - .idea/encodings.xml
35
+ - .idea/misc.xml
36
+ - .idea/modules.xml
37
+ - .idea/vcs.xml
38
+ - .idea/workspace.xml
39
+ - Gemfile
40
+ - Rakefile
41
+ - actic.gemspec
42
+ - lib/actic.rb
43
+ - lib/actic/engine.rb
44
+ - lib/actic/models/actic_calendar.rb
45
+ - lib/actic/models/event.rb
46
+ - lib/actic/models/sub_component.rb
47
+ - lib/actic/railtie.rb
48
+ - lib/actic/version.rb
49
+ - lib/generators/actic/USAGE
50
+ - lib/generators/actic/actic_generator.rb
51
+ - lib/generators/actic_calendar/USAGE
52
+ - lib/generators/actic_calendar/actic_calendar_generator.rb
53
+ - lib/generators/actic_calendar/templates/actic_calendar.rb.txt
54
+ - lib/generators/actic_calendar/templates/migration.rb.txt
55
+ - lib/generators/actic_subcomponent/USAGE
56
+ - lib/generators/actic_subcomponent/actic_subcomponent_generator.rb
57
+ - lib/generators/actic_subcomponent/templates/event.rb.txt
58
+ - lib/generators/actic_subcomponent/templates/journal.rb.txt
59
+ has_rdoc: true
60
+ homepage: http://rubygems.org/gems/actic
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options: []
65
+
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project: actic
87
+ rubygems_version: 1.3.7
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: A fusion of ORM and ical
91
+ test_files: []
92
+