Class: DiscourseDev::Category
- Defined in:
- lib/discourse_dev/category.rb
Constant Summary
Constants inherited from Record
Instance Attribute Summary
Attributes inherited from Record
Instance Method Summary collapse
- #create! ⇒ Object
- #data ⇒ Object
-
#initialize(count = DEFAULT_COUNT) ⇒ Category
constructor
A new instance of Category.
- #permissions ⇒ Object
Methods inherited from Record
Constructor Details
#initialize(count = DEFAULT_COUNT) ⇒ Category
Returns a new instance of Category.
10 11 12 13 14 15 |
# File 'lib/discourse_dev/category.rb', line 10 def initialize(count = DEFAULT_COUNT) super(::Category, count) @existing_names = ::Category.pluck(:name) @parent_category_ids = ::Category.where(parent_category_id: nil).pluck(:id) @group_count = ::Group.count end |
Instance Method Details
#create! ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/discourse_dev/category.rb', line 55 def create! super do |category| category.() category.save! @parent_category_ids << category.id if category.parent_category_id.blank? end end |
#data ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/discourse_dev/category.rb', line 17 def data name = Faker::Discourse.category parent_category_id = nil while @existing_names.include? name name = Faker::Discourse.category end @existing_names << name if Faker::Boolean.boolean(true_ratio: 0.6) parent_category_id = @parent_category_ids.sample = ::Category.find(parent_category_id)..presence else = nil end { name: name, description: Faker::Lorem.paragraph, user_id: ::Discourse::SYSTEM_USER_ID, color: Faker::Color.hex_color.last(6), parent_category_id: parent_category_id } end |
#permissions ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/discourse_dev/category.rb', line 43 def return if .present? return { everyone: :full } if Faker::Boolean.boolean(true_ratio: 0.75) = {} offset = rand(@group_count) group = ::Group.offset(offset).first [group.id] = Faker::Number.between(from: 1, to: 3) end |