spiderfw 0.6.23 → 0.6.24

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/CHANGELOG +10 -1
  2. data/README.rdoc +1 -1
  3. data/VERSION +1 -1
  4. data/apps/config_editor/_init.rb +1 -2
  5. data/apps/config_editor/controllers/config_editor_controller.rb +1 -7
  6. data/apps/core/admin/controllers/admin_controller.rb +1 -1
  7. data/apps/core/admin/public/css/sass/admin.css +35 -31
  8. data/apps/core/admin/public/sass/admin.scss +6 -1
  9. data/apps/core/components/widgets/crud/crud.shtml +2 -2
  10. data/apps/core/components/widgets/table/table.rb +5 -5
  11. data/apps/core/forms/tags/element_row.erb +15 -10
  12. data/apps/core/forms/widgets/form/form.rb +35 -22
  13. data/apps/core/forms/widgets/inputs/checkbox/checkbox.shtml +2 -2
  14. data/apps/core/forms/widgets/inputs/date_time/date_time.shtml +2 -2
  15. data/apps/core/forms/widgets/inputs/file_input/file_input.shtml +2 -2
  16. data/apps/core/forms/widgets/inputs/html_area/html_area.shtml +2 -2
  17. data/apps/core/forms/widgets/inputs/input/input.shtml +2 -2
  18. data/apps/core/forms/widgets/inputs/password/password.shtml +2 -2
  19. data/apps/core/forms/widgets/inputs/search_select/search_select.shtml +1 -1
  20. data/apps/core/forms/widgets/inputs/select/select.shtml +2 -2
  21. data/apps/core/forms/widgets/inputs/text/text.shtml +2 -2
  22. data/apps/core/forms/widgets/inputs/text_area/text_area.shtml +2 -2
  23. data/apps/core/forms/widgets/inputs/time_span/time_span.shtml +1 -1
  24. data/blueprints/home/config.ru +8 -0
  25. data/lib/spiderfw/app.rb +416 -224
  26. data/lib/spiderfw/cmd/commands/app.rb +243 -239
  27. data/lib/spiderfw/cmd/commands/cert.rb +421 -417
  28. data/lib/spiderfw/cmd/commands/config.rb +85 -82
  29. data/lib/spiderfw/cmd/commands/console.rb +64 -40
  30. data/lib/spiderfw/cmd/commands/content.rb +29 -25
  31. data/lib/spiderfw/cmd/commands/create.rb +58 -54
  32. data/lib/spiderfw/cmd/commands/model.rb +118 -114
  33. data/lib/spiderfw/cmd/commands/setup.rb +55 -51
  34. data/lib/spiderfw/cmd/commands/test.rb +63 -59
  35. data/lib/spiderfw/cmd/commands/webserver.rb +56 -51
  36. data/lib/spiderfw/config/options/spider.rb +4 -3
  37. data/lib/spiderfw/controller/controller.rb +2 -0
  38. data/lib/spiderfw/controller/http_controller.rb +1 -2
  39. data/lib/spiderfw/controller/mixins/static_content.rb +3 -3
  40. data/lib/spiderfw/controller/mixins/visual.rb +30 -15
  41. data/lib/spiderfw/controller/response.rb +84 -0
  42. data/lib/spiderfw/controller/session/file_session.rb +2 -2
  43. data/lib/spiderfw/http/adapters/rack.rb +12 -13
  44. data/lib/spiderfw/http/server.rb +80 -46
  45. data/lib/spiderfw/i18n/cldr.rb +6 -9
  46. data/lib/spiderfw/model/base_model.rb +103 -23
  47. data/lib/spiderfw/model/condition.rb +110 -25
  48. data/lib/spiderfw/model/mappers/db_mapper.rb +14 -6
  49. data/lib/spiderfw/model/mappers/mapper.rb +440 -197
  50. data/lib/spiderfw/model/model.rb +105 -21
  51. data/lib/spiderfw/model/model_hash.rb +9 -1
  52. data/lib/spiderfw/model/query.rb +50 -9
  53. data/lib/spiderfw/model/query_set.rb +211 -44
  54. data/lib/spiderfw/model/request.rb +28 -21
  55. data/lib/spiderfw/model/storage/base_storage.rb +125 -10
  56. data/lib/spiderfw/model/storage/db/db_storage.rb +7 -4
  57. data/lib/spiderfw/model/storage.rb +8 -1
  58. data/lib/spiderfw/setup/spider_setup_wizard.rb +9 -7
  59. data/lib/spiderfw/spider.rb +270 -43
  60. data/lib/spiderfw/templates/layout.rb +9 -4
  61. data/lib/spiderfw/templates/resources/sass.rb +3 -2
  62. data/lib/spiderfw/templates/template.rb +1 -0
  63. data/lib/spiderfw/utils/annotations.rb +3 -1
  64. data/lib/spiderfw/utils/logger.rb +1 -1
  65. data/lib/spiderfw/utils/monkey/symbol.rb +4 -2
  66. data/lib/spiderfw/utils/shared_store/file_shared_store.rb +2 -2
  67. data/lib/spiderfw/utils/thread_out.rb +3 -1
  68. data/public/css/error_page.css +83 -0
  69. data/public/js/error_page.js +5 -0
  70. data/spider.gemspec +4 -1
  71. data/templates/email/error.erb +9 -0
  72. metadata +28 -12
  73. data/apps/config_editor/widgets/edit_bool/edit_bool.rb +0 -8
  74. data/apps/config_editor/widgets/edit_bool/edit_bool.shtml +0 -5
@@ -6,6 +6,7 @@ require 'iconv'
6
6
 
7
7
  module Spider; module Model
8
8
 
9
+ # @abtract
9
10
  # The main class for interacting with data.
10
11
  # When not dealing with legacy storages, subclasses should use Managed instead, which provides an id and
11
12
  # other conveniences.
@@ -50,8 +51,6 @@ module Spider; module Model
50
51
  # => 2
51
52
  # p salmon_lovers[0].name
52
53
  # => 'Cat'
53
-
54
-
55
54
  class BaseModel
56
55
  include Spider::Logger
57
56
  include DataTypes
@@ -60,40 +59,61 @@ module Spider; module Model
60
59
  # include StateMachine
61
60
 
62
61
  # The BaseModel class itself. Used when dealing with proxy objects.
62
+ # @return [Class<BaseModel]
63
63
  attr_reader :model
64
64
  # An Hash of loaded elements
65
+ # @return [Hash]
65
66
  attr_reader :loaded_elements
67
+ # @private
66
68
  # Model instance or QuerySet containing the object
69
+ # @return [BaseModel|QuerySet]
67
70
  attr_accessor :_parent
71
+ # @private
68
72
  # If _parent is a model instance, which element points to this one
73
+ # @return [Symbol]
69
74
  attr_accessor :_parent_element
70
- #
75
+ # @private
76
+ # If true, forces the mapper to check for existance of the object in the storage
77
+ # @return [bool]
71
78
  attr_accessor :_check_if_saved
72
79
 
80
+ # @private
73
81
  # If this object is used as a superclass in class_table_inheritance, points to the current subclass
82
+ # @return [Class<BaseModel]
74
83
  attr_accessor :_subclass_object
84
+ # @private
75
85
  # This object won't be put into the identity mapper
86
+ # @return [bool]
76
87
  attr_accessor :_no_identity_mapper
88
+ # @private
77
89
  # Elements that were modified since a load or a save (note: this only keeps track of changed references on the object;
78
90
  # it doesn't consider if a associated object or QuerySet has changed. Use element_modified? to get that information)
91
+ # @return [Array]
79
92
  attr_reader :_modified_elements
80
93
 
81
94
  class <<self
82
95
  # An Hash of model attributes. They can be used freely.
96
+ # @return [Hash]
83
97
  attr_reader :attributes
84
98
  # An array of element names, in definition order.
99
+ # @return [Array]
85
100
  attr_reader :elements_order
86
101
  # An Hash of integrated models => corresponding integrated element name.
102
+ # @return [Hash]
87
103
  attr_reader :integrated_models
88
104
  # An Hash of polymorphic models => polymorphic params
105
+ # @return [Hash]
89
106
  attr_reader :polymorphic_models
90
107
  # An Array of named sequences.
108
+ # @return [Array]
91
109
  attr_reader :sequences
92
110
  end
93
111
 
94
112
 
95
113
 
96
114
  # Copies this class' elements to the subclass.
115
+ # @param [Class<BaseModel] self
116
+ # @return [void]
97
117
  def self.inherited(subclass) #:nodoc:
98
118
  # FIXME: might need to clone every element
99
119
  @subclasses ||= []
@@ -112,11 +132,14 @@ module Spider; module Model
112
132
  super
113
133
  end
114
134
 
135
+ # All known subclasses of this model
136
+ # @return [Array]
115
137
  def self.subclasses
116
138
  @subclasses || []
117
139
  end
118
140
 
119
141
  # Returns the parent Spider::App of the module
142
+ # @return [Spider::App]
120
143
  def self.app
121
144
  return @app if @app
122
145
  app = self
@@ -197,6 +220,11 @@ module Spider; module Model
197
220
  #
198
221
  # Other attributes may be used by DataTypes (see #DataType::ClassMethods.take_attributes), and other code.
199
222
  # See also Element.
223
+ # @yield If a block is given, will be called in the context of the junction model
224
+ # @param [Symbol] name
225
+ # @param [Class] type
226
+ # @param [Hash] attributes
227
+ # @return [Element]
200
228
  def self.element(name, type, attributes={}, &proc)
201
229
  name = name.to_sym
202
230
  @elements ||= {}
@@ -404,6 +432,10 @@ module Spider; module Model
404
432
  end
405
433
 
406
434
 
435
+ # @private
436
+ # Helper method that defines getter and setter for an element
437
+ # @param [Symbol] name Element name
438
+ # @return [void]
407
439
  def self.define_element_methods(name)
408
440
  ivar = :"@#{ name }"
409
441
 
@@ -524,10 +556,13 @@ module Spider; module Model
524
556
  end
525
557
  end
526
558
  val
527
- #extend_element(name)
528
559
  end
529
560
  end
530
561
 
562
+ # @private
563
+ # Helper method that registers an element with the model
564
+ # @param [Element] element
565
+ # @return [void]
531
566
  def self.add_element(el)
532
567
  @elements ||= {}
533
568
  @elements[el.name] = el
@@ -546,6 +581,8 @@ module Spider; module Model
546
581
 
547
582
 
548
583
  # Removes a defined element
584
+ # @param [Symbol|Element] element
585
+ # @return nil
549
586
  def self.remove_element(el)
550
587
  return unless @elements
551
588
  el = el.name if el.is_a?(Element)
@@ -571,6 +608,9 @@ module Spider; module Model
571
608
  # end
572
609
  end
573
610
 
611
+ # @private
612
+ # Called when an element is defined
613
+ # @return [void]
574
614
  def self.element_defined(el)
575
615
  if (@on_element_defined && @on_element_defined[el.name])
576
616
  @on_element_defined[el.name].each do |proc|
@@ -579,6 +619,11 @@ module Spider; module Model
579
619
  end
580
620
  end
581
621
 
622
+ # Registers a block that will be called whenever an element is defined.
623
+ #
624
+ # The block will be called with the created element as an argument.
625
+ # @param [Symbol] element_name
626
+ # @param [Proc] proc A block to execute
582
627
  def self.on_element_defined(el_name, &proc)
583
628
  @on_element_defined ||= {}
584
629
  @on_element_defined[el_name] ||= []
@@ -599,6 +644,14 @@ module Spider; module Model
599
644
  # end
600
645
  # p = Person.new(...)
601
646
  # p.street == p.address.street
647
+ # @param [Symbol] element_name
648
+ # @param [Hash] params Params can be:
649
+ # * :except Excludes some elements of the integrated model
650
+ # * :overwrite Allows overwriting this model's elements with the integrated model's ones.
651
+ # * :keep_pks Integrate the model's primary keys as well
652
+ # * :hidden Set the :hidden attribute on integrated elements
653
+ # * :mapping An Hash of new names to assign to integrated elements
654
+ # @return [void]
602
655
  def self.integrate(element_name, params={})
603
656
  params ||= {}
604
657
  elements[element_name].attributes[:integrated_model] = true
@@ -616,11 +669,18 @@ module Spider; module Model
616
669
  model.attributes[:integrated_from_elements] << [self, element_name]
617
670
  end
618
671
 
672
+ # @private
673
+ # Integrates a single element from a model.
674
+ # See {BaseModel.integrate}
675
+ # @param [Symbol] element_name
676
+ # @param [Symbol] element_element The element inside the element's model to integrate
677
+ # @param [Hash] params See {BaseModel.integrate}
678
+ # @return [void]
619
679
  def self.integrate_element(element_name, element_element, params={})
620
680
  el = element_element
621
681
  el = self.elements[element_name].model.elements[el] if el.is_a?(Symbol)
622
682
  integrated_attributes = {}
623
- integrated_attributes[:primary_key] = false if params[:no_pks]
683
+ integrated_attributes[:primary_key] = false if params[:no_pks] # deprecated
624
684
  integrated_attributes[:hidden] = params[:hidden] unless (params[:hidden].nil?)
625
685
 
626
686
  integrated_attributes[:primary_key] = false unless (params[:keep_pks])
@@ -634,6 +694,10 @@ module Spider; module Model
634
694
  define_element_methods(name)
635
695
  end
636
696
 
697
+ # Undoes an integration
698
+ # See {BaseModel.integrate}
699
+ # @param [Symbol|Element] element
700
+ # @return [void]
637
701
  def self.remove_integrate(element_name)
638
702
  element = element_name.is_a?(Element) ? element_name : self.elements[element_name]
639
703
  model = element.model
@@ -645,8 +709,12 @@ module Spider; module Model
645
709
 
646
710
  # Sets additional attributes on the element
647
711
  #
648
- # _Warning:_ for attributes which are parsed by the BaseModel during element definition,
712
+ # **Warning:** for attributes which are parsed by the BaseModel during element definition,
649
713
  # this will not have the desired effect; remove and redefine the element instead.
714
+ #
715
+ # @param [Symbol] element_name
716
+ # @param [Hash] attributes Attributes to set
717
+ # @return [void]
650
718
  def self.element_attributes(element_name, attributes)
651
719
  elements[element_name].attributes = elements[element_name].attributes.merge(attributes)
652
720
  if attributes[:primary_key] && !@primary_keys.include?(elements[element_name])
@@ -658,6 +726,12 @@ module Spider; module Model
658
726
 
659
727
  # Defines a multiple element. Equivalent to calling
660
728
  # element(name, type, :multiple => true, :association => :many, ...)
729
+ # See also {BaseModel.element}.
730
+ # @param [Symbol] name
731
+ # @param [Class] type
732
+ # @param [Hash] attributes
733
+ # @param [Proc] proc
734
+ # @return [Element]
661
735
  def self.many(name, type, attributes={}, &proc)
662
736
  attributes[:multiple] = true
663
737
  attributes[:association] ||= :many
@@ -665,7 +739,12 @@ module Spider; module Model
665
739
  end
666
740
 
667
741
  # Defines an element with choice association. Shorthand for
668
- # element(name, type, :association => :choice, ...)
742
+ # element(name, type, :association => :choice, ...)
743
+ # @param [Symbol] name
744
+ # @param [Class] type
745
+ # @param [Hash] attributes
746
+ # @param [Proc] proc
747
+ # @return [Element]
669
748
  def self.choice(name, type, attributes={}, &proc)
670
749
  attributes[:association] = :choice
671
750
  element(name, type, attributes, &proc)
@@ -678,6 +757,10 @@ module Spider; module Model
678
757
  many(name, type, attributes, &proc)
679
758
  end
680
759
 
760
+ # Defines an element which returns a query on another one.
761
+ # @param [Symbol] name Name of the new element
762
+ # @param [Sybmol] element_name Name of the element to run the query on
763
+ # @param [Hash] attributes Attributes for the new elements. Must have a :condition attribute.
681
764
  def self.element_query(name, element_name, attributes={})
682
765
  orig_element = self.elements[element_name]
683
766
  set_el_query = lambda do
@@ -704,15 +787,12 @@ module Spider; module Model
704
787
  end
705
788
 
706
789
 
707
- # Saves the element definition and evals it when first needed, avoiding problems with classes not
708
- # available yet when the model is defined.
709
- # FIXME: remove?
710
- def self.define_elements(&proc) #:nodoc:
711
- @elements_definition = proc
712
- end
713
-
714
- # Creates an inline model
715
- def self.create_inline_model(name, hash, attributes={}) #:nodoc:
790
+ # @private
791
+ # Creates an element with an {InlineModel} as type.
792
+ # @param [Symbol] name Element name
793
+ # @param [Hash] hash The hash to create the inline model from
794
+ # @param [Hash] attributes Attributes for the new element
795
+ def self.create_inline_model(name, hash, attributes={})
716
796
  model = self.const_set(Spider::Inflector.camelize(name), Class.new(InlineModel))
717
797
  model.instance_eval do
718
798
  if attributes[:inline_model]
@@ -737,11 +817,13 @@ module Spider; module Model
737
817
  end
738
818
 
739
819
  # An array of other models this class points to.
820
+ # @return [Array] An array of models which are referenced by this one's elements.
740
821
  def self.submodels
741
822
  elements.select{ |name, el| el.model? }.map{ |name, el| el.model }
742
823
  end
743
824
 
744
825
 
826
+ # @return [void]
745
827
  def self.extend_model(model, params={}) #:nodoc:
746
828
  if (model == superclass) # first undo table per class inheritance
747
829
  @elements = {}
@@ -778,10 +860,11 @@ module Spider; module Model
778
860
  end
779
861
 
780
862
  # Externalizes the superclass elements making the superclass an external integrated element.
781
- # Parameters may be:
782
- # * :name (symbol) name of the created element
783
- # * :delete_cascade (bool) delete cascade the superclass instance. True by default.
784
- # * :no_local_pk (bool) do not define an id for this class
863
+ # @param [Hash] params Parameters may be:
864
+ # * :name (symbol) name of the created element
865
+ # * :delete_cascade (bool) delete cascade the superclass instance. True by default.
866
+ # * :no_local_pk (bool) do not define an id for this class
867
+ # @return [void]
785
868
  def self.class_table_inheritance(params={})
786
869
  self.extend_model(superclass, params)
787
870
  end
@@ -1872,9 +1955,6 @@ module Spider; module Model
1872
1955
  val = instance_variable_get("@#{el_name}")
1873
1956
  val.modified = false if val.is_a?(QuerySet)
1874
1957
  end
1875
- self.class.elements_array.select{ |el| el.attributes[:integrated_model] && self.element_has_value?(el) }.each do |el|
1876
- self.get(el).reset_modified_elements(*elements)
1877
- end
1878
1958
 
1879
1959
  nil
1880
1960
  end